Port IO_EMA_Delta_Oscillator from Tradingview to TOS

R

Risto Benji

New member
Can someone please help with porting the tradingview code to thinkscript, thanks!

Code:
// @version=3
study(title="IO_EMA_Delta_Oscillator", shorttitle="IO_EMAD", overlay=false )

length2 = input(20, minval=1)
mult = input(2.25)
src = input(close, title="Source")

ma = ema(src, length2)

//Slope Calculation
rad2degree=180/3.14159265359  //pi
iBarsBack=14
sma2sample=ma
ema_slope=rad2degree*atan((sma2sample[0]-nz(sma2sample[iBarsBack]))/iBarsBack)

avgTR = atr(14)

//Normalization
Length=100
normalize(series) =>
    h = highest(series, Length)
    l = lowest(series, Length)
    res = (series - l)/(h - l)

norm_slope=normalize(abs(ema_slope))
c_value=0.3 //critical value
se_color = (norm_slope>c_value) and ema_slope>0 and close>ma and open>ma? lime : (norm_slope>(c_value) and ema_slope<0) and close<ma and open<ma ? red : blue

//Plot normalized slope with bar colors
plot(norm_slope,color=se_color,title="EMA_Delta")
hline(0)
barcolor(se_color)
 

Similar threads

Top