Convert TradingView Indicator to ThinkorSwim

javin82

New member
I need help converting a pine script indicator into a think script study for Thinkorswim. The name of the indicator is called Range. It is a reversal indicator and plots long and short signals. If you can help me with this, please let me know. Thank you!

PineScript code below:
Code:
//////////////
//@version=3
study("Range fv2",overlay=true)
showTrendLine = input(false, title="Show Trend Line")
colorBars = input(true, title="Color Bars?")
filterTrend = input(true, title="Filter Trend?")

//Source
src = close

//Sampling Period
per = input(defval=25, minval=1, title="Sampling Period")

//Range Multiplier
mult = input(defval=2, minval=0, title="Range Multiplier")

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Definitions
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------

//Smooth Average Range
smoothrng(x, t, m)=>
    wper      = (t/3) - 1
    avrng     = sma(abs(x - x[1]), t)
    smoothrng = sma(avrng, wper)*m
    smoothrng
smrng = smoothrng(src, per, mult)

//Range Filter
rngfilt(x, r)=>
    rngfilt  = x
    rngfilt := x > nz(rngfilt[1]) ? ((x - r) < nz(rngfilt[1]) ? nz(rngfilt[1]) : (x - r)) : ((x + r) > nz(rngfilt[1]) ? nz(rngfilt[1]) : (x + r))
    rngfilt
filt = rngfilt(src, smrng)

//Filter Direction
upward   = 0.0
upward  := filt > filt[1] ? nz(upward[1]) + 1 : filt < filt[1] ? 0 : nz(upward[1])
downward = 0.0
downward := filt < filt[1] ? nz(downward[1]) + 1 : filt > filt[1] ? 0 : nz(downward[1])

//Target Bands
hband = filt + smrng
lband = filt - smrng

//Colors
filtcolor = upward > 0 ? lime : downward > 0 ? red : orange
barcolor  = (src > filt) and (src > src[1]) and (upward > 0) ? lime : (src > filt) and (src < src[1]) and (upward > 0) ? green : (src < filt) and (src < src[1]) and (downward > 0) ? red : (src < filt) and (src > src[1]) and (downward > 0) ? maroon : orange
barcolor(colorBars ? barcolor : na)

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Plots
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------

//Range Filter
if filterTrend == true
    showTrendLine := false
filtplot = plot(filterTrend ? filt : na, color=filtcolor, linewidth=4, title="Range Filter")
//
Factor=input(3, minval=1,maxval = 100)
Pd=input(3, minval=1,maxval = 100)

Up=hl2-(Factor*atr(Pd))
Dn=hl2+(Factor*atr(Pd))
TrendUp = 0.0
TrendDown = 0.0
linecolor = na
up = na
down = na
Tsl = 0.0
Trend = 0.0
TrendUp := close[1]>TrendUp[1]? max(Up,TrendUp[1]) : Up
TrendDown := close[1]<TrendDown[1]? min(Dn,TrendDown[1]) : Dn
Trend := close > TrendDown[1] ? 1: close< TrendUp[1]? -1: nz(Trend[1],1)
Tsl := Trend==1? TrendUp: TrendDown
linecolor := Trend == 1 ? green : red
plot(showTrendLine ? Tsl : na, color = linecolor , style = line , linewidth = 3,title = "SuperTrend")

// Strategy


longCond = na
shortCond = na
longCond :=crossunder(Tsl,filt)
shortCond :=crossover(Tsl,filt)

// Count your long short conditions for more control with Pyramiding

sectionLongs = 0
sectionLongs := nz(sectionLongs[1])
sectionShorts = 0
sectionShorts := nz(sectionShorts[1])

if longCond
    sectionLongs := sectionLongs + 1
    sectionShorts := 0

if shortCond
    sectionLongs := 0
    sectionShorts := sectionShorts + 1

// Pyramiding

pyrl = 1


// These check to see your signal and cross references it against the pyramiding settings above

longCondition = longCond and sectionLongs <= pyrl
shortCondition = shortCond and sectionShorts <= pyrl

// Get the price of the last opened long or short

last_open_longCondition = na
last_open_shortCondition = na
last_open_longCondition := longCondition ? open : nz(last_open_longCondition[1])
last_open_shortCondition := shortCondition ? open : nz(last_open_shortCondition[1])

// Check if your last postion was a long or a short

last_longCondition = na
last_shortCondition = na
last_longCondition := longCondition ? time : nz(last_longCondition[1])
last_shortCondition := shortCondition ? time : nz(last_shortCondition[1])

in_longCondition = last_longCondition > last_shortCondition
in_shortCondition = last_shortCondition > last_longCondition

// Take profit

isTPl = input(true, "Take Profit Long")
isTPs = input(true, "Take Profit Short")
tp = input(5, "Take Profit ", type=float)
long_tp = isTPl and crossover(high, (1+(tp/100))*last_open_longCondition) and longCondition == 0 and in_longCondition  == 1
short_tp = isTPs and crossunder(low, (1-(tp/100))*last_open_shortCondition) and shortCondition == 0 and in_shortCondition == 1


// Create a single close for all the different closing conditions.

long_close = long_tp  ? 1 : 0
short_close = short_tp ? 1 : 0

// Get the time of the last close

last_long_close = na
last_short_close = na
last_long_close := long_close ? time : nz(last_long_close[1])
last_short_close := short_close ? time : nz(last_short_close[1])


// Alerts & Signals

bton(b) => b ? 1 : 0
plotshape(longCondition , title="Long", color=green, textcolor=green, transp=0,
          style=shape.triangleup, location=location.belowbar, size=size.small,text="LONG",offset=0)


plotshape(shortCondition, title="Short", color=red, textcolor=red, transp=0,
          style=shape.triangledown, location=location.abovebar, size=size.small,text="SHORT",offset=0)


//plotshape(longCondition, title = "BUY Signal", text = "Buy", style=shape.triangleup, location=location.belowbar, color = blue, editable = false, transp = 0)
//plotshape(shortCondition, title = "SELL Signal", text = "Sell", style=shape.triangledown, location=location.abovebar, color = black, editable = false, transp = 0)

plotshape(long_tp and last_longCondition > nz(last_long_close[1]), text ="TP", title="Take Profit Long", style=shape.triangledown,
   location=location.abovebar, color = red, editable = false, transp = 0)
plotshape(short_tp and last_shortCondition > nz(last_short_close[1]) , text ="TP", title="Take Profit Short", style=shape.triangleup,
   location=location.belowbar, color = lime, editable = false, transp = 0)

alertcondition(bton(longCondition), title="Long Alert")
alertcondition(bton(shortCondition), title="Short Alert")
alertcondition(bton(long_tp and last_longCondition > nz(last_long_close[1])), title="Take Profit Long")
alertcondition(bton(short_tp and last_shortCondition > nz(last_short_close[1])), title="Take Profit Short")

Any help I can get with this will be greatly appreciated! Thank you!

Admin's Notes:

You can now use this thread to make your own request. If there is a TradingView script that you would like to see in ThinkorSwim, please post the source code and link to that script below. We'll try our best to help you with the conversion.

Below are the TradingView scripts that have been converted to TOS.
 
Last edited by a moderator:

Volatility Trading Range

VTR is a momentum indicator that shows if a stock is overbought or oversold based on its Weekly and Monthly average volatility trading range.

Download the indicator

jrob0124

New member
Can anyone please help me turn this TradingView indicator into a TOS indicator? Much appreciated!


Code:
study(title="SQN-ChrisD-Fallible", shorttitle="SQN-ChrisD-Fallible", overlay = false)
Period = input(100, minval=5, title="Period")
close_difference = close/close[1]-1
Stdev = stdev(close_difference,Period)
_sma= sma(close_difference,Period)
SQN=((_sma*sqrt(Period))/Stdev)
c=(SQN < .2 and SQN > -.2)?#FFD700:  (SQN>0.6 and SQN<1.7)?#808000: (SQN>-0.6 and SQN<0.2) ?#FF0000: (SQN>=1.7)?#0000FF:(SQN<-0.6)?#800000: (SQN>.2 and SQN<0.6)? #FFD700FF:gray
plot(SQN, title="SQN", color=c, transp=10,histbase=0,style=area,linewidth=4)
 

BenTen

Administrative
Staff
VIP
@jrob0124 Here you go:

Code:
# SQN-ChrisD-Fallible
# Assembled by BenTen at UseThinkScript.com
# Converted from https://www.tradingview.com/script/ZhHf4DFD-SQN-ChrisD-Fallible/

declare lower;

input Period = 100;
def close_difference = close/close[1]-1;
def Stdev = stdev(close_difference,Period);
def underscore_sma = simpleMovingAvg(close_difference,Period);
def SQN=((underscore_sma*sqrt(Period))/Stdev);
plot histogram = SQN;

histogram.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
histogram.AssignValueColor(if (SQN < .2 and SQN > -.2) then color.yellow else if (SQN>0.6 and SQN<1.7) then color.lime else if (SQN>-0.6 and SQN<0.2) then color.red else if (SQN>=1.7) then color.blue else if (SQN<-0.6) then color.dark_red else if (SQN>.2 and SQN<0.6) then color.magenta else color.gray);
 

jrob0124

New member
@BenTen,

Here is the code for TradingView traditional pivots. I cannot find any pivots in TOS that map to these. Is it possible to turn these into a TOS indicator as well? Thank you for all your help!

Code:
PP = (HIGHprev + LOWprev + CLOSEprev) / 3
    R1 = PP * 2 - LOWprev
    S1 = PP * 2 - HIGHprev
    R2 = PP + (HIGHprev - LOWprev)
    S2 = PP - (HIGHprev - LOWprev)
    R3 = PP * 2 + (HIGHprev - 2 * LOWprev)
    S3 = PP * 2 - (2 * HIGHprev - LOWprev)
    R4 = PP * 3 + (HIGHprev - 3 * LOWprev)
    S4 = PP * 3 - (3 * HIGHprev - LOWprev)
    R5 = PP * 4 + (HIGHprev - 4 * LOWprev)
    S5 = PP * 4 - (4 * HIGHprev - LOWprev)
 

BenTen

Administrative
Staff
VIP
@jrob0124 Here are the built-in pivot indicators in ToS:

oUZkd0R.png
 

rad14733

Well-known member
VIP
@jrob0124 Can you provide the entire TradingView script please... There may or may not already be a custom script written fitting the criteria but we can't say without seeing the entire block of code...
 

jrob0124

New member
@jrob0124 Can you provide the entire TradingView script please... There may or may not already be a custom script written fitting the criteria but we can't say without seeing the entire block of code...

Thanks for replying @rad14733.

Here is the article I pulled from TradingView describing how they create their pivot points, which includes some of the code I pasted above.

https://www.tradingview.com/support...nts Standard — is a,and resistance (R) levels.

I also found this link, that has some of the code mentioned above, but maybe more complete.

https://getsatisfaction.com/tradingview/topics/traditional_and_classic_pivot_point_formula

Please let me know if this helps and thanks again for your time.
 

Beltrame1

New member
VIP
I found this code in Tradingview and it is called Didi Index/Indicator. It seems Odir Aguiar (the Brazilian creator) flattened the 8 simple moving average and made it the "zero line" if I am not mistaken. I believe the picture below shows it and it would be AWESOME if when they CROSS PERFECTLY to have some sort of sound alert or ARROW. The original code at the bottom of the link.
He explains in one of his videos that he views the straight line as a fence separating 2 bulls (the other 2 MA`s) and when they run away from each other and there is a perfect cross, price runs big @BenTen[/USER] the MA`s are 3 in blue, 8 in black and 20 in red

okfWU1X.png

Didi_index
input price = close;
input short_length = 3;
input mid_length = 8;
input long_length = 20;

def sEMA = ExpAverage(price, short_length);
def mEMA = ExpAverage(price, mid_length);
def lEMA = ExpAverage(price, long_length);

plot s = sEMA / mEMA - 1;
plot l = lEMA / mEMA - 1;

s.AssignValueColor(Color.GREEN);
l.AssignValueColor(Color.MAGENTA);

plot zeroline = 0;
zeroline.AssignValueColor(Color.GRAY);
 
Last edited:

amao11

New member
Found this amazing study called "Auto Support" in tradingview from this guy "jmac" and am wondering if someone could make it available for TOS. The script is free. Please and thank you!!

Code:
study("Auto-Support v 0.3", overlay=true)
a = input(title="Sensitivity", type=integer, defval=10, minval=1, maxval=10)
d = input(title="Transparency", type=integer, defval=85, minval=1, maxval=100)
b = #FF0000
c = #0000FF
plot(highest(a*1), title='Resistance 1', color=b, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(lowest (a*1), title='Support', color=c, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*2), title='Resistance', color=b, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(lowest (a*2), title='Support', color=c, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*3), title='Resistance', color=b, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(lowest (a*3), title='Support', color=c, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*4), title='Resistance', color=b, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(lowest (a*4), title='Support', color=c, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*5), title='Resistance', color=b, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(lowest (a*5), title='Support', color=c, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*6), title='Resistance', color=b, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(lowest (a*6), title='Support', color=c, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*7), title='Resistance', color=b, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(lowest (a*7), title='Support', color=c, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*8), title='Resistance', color=b, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(lowest (a*8), title='Support', color=c, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*9), title='Resistance', color=b, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(lowest (a*9), title='Support', color=c, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*10), title='Resistance', color=b, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(lowest (a*10), title='Support', color=c, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*15), title='Resistance', color=b, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(lowest (a*15), title='Support', color=c, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*20), title='Resistance', color=b, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(lowest (a*20), title='Support', color=c, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*25), title='Resistance', color=b, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(lowest (a*25), title='Support', color=c, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*30), title='Resistance', color=b, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(lowest (a*30), title='Support', color=c, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*35), title='Resistance', color=b, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(lowest (a*35), title='Support', color=c, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*40), title='Resistance', color=b, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(lowest (a*40), title='Support', color=c, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*45), title='Resistance', color=b, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(lowest (a*45), title='Support', color=c, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*50), title='Resistance', color=b, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(lowest (a*50), title='Support', color=c, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*75), title='Resistance', color=b, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(lowest (a*75), title='Support', color=c, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*100), title='Resistance', color=b, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(lowest (a*100), title='Support', color=c, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*150), title='Resistance', color=b, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(lowest (a*150), title='Support', color=c, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*200), title='Resistance', color=b, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(lowest (a*200), title='Support', color=c, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*250), title='Resistance', color=b, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(lowest (a*250), title='Support', color=c, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*300), title='Resistance', color=b, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(lowest (a*300), title='Support', color=c, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*350), title='Resistance', color=b, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(lowest (a*350), title='Support', color=c, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*400), title='Resistance', color=b, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(lowest (a*400), title='Support', color=c, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*450), title='Resistance', color=b, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(lowest (a*450), title='Support', color=c, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(highest(a*500), title='Resistance', color=b, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
plot(lowest (a*500), title='Support', color=c, linewidth=2, style=line, transp=d, offset=-9999, trackprice=true)
 

J007RMC

Well-known member
2019 Donor
I don't know if we have anything similar to the below code?

KbNPKHT.png


Code:
//
// @author LazyBear
//
study("CCI coded OBV", shorttitle="CCIOBV_LB")
src = close
length = input(20, minval=1, title="CCI Length")
threshold=input(0, title="CCI threshold for OBV coding")
lengthema=input(13, title="EMA length")
obv(src) =>
    cum(change(src) > 0 ? volume : change(src) < 0 ? -volume : 0*volume)
  
o=obv(src)
c=cci(src, length)
plot(o, color=c>=threshold?green:red, title="OBV_CCI coded", linewidth=2)
plot(ema(o,lengthema), color=orange, linewidth=2)
 

vinced

New member
VIP
https://www.tradingview.com/script/uuDEajsI-Quadratic-Regression/

I've been using this on different timeframes to predict trends. I'd love to have this on thinkscript along with other indicators for my study.
Thanks in advance!!

Code:
// This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License https://creativecommons.org/licenses/by-sa/4.0/
// © alexgrover

//@version=4
study("Quadratic Regression",overlay=true)
length = input(54,maxval=54)
offset = input(27,maxval=55)
src    = input(close)
show   = input(true,"Show R2")
//------------------------------------------------------------------------------
n = bar_index
Var(x) => variance(x,length)
Cov(x,y) => sma(x*y,length) - sma(x,length)*sma(y,length)
//------------------------------------------------------------------------------
sma = sma(src,length)
varn = (pow(length,2)-1)/12
norm = Var(n*n)*varn-pow(Cov(n,n*n),2)
a = (Cov(n*n,src)*varn - Cov(n,src)*Cov(n,n*n))/norm
b = (Cov(n,src)*Var(n*n) - Cov(n*n,src)*Cov(n,n*n))/norm
c = sma - a*sma(n*n,length) - b*sma(n,length)
Q(x)=> a*pow(n+x,2) + b*(n+x) + c
//------------------------------------------------------------------------------
sse = 0.,sst = 0.
for i = 0 to length-1
    sse := sse + pow(src[i] - Q(-i),2)
    sst := sst + pow(src[i] - sma,2)
r2 = 1 - sse/sst
//------------------------------------------------------------------------------
line l = na
dt = round(time - time[1])
for i = 1-offset to 54-offset
    css = abs(i) > length ? na : #2157f3
    l := line.new(time+dt*i,Q(i),time+dt*(i+1),Q(i+1),
      xloc=xloc.bar_time,color=css,width=2)
line.delete(l[1])
//------------------------------------------------------------------------------
label la = na
min = min(offset,length+1)
transp = color.new(color.white, 100)
if show
    la := label.new(n[min],Q(-min),tostring(r2,"#.###")
      ,color=transp,style=label.style_label_up,textcolor=#2157f3)
    label.delete(la[1])
 
Last edited:

Steakeater

New member
I have been a long time lurker and would just like to say @BenTen, @markos , and @mashume huge fans of your work, along with so many names if a tried to list them all this page would be filled. Thanks for all your hard work. If someone could convert these two Tradingview indicators that would be great.

Best of luck with everyone's trades may the profits flow.

Steak

Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © opiumfive

//@version=4
study("Drake Delay Stochastic")

pds = input(title="pds", type=input.integer, defval=13, minval=1)
slw = input(title="ema", type=input.integer, defval=8, minval=1)
slwsignal = input(title="trigger", type=input.integer, defval=9, minval=1)

MAValue = 0.0
MAValue2 = 0.0
MAValue3 = 0.0

smconst = 2.0 / (1 + slw)
smconst1 = 2.0 / (1 + slwsignal)

prev = na(MAValue2[1]) ? 0.0 : MAValue2[1]

AA = 0.0
tmpDevAA = highest(pds) - lowest(pds)

if tmpDevAA != 0
    AA := 100* ((close - lowest(pds)) / tmpDevAA)
   
MAValue2 := smconst * (AA-prev) + prev


MyHigh = -999999.0
MyLow = 999999.0
for i = 0 to pds
    Price = na(MAValue2) ? 0.0 : MAValue2
    if Price != 0.0
        if Price > MyHigh
            MyHigh := Price
        if pds <= 0
            MyHigh := Price
        if Price < MyLow
            MyLow := Price
        if pds <= 0
            MyLow := Price

prev1 = na(MAValue[1]) ? 0.0 : MAValue[1]
aa1=MAValue2

bb= 0.0
if MyHigh-MyLow != 0 
    bb:=100*(aa1-MyLow)/(MyHigh-MyLow)

MAValue := smconst * (bb-prev1) + prev1

MAValue3:= ema(MAValue, slwsignal)

plot(MAValue, color = MAValue >= MAValue3 ? color.lime : color.red, linewidth = 2)
plot(MAValue3, color = color.black)
hline(20, title="Sell", color=color.gray, linestyle=hline.style_dashed)
hline(80, title="Buy", color=color.gray, linestyle=hline.style_dashed)

bgcolor(MAValue >= MAValue3 ? #38a32a : #da680f, transp=80)

2nd
Code:
//By Darkyalt
study(title="Relative Strength Index of MA", shorttitle="RSIOMA")
src = close, len = input(14, minval=1, title="Length")
up = rma(max(change(ema(src, len)), 0), len)
down = rma(-min(change(ema(src, len)), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
plot(rsi, color=blue)
band1 = hline(80)
band0 = hline(20)
fill(band1, band0, color=purple, transp=90)
hline(50, color=gray, linestyle=line)
sig = ema(rsi, 21)
plot(sig, color=purple)
 
Last edited by a moderator:

SugarTrader

Member
VIP
Hello,

Any one interested by this challenge?

An author shared his tradingview indicator (without source and without explaining the principles used to build it).
This indicator basically provide some levels on 1h chart. I found them quite relevant.

Any expert want to give a try? Identifying what is behind this indicator and eventually try to write our own version on TOS? or maybe we already have something similar? I would be interested to see your proposals
Thanks and good luck.

link to this tradingview indicator - link
here is also a couple of vids on youtube, maybe you are better than me to find some hints.
 

rad14733

Well-known member
VIP
The biggest problem with these types of studies with multiple moving averages is that they can detrimentally diminish the overall performance of Thinkorswim... A single study implementing them is fine but if you keep multiple charts up, as I do, you will see a drastic reduction in performance... I tried running the Madrid Moving Average Ribbons on about eight charts and ended up having to remove the study from my charts and I don't even consider eight charts to be an excessive number... For example, the Madrid Moving Average Ribbons paints 20 moving averages per chart... Multiply that times 8 charts and you've got 160 moving averages being repainted... And that is without calculating any other additional studies... I even tried turning off every other moving average plot to help with performance but decided I could get the same or better results without them... Just be aware that having to constantly repaint 12 - 20 moving averages on a chart takes a good amount of time and overhead... While they may look sexy, do they really give you any more information than a leaner and cleaner setup...??? Many traders would say that simpler is better...
 
Help needed for converting the indicator in thinkscript.

Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © finallynitin
//Modified TradingView script for @bankniftydoctor's RDX strategy. Original script credits to @TheProfessorDev

study("RDX Score", overlay=true)
len = input(title="length_ADX", type=integer, defval=14)
th = input(title="threshold_ADX", type=integer, defval=14)

TrueRange = max(max(high-low, abs(high-nz(close[1]))), abs(low-nz(close[1])))
DirectionalMovementPlus = high-nz(high[1]) > nz(low[1])-low ? max(high-nz(high[1]), 0): 0
DirectionalMovementMinus = nz(low[1])-low > high-nz(high[1]) ? max(nz(low[1])-low, 0): 0

SmoothedTrueRange = nz(SmoothedTrueRange[1]) - (nz(SmoothedTrueRange[1])/len) + TrueRange
SmoothedDirectionalMovementPlus = nz(SmoothedDirectionalMovementPlus[1]) - (nz(SmoothedDirectionalMovementPlus[1])/len) + DirectionalMovementPlus
SmoothedDirectionalMovementMinus = nz(SmoothedDirectionalMovementMinus[1]) - (nz(SmoothedDirectionalMovementMinus[1])/len) + DirectionalMovementMinus

DIPlus = SmoothedDirectionalMovementPlus / SmoothedTrueRange * 100
DIMinus = SmoothedDirectionalMovementMinus / SmoothedTrueRange * 100
DX = abs(DIPlus-DIMinus) / (DIPlus+DIMinus)*100
ADX = sma(DX, len)


length_RSI = input(14 )
priceRSI = close
vrsi = rsi(priceRSI, length_RSI)

m5 = ADX[1]<ADX and vrsi<30
plotshape(m5, title="SCORE -5", text="-5", textcolor=white, style=shape.labeldown, location=location.abovebar, color=red, transp=0, size=size.tiny)

m4 = (ADX[1]>ADX and vrsi<30) or (ADX[1]<ADX and vrsi<35 and vrsi>30)
plotshape(m4, title="SCORE -4", text="-4", textcolor=white, style=shape.labeldown, location=location.abovebar, color=red, transp=0, size=size.tiny)

m3 = (ADX[1]>ADX and vrsi<35 and vrsi>30) or (ADX[1]<ADX and vrsi<40 and vrsi>35)
plotshape(m3, title="SCORE -3", text="-3", textcolor=white, style=shape.labeldown, location=location.abovebar, color=red, transp=0, size=size.tiny)

m2 = (ADX[1]>ADX and vrsi<40 and vrsi>35) or (ADX[1]<ADX and vrsi<45 and vrsi>40)
plotshape(m2, title="SCORE -2", text="-2", textcolor=white, style=shape.labeldown, location=location.abovebar, color=red, transp=0, size=size.tiny)

m1 = ADX[1]>ADX and vrsi<45 and vrsi>40
plotshape(m1, title="SCORE -1", text="-1", textcolor=white, style=shape.labeldown, location=location.abovebar, color=red, transp=0, size=size.tiny)

m0 = vrsi<55 and vrsi>45
//plotshape(m0, title="QQE short", text="0", textcolor=black, style=shape.labeldown, location=location.abovebar, color=yellow, transp=0, size=size.tiny)
plotshape(m0, title="QQE long", text="0", textcolor=black, style=shape.labelup, location=location.belowbar, color=yellow, transp=0, size=size.tiny)

p1 = ADX[1]>ADX and vrsi>55 and vrsi<60
plotshape(p1, title="SCORE 1", text="1", textcolor=white, style=shape.labelup, location=location.belowbar, color=green, transp=0, size=size.tiny)

p2 = (ADX[1]>ADX and vrsi>60 and vrsi<65) or (ADX[1]<ADX and vrsi>55 and vrsi<60)
plotshape(p2, title="SCORE 2", text="2", textcolor=white, style=shape.labelup, location=location.belowbar, color=green, transp=0, size=size.tiny)

p3 = (ADX[1]>ADX and vrsi>65 and vrsi<70) or (ADX[1]<ADX and vrsi>60 and vrsi<65)
plotshape(p3, title="SCORE 3", text="3", textcolor=white, style=shape.labelup, location=location.belowbar, color=green, transp=0, size=size.tiny)

p4 = (ADX[1]>ADX and vrsi>70) or (ADX[1]<ADX and vrsi>65 and vrsi<70)
plotshape(p4, title="SCORE 4", text="4", textcolor=white, style=shape.labelup, location=location.belowbar, color=green, transp=0, size=size.tiny)

p5 = ADX[1]<ADX and vrsi>70
plotshape(p5, title="SCORE 5", text="5", textcolor=white, style=shape.labelup, location=location.belowbar, color=green, transp=0, size=size.tiny)
 
Last edited by a moderator:

borntostun

New member
Lifetime
Hi all. I have a handy little indicator that I use in the background on Tradingview -- mainly on the 4hr and daily.

Curious if anyone could assist with converting to thinkscript? The ability to scan in ToS on the HAZEMA direction up/down would a huge timesaver for me. Thanks!

-Kevin

----------------

Code:
//@version=3
//
study(title = "Heiken Ashi zero lag EMA v1.2 by JustUncleL", shorttitle="HAZEMA v1.2 by JustUncleL", overlay=true)
//

// Title: Heiken Ashi with non lag dot by JustUncleL
// Author: JustUncleL
// Version: 1.2
// Date: 5-feb-2016
//
// Description:
//  This Alert indicator utilizes the Heiken Ashi with non lag EMA was a scalping and intraday trading system
//  that has been adapted also for trading with binary options high/low. There is also included
//  filtering on MACD direction and trend direction as indicated by two MA: smoothed MA(11) and EMA(89).
//  The the Heiken Ashi candles are great as price action trending indicator, they shows smooth strong
//  and clear price fluctuations.
// 
//  Financial Markets: any.
//  Optimsed settings for 1 min, 5 min and 15 min Time Frame;
//  Expiry time for Binary options High/Low 3-6 candles.
//
//  Indicators used in calculations:
//  - Exponential moving average, period 89
//  - Smoothed moving average, period 11
//  - Non lag EMA, period 20
//  - MACD 2 colour (13,26,9)
//
//
//  Generate Alerts use the following Trading Rules
//    Heiken Ashi with non lag dot
//    Trade only in direction of the trend.
//    UP trend moving average 11 period is above Exponential moving average 89 period,
//    Doun trend moving average 11 period is below Exponential moving average 89 period,
//
//  CALL Arrow appears when:
//    Trend UP SMA11>EMA89 (optionally disabled),
//    Non lag MA blue dot and blue background.
//    Heike ashi green color.
//    MACD 2 Colour histogram green bars (optional disabled).
//
//  PUT Arrow appears when:
//    Trend UP SMA11<EMA89 (optionally disabled),
//    Heike ashi red color.
//    Non lag MA red dot and red background
//    MACD 2 colour histogram red bars (optionally disabled).
//
// Modifications:
//  1.2 - Added extra Alerts.
//      - Added optional Arrows for ZEMA direction change alerts.
//      - Updated to version3 Pinescript.
//      - Replace ZEMA calculation with more accurate formula.
//
//  0.2 - Added MACD and directional filtering.
//        Added background highlighting of Zero Lag EMA dots.
//        Replaced Bollinger Band squeeze indicator with MACD 2 colour
//  0.1 - Original version.
//
// References:
// - Almost Zero Lag EMA [LazyBear]
// - MACD 2 colour v0.2 by JustUncleL
// - http://www.forexstrategiesresources.com/binary-options-strategies-ii/163-heiken-ashi-with-non-lag-dot/
//

FastLen = input(11,minval=2,title="Fast Smoothed MA Length")
SlowLen = input(89,minval=10,title="Slow EMA Length")
length=input(20, minval=2,title="Zero Lag EMA (DOTS) Length")
umaf = input(true,title="Use Trend Directional Filter")
sarrows = input(false,title="Show ZEMA Directional Change Arrows")

//Function to Calculate Zero lag EMA
zema(src,len) =>
    lag = len>1 ? (len - 1)/2 : 0
    ema_data = (src + (src - nz(src[lag])))
    return = ema(ema_data, len)
    return


//Collect source input and Moving Average Lengths
//
// Use only Heikinashi Candles for all calculations
srcClose = security(heikinashi(tickerid), period, close)
srcOpen =  security(heikinashi(tickerid), period, open)
srcHigh =  security(heikinashi(tickerid), period, high)
srcLow =   security(heikinashi(tickerid), period, low)
//
//
fastMA = input(title="MACD Fast MA Length", type = integer, defval = 13, minval = 2)
slowMA = input(title="MACD Slow MA Length", type = integer, defval = 26, minval = 7)
signal = input(title="MACD Signal Length",  type = integer, defval = 9, minval=1)
umacd  = input(true,title="Use MACD Filtering")
//
[currMacd,currSig,_] = macd(srcClose[0], fastMA, slowMA, signal)
macdH = currMacd > 0 ? rising(currMacd,3) ? green : red : falling(currMacd,3) ? red : green
//
//Calculate No lag EMA
//ema1=ema(srcClose, length)
//ema2=ema(ema1, length)
//d=ema1-ema2
//zlema=ema1+d
zlema = zema(srcClose, length)
//
col =  zlema > zlema[1] ? blue : red
up = zlema > zlema[1] ? true : false
down = zlema < zlema[1] ? true : false
// Draw the DOT no lag MA and colour background to make it easier to see.
plot(zlema,color=col, style=circles, linewidth=4, transp=30, title="HAZEMA ZEMA line")
bgcolor(col, transp=85)

//
// Calculate Smoothed MA and EMA
FastMA = 0.0
FastMA := na(FastMA[1]) ? sma(srcClose, FastLen) : (FastMA[1] * (FastLen - 1) + srcClose) / FastLen
SlowMA = ema(srcClose,SlowLen)

// Draw the directional MA's
plot(FastMA,color=olive,transp=0,style=line,linewidth=2)
plot(SlowMA,color=red,transp=0,style=line,linewidth=2)

//
//Calculate potential Entry point
trendup = 0
trenddn = 0
trendup := up and srcOpen<srcClose and (not umaf or FastMA>SlowMA) and (not umacd or macdH==green)? na(trendup[1]) ? 1 : trendup[1]+1 : 0
trenddn := down and srcOpen>srcClose and (not umaf or FastMA<SlowMA) and (not umacd or macdH==red)? na(trenddn[1]) ? 1 : trenddn[1]+1 : 0
//Plot PUT/CALL pointer for entry
plotshape(trenddn==1, title="HAZEMA Up Arrow", style=shape.triangledown,location=location.abovebar, color=red, transp=0, size=size.small,text="PUT")
plotshape(trendup==1,  title="HAZEMA Down Arrow", style=shape.triangleup,location=location.belowbar, color=green, transp=0, size=size.small,text="CALL")

// Create alert to signal entry and plot circle along bottom to indicate alarm set
zDirection =  zlema > zlema[1] ? 1 : 2
trendalert = trendup==1 or trenddn==1
isZEMAup = change(zDirection) and zDirection==1
isZEMAdn = change(zDirection) and zDirection==2
//
alertcondition(trendalert,title="HAZEMA Alert",message="HAZEMA Alert")
alertcondition(trendup==1,title="HAZEMA Call",message="HAZEMA CALL")
alertcondition(trenddn==1,title="HAZEMA Put",message="HAZEMA PUT")
alertcondition(isZEMAup, title="HAZEMA ZEMA UP",message="HAZEMA ZEMA UP")
alertcondition(isZEMAdn, title="HAZEMA ZEMA DOWN",message="HAZEMA ZEMA DOWN")
//
plotshape(trendalert[1],  title="HAZEMA Alert Dot", style=shape.circle,location=location.bottom, color=trendup[1]?green:trenddn[1]?red:na, transp=0,offset=-1)
plotarrow(sarrows? (isZEMAup? 1 : isZEMAdn ? -1 : na) : na,  title="HAZEMA ZEMA Direction", colorup=blue, colordown=red, transp=10, minheight = 40, maxheight=50, offset=0)

//EOF
 

New Indicator: Buy the Dip

Check out our Buy the Dip indicator and see how it can help you find profitable swing trading ideas. Scanner, watchlist columns, and add-ons are included.

Download the indicator

Similar threads

Top