blackbeard12
New member
Hey guys, found this cool indicator on tradingview called the SSL indicator, very useful for trend trading. Is anyone well enough versed or have any ideas on how to convert this code to thinkscript? Thank you.
The code is:
The code is:
Code:
//@version=3
study("Generalized SSL by Vts", shorttitle="GSSL", overlay=true)
// Generalized SSL:
// This is the very first time the SSL indicator, whose acronym I ignore, is on Tradingview.
// It is based on moving averages of the highs and lows.
// Similar channel indicators can be found, whereas
// this one implements the persistency inside the channel, which is rather tricky.
// The green line is the base line which decides entries and exits, possibly with trailing stops.
// With respect to the original version, here one can play with different moving averages.
// The default settings are (10,SMA)
//
// Vitelot/Yanez/Vts March 2019
//
// April 2019: added colored cloud (red=bearish, green=bullish)
lb = input(10, title="Lb", minval=1)
maType = input(type=string, defval="SMA", title="MA Type", options=["SMA","EMA","HMA","McG","WMA","Tenkan"])
hma(sig, n) => // Hull moving average definition
wma( 2*wma(sig,round(n/2))-wma(sig,n), round(sqrt(n)))
mcg(sig,length) => // Mc Ginley MA definition
mg = 0.0
mg := na(mg[1]) ? ema(sig, length) : mg[1] + (sig - mg[1]) / (length * pow(sig/mg[1], 4))
tenkan(sig,len) =>
0.5*(highest(sig,len)+lowest(sig,len))
ma(t,sig,len) =>
sss=na
if t =="SMA"
sss := sma(sig,len)
if t == "EMA"
sss := ema(sig,len)
if t == "HMA"
sss := hma(sig,len)
if t == "McG" // Mc Ginley
sss := mcg(sig,len)
if t == "Tenkan"
sss := tenkan(sig,len)
if t == "WMA"
sss := wma(sig,len)
sss
base(mah, mal) =>
bbb = na
inChannel = close<mah and close>mal
belowChannel = close<mah and close<mal
bbb := inChannel? bbb[1]: belowChannel? -1: 1
uuu = bbb==1? mal: mah
ddd = bbb==1? mah: mal
[uuu, ddd]
maH = ma(maType, high, lb)
maL = ma(maType, low, lb)
[up, dn] = base(maH,maL)
pu = plot(up, title="High MA", color=lime, linewidth=3)
pd = plot(dn, title="Low MA", color=orange, linewidth=3)
fill(pu,pd, color= up>dn? red:green, title="Cloud", transp=65)
///////////////////