Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=3
- study(title="[V] Multi MAs", shorttitle="[V] Multi MAs", overlay=true)
- // Config
- src = input(close, title="Source")
- show_sma = input(title="Show SMAs", type=bool, defval=true)
- show_ema = input(title="Show EMAs", type=bool, defval=false)
- show_lr = input(title="Show L.Regressions", type=bool, defval=false)
- show_flat = input(title="Show Flatness", type=bool, defval=false)
- // Inputs:
- input_sma1 = input(20, minval=1, title="SMA 1")
- input_sma2 = input(50, minval=1, title="SMA 2")
- input_sma3 = input(100, minval=1, title="SMA 3")
- input_sma4 = input(200, minval=1, title="SMA 4")
- input_sma5 = input(350, minval=1, title="SMA 5")
- input_ema1 = input(2, minval=1, title="EMA 1")
- input_ema2 = input(21, minval=1, title="EMA 2")
- input_ema3 = input(55, minval=1, title="EMA 3")
- input_ema4 = input(100, minval=1, title="EMA 4")
- input_ema5 = input(200, minval=1, title="EMA 5")
- input_lr1 = input(9, minval=1, title="L.Reg 1")
- input_lr2 = input(20, minval=1, title="L.Reg 2")
- input_lr3 = input(50, minval=1, title="L.Reg 3")
- input_lr4 = input(100, minval=1, title="L.Reg 4")
- input_lr5 = input(200, minval=1, title="L.Reg 5")
- // Indicators
- ema1 = ema(src, input_ema1)
- ema2 = ema(src, input_ema2)
- ema3 = ema(src, input_ema3)
- ema4 = ema(src, input_ema4)
- ema5 = ema(src, input_ema5)
- sma1 = sma(src, input_sma1)
- sma2 = sma(src, input_sma2)
- sma3 = sma(src, input_sma3)
- sma4 = sma(src, input_sma4)
- sma5 = sma(src, input_sma5)
- lr1 = linreg(src, input_lr1, 0)
- lr2 = linreg(src, input_lr2, 0)
- lr3 = linreg(src, input_lr3, 0)
- lr4 = linreg(src, input_lr4, 0)
- lr5 = linreg(src, input_lr5, 0)
- k1 = 0.001
- // flat = (sma2[1] - sma2) >= -(sma2*k1) and (sma2[1] - sma2) <= (sma2*k1)
- // down = (sma2[2] <= sma2[1] and sma2[1] > sma2)
- // up = (sma2[2] >= sma2[1] and sma2[1] < sma2)
- // sma4_state = (sma4[2] <= sma4[1] and sma4[1] > sma4) ? "down" : (sma4[1] - sma4) >= -(sma4*k1) and (sma4[1] - sma4) <= (sma4*k1) ? "flat" : (sma4[2] >= sma4[1] and sma4[1] < sma4) ? "up" : na
- sma2_flat = (sma2[1] - sma2) >= -(sma2*k1) and (sma2[1] - sma2) <= (sma2*k1)
- sma2_down = (sma2[2] <= sma2[1] and sma2[1] > sma2)
- sma2_up = (sma2[2] >= sma2[1] and sma2[1] < sma2)
- sma4_flat = (sma4[1] - sma4) >= -(sma4*k1) and (sma4[1] - sma4) <= (sma4*k1)
- sma4_down = (sma4[2] <= sma4[1] and sma4[1] > sma4)
- sma4_up = (sma4[2] >= sma4[1] and sma4[1] < sma4)
- ema5_flat = (ema5[1] - ema5) >= -(ema5*k1) and (ema5[1] - ema5) <= (ema5*k1)
- ema5_down = (ema5[2] <= ema5[1] and ema5[1] > ema5)
- ema5_up = (ema5[2] >= ema5[1] and ema5[1] < ema5)
- // flat ? plotarrow(codiff, colorup=teal, colordown=orange, transp=40)
- lr3_flat = (lr3[1] - lr3) >= -(lr3*k1) and (lr3[1] - lr3) <= (lr3*k1)
- lr3_down = (lr3[2] <= lr3[1] and lr3[1] > lr3)
- lr3_up = (lr3[2] >= lr3[1] and lr3[1] < lr3)
- //// Plot
- plot(show_sma ? sma1 : na, title="SMA 1", color=orange, linewidth=1 )
- plot(show_sma ? sma2 : na, title="SMA 2", color=orange, linewidth=1 )
- plot(show_sma ? sma3 : na, title="SMA 3", color=orange, linewidth=2 )
- plot(show_sma ? sma4 : na, title="SMA 4", color=orange, linewidth=3 )
- plot(show_sma ? sma5 : na, title="SMA 5", color=orange, linewidth=3 )
- plot(show_ema ? ema1 : na, title="EMA 1", color=#6CA7E2, linewidth=1 )
- plot(show_ema ? ema2 : na, title="EMA 2", color=#1976D2, linewidth=1 )
- plot(show_ema ? ema3 : na, title="EMA 3", color=#104C86, linewidth=2 )
- plot(show_ema ? ema4 : na, title="EMA 4", color=#104C86, linewidth=2 )
- plot(show_ema ? ema5 : na, title="EMA 5", color=#104C86, linewidth=3 )
- plot(show_lr ? lr1 : na, title="L.Reg 1", color=red, linewidth=1)
- plot(show_lr ? lr2 : na, title="L.Reg 2", color=red, linewidth=1)
- plot(show_lr ? lr3 : na, title="L.Reg 3", color=red, linewidth=2)
- plot(show_lr ? lr4 : na, title="L.Reg 4", color=red, linewidth=2)
- plot(show_lr ? lr5 : na, title="L.Reg 5", color=red, linewidth=3)
- plotshape( show_flat and show_sma and sma2_flat ? sma2 : na, style=shape.square, location=location.absolute, color=orange)
- plotshape( show_flat and show_sma and sma2_up? sma2 : na, style=shape.triangleup, location=location.absolute, color=green)
- plotshape( show_flat and show_sma and sma2_down? sma2 : na, style=shape.triangledown, location=location.absolute, color=red)
- plotshape( show_flat and show_sma and sma4_flat and not sma4_down and not sma4_up ? sma4 : na, style=shape.square, location=location.absolute, color=orange)
- plotshape( show_flat and show_sma and sma4_down ? sma4 : na, style=shape.triangledown, location=location.absolute, color=red)
- plotshape( show_flat and show_sma and sma4_up ? sma4 : na, style=shape.triangleup, location=location.absolute, color=green)
- // plotshape( show_flat and show_ema and ema5_flat and not ema5_down and not ema5_up ? ema5 : na, style=shape.square, location=location.absolute, color=blue)
- // plotshape( show_flat and show_ema and ema5_down ? ema5 : na, style=shape.triangledown, location=location.absolute, color=red)
- // plotshape( show_flat and show_ema and ema5_up ? ema5 : na, style=shape.triangleup, location=location.absolute, color=green)
- plotshape( show_flat and show_lr and lr3_flat? lr3 : na, style=shape.square, location=location.absolute, color=orange)
- plotshape( show_flat and show_lr and lr3_down ? lr3 : na, style=shape.triangledown, location=location.absolute, color=red)
- plotshape( show_flat and show_lr and lr3_up ? lr3 : na, style=shape.triangleup, location=location.absolute, color=green)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement