# SUPERTREND THREE LINE STRATEGY

FX_IDC:EURUSD   Euro / U.S. Dollar
6798 views
This is slightly modified SuperTrend Script.

1.Buy when all three lines are Green and cover the position even one green become Red line
2.Sell when all the three line are red and cove the position even one become Green.

//@version=2
//Test
//
study("CandleST", shorttitle="Candle", overlay=false)
// --------------- Calculating HA Candle's values

plotcandle(open, high, low, close, title='candle', color=(open < close) ? green : red, wickcolor=gray)
// END

//The below is Super Trend Strategy
Factor1=input(1,type =float, minval=1,maxval = 100)
Factor2=input(2,type =float, minval=1,maxval = 100)
Factor3=input(3,type =float, minval=1,maxval = 100)
Pd1=input(10,minval=1,maxval = 100)
Pd2=input(10,minval=1,maxval = 100)
Pd3=input(10,minval=1,maxval = 100)
// ST 1
Up1=hl2-(Factor1*atr(Pd1))
Up2=hl2-(Factor2*atr(Pd2))
Up3=hl2-(Factor3*atr(Pd3))
Dn1=hl2+(Factor1*atr(Pd1))
Dn2=hl2+(Factor2*atr(Pd2))
Dn3=hl2+(Factor3*atr(Pd3))
//ST1
TrendUp1=close>TrendUp1? max(Up1,TrendUp1) : Up1
TrendUp2=close>TrendUp2? max(Up2,TrendUp2) : Up2
TrendUp3=close>TrendUp3? max(Up3,TrendUp3) : Up3

TrendDown1=close<TrendDown1? min(Dn1,TrendDown1) : Dn1
TrendDown2=close<TrendDown2? min(Dn2,TrendDown2) : Dn2
TrendDown3=close<TrendDown3? min(Dn3,TrendDown3) : Dn3

Trend1 = close > TrendDown1 ? 1: close< TrendUp1? -1: nz (Trend1,1)
Tsl1 = Trend1==1? TrendUp1: TrendDown1
Trend2 = close > TrendDown2 ? 1: close< TrendUp2? -1: nz (Trend2,1)
Tsl2 = Trend2==1? TrendUp2: TrendDown2
Trend3 = close > TrendDown3 ? 1: close< TrendUp3? -1: nz (Trend3,1)
Tsl3 = Trend3==1? TrendUp3: TrendDown3

linecolor1 = Trend1 == 1 ? yellow : red
linecolor2 = Trend2 == 1 ? green : red
linecolor3 = Trend3 == 1 ? #7FFF00 : red

plot(Tsl1, color = linecolor1 , style = line , linewidth = 2,title = "SuperTrend1")
plot(Tsl2, color = linecolor2 , style = line , linewidth = 2,title = "SuperTrend2")
plot(Tsl3, color = linecolor3 , style = line , linewidth = 2,title = "SuperTrend3")

plotshape(cross(close,Tsl1) and close>Tsl1 , "UpShape1", shape.flag,location.bottom,yellow,0,0)
plotshape(cross(Tsl1,close) and close<Tsl1 , "DownShape1", shape.triangledown , location.bottom, red,0,0)
//plot(Trend==1 and Trend==-1,color = linecolor, style = circles, linewidth = 3,title="Trend")

plotshape(cross(close,Tsl2) and close>Tsl2 , "UpShape2", shape.triangleup,location.bottom,green,0,0)
plotshape(cross(Tsl2,close) and close<Tsl2 , "DownShape2", shape.triangledown , location.bottom, red,0,0)
//plot(Trend==1 and Trend==-1,color = linecolor, style = circles, linewidth = 3,title="Trend")

plotshape(cross(close,Tsl3) and close>Tsl3 , "UpShape1", shape.triangleup,location.bottom,green,0,0)
plotshape(cross(Tsl3,close) and close<Tsl3 , "DownShape2", shape.triangledown , location.bottom, red,0,0)
//plot(Trend==1 and Trend==-1,color = linecolor, style = circles, linewidth = 3,title="Trend")

plotarrow(Trend1 == 1 and Trend1 == -1 ? Trend1 : na, title="UpSTArrow1", colorup=lime, maxheight=60, minheight=50, transp=0)
plotarrow(Trend1 == -1 and Trend1 == 1 ? Trend1 : na, title="DnSTArrow1", colordown=red, maxheight=60, minheight=50, transp=0)
//ST2
plotarrow(Trend2 == 1 and Trend2 == -1 ? Trend2 : na, title="UpSTArrow2", colorup=lime, maxheight=60, minheight=50, transp=0)
plotarrow(Trend2 == -1 and Trend2 == 1 ? Trend2 : na, title="DnSTArrow2", colordown=red, maxheight=60, minheight=50, transp=0)
//ST3
plotarrow(Trend3 == 1 and Trend3 == -1 ? Trend3 : na, title="UpSTArrow3", colorup=lime, maxheight=60, minheight=50, transp=0)
plotarrow(Trend3 == -1 and Trend3 == 1 ? Trend3 : na, title="DnSTArrow3", colordown=red, maxheight=60, minheight=50, transp=0)

alertcondition(Trend1 == 1 and Trend1 == -1 ? Trend1 : na, title='Up Entry Arrow', message='Up Entry Arrow!')
alertcondition(Trend1 == -1 and Trend1 == 1 ? Trend1 : na, title='Down Entry Arrow', message='Down Entry Arrow!')

Throws an error line 72 : Undeclared identifier trend1
I'd like to ask what the green and red arrows are for? Are they signals for when to buy or sell?

Apologies if they are general knowledge. I'm new to Trading View.
joyapco
Okay I get it:
Green arrows indicate if a line turned red to green at that point
Red arrows indicate if a line turned green to red at that point

Then follow the stated rule of the script:
1.Buy when all three lines are Green and cover the position even one green become Red line
2.Sell when all the three line are red and cove the position even one become Green.

So my next questions are:
1. Where do I set the stop loss?
2. What is the exit strategy for this?
Sorry: Trend1 == 1 and Trend1 == -1 is that true?
CAN I USE THIS SCRIPT ON BINARY.GUYS PLES HELP ME I NEED A BEST SCRIPT TO USER ON BINARY I HAVE LOST ALOMOST EVERYTHNG

//@version=2
//Test
//
study("CandleST", shorttitle="Candle", overlay=false)
// --------------- Calculating HA Candle's values

plotcandle(open, high, low, close, title='candle', color=(open < close) ? green : red, wickcolor=gray)
// END

//The below is Super Trend Strategy
Factor1=input(1,type =float, minval=1,maxval = 100)
Factor2=input(2,type =float, minval=1,maxval = 100)
Factor3=input(3,type =float, minval=1,maxval = 100)
Pd1=input(10,minval=1,maxval = 100)
Pd2=input(10,minval=1,maxval = 100)
Pd3=input(10,minval=1,maxval = 100)
//ST 1
Up1=hl2-(Factor1*atr(Pd1))
Up2=hl2-(Factor2*atr(Pd2))
Up3=hl2-(Factor3*atr(Pd3))
Dn1=hl2+(Factor1*atr(Pd1))
Dn2=hl2+(Factor2*atr(Pd2))
Dn3=hl2+(Factor3*atr(Pd3))
//ST1
TrendUp1=close>TrendUp1? max(Up1,TrendUp1) : Up1
TrendUp2=close>TrendUp2? max(Up2,TrendUp2) : Up2
TrendUp3=close>TrendUp3? max(Up3,TrendUp3) : Up3

TrendDown1=close<TrendDown1? min(Dn1,TrendDown1) : Dn1
TrendDown2=close<TrendDown2? min(Dn2,TrendDown2) : Dn2
TrendDown3=close<TrendDown3? min(Dn3,TrendDown3) : Dn3

Trend1 = close > TrendDown1 ? 1: close< TrendUp1? -1: nz(Trend1,1)
Tsl1 = Trend1==1? TrendUp1: TrendDown1
Trend2 = close > TrendDown2 ? 1: close< TrendUp2? -1: nz(Trend2,1)
Tsl2 = Trend2==1? TrendUp2: TrendDown2
Trend3 = close > TrendDown3 ? 1: close< TrendUp3? -1: nz(Trend3,1)
Tsl3 = Trend3==1? TrendUp3: TrendDown3

linecolor1 = Trend1 == 1 ? yellow : red
linecolor2 = Trend2 == 1 ? green : red
linecolor3 = Trend3 == 1 ? #7FFF00 : red

plot(Tsl1, color = linecolor1 , style = line , linewidth = 2,title = "SuperTrend1")
plot(Tsl2, color = linecolor2 , style = line , linewidth = 2,title = "SuperTrend2")
plot(Tsl3, color = linecolor3 , style = line , linewidth = 2,title = "SuperTrend3")

plotshape(cross(close,Tsl1) and close>Tsl1 , "UpShape1", shape.flag,location.bottom,yellow,0,0)
plotshape(cross(Tsl1,close) and close<Tsl1 , "DownShape1", shape.triangledown , location.bottom, red,0,0)
//plot(Trend==1 and Trend==-1,color = linecolor, style = circles, linewidth = 3,title="Trend")

plotshape(cross(close,Tsl2) and close>Tsl2 , "UpShape2", shape.triangleup,location.bottom,green,0,0)
plotshape(cross(Tsl2,close) and close<Tsl2 , "DownShape2", shape.triangledown , location.bottom, red,0,0)
//plot(Trend==1 and Trend==-1,color = linecolor, style = circles, linewidth = 3,title="Trend")

plotshape(cross(close,Tsl3) and close>Tsl3 , "UpShape1", shape.triangleup,location.bottom,green,0,0)
plotshape(cross(Tsl3,close) and close<Tsl3 , "DownShape2", shape.triangledown , location.bottom, red,0,0)
//plot(Trend==1 and Trend==-1,color = linecolor, style = circles, linewidth = 3,title="Trend")

plotarrow(Trend1 == 1 and Trend1 == -1 ? Trend1 : na, title="UpSTArrow1", colorup=lime, maxheight=60, minheight=50, transp=0)
plotarrow(Trend1 == -1 and Trend1 == 1 ? Trend1 : na, title="DnSTArrow1", colordown=red, maxheight=60, minheight=50, transp=0)
//ST2
plotarrow(Trend2 == 1 and Trend2 == -1 ? Trend2 : na, title="UpSTArrow2", colorup=lime, maxheight=60, minheight=50, transp=0)
plotarrow(Trend2 == -1 and Trend2 == 1 ? Trend2 : na, title="DnSTArrow2", colordown=red, maxheight=60, minheight=50, transp=0)
//ST3
plotarrow(Trend3 == 1 and Trend3 == -1 ? Trend3 : na, title="UpSTArrow3", colorup=lime, maxheight=60, minheight=50, transp=0)
plotarrow(Trend3 == -1 and Trend3 == 1 ? Trend3 : na, title="DnSTArrow3", colordown=red, maxheight=60, minheight=50, transp=0)

alertcondition(Trend1 == 1 and Trend1 == -1 ? Trend1 : na, title='Up Entry Arrow', message='Up Entry Arrow!')
alertcondition(Trend1 == -1 and Trend1 == 1 ? Trend1 : na, title='Down Entry Arrow', message='Down Entry Arrow!')