You are on page 1of 2

// This source code is subject to the terms of the Mozilla Public License 2.

0 at
https://mozilla.org/MPL/2.0/
// © legroszach

//@version=4
study("Triple Supertrend", overlay = true, format=format.price, precision=2,
shorttitle="3x SuperTrend")

// inputs
Periods = input(title="ATR Period 1", type=input.integer, defval=10)
src = input(hl2, title="Source 1")
Multiplier = input(title="ATR Multiplier 1", type=input.float, step=0.1,
defval=1.0)

// calculations
atr= atr(Periods)
up=src-(Multiplier*atr)
up1 = nz(up[1],up)
up := close[1] > up1 ? max(up,up1) : up
dn=src+(Multiplier*atr)
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? min(dn, dn1) : dn
trend = 1
trend := nz(trend[1], trend)

// plotting
trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend
upPlot = plot(trend == 1 ? up : na, title="Up Trend", style=plot.style_linebr,
linewidth=2, color=color.green)
buySignal = trend == 1 and trend[1] == -1
plotshape(buySignal ? up : na, title="UpTrend Begins", location=location.absolute,
style=shape.circle, size=size.tiny, color=color.green, transp=0)
dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_linebr,
linewidth=2, color=color.red)
sellSignal = trend == -1 and trend[1] == 1
plotshape(sellSignal ? dn : na, title="DownTrend Begins",
location=location.absolute, style=shape.circle, size=size.tiny, color=color.red,
transp=0)

// inputs
Periods2 = input(title="ATR Period 2", type=input.integer, defval=11)
src2 = input(hl2, title="Source 2")
Multiplier2 = input(title="ATR Multiplier 2", type=input.float, step=0.1,
defval=2.0)

// calculations
atr_2= atr(Periods2)
up_2=src2-(Multiplier2*atr_2)
up1_2 = nz(up_2[1],up_2)
up_2 := close[1] > up1_2 ? max(up_2,up1_2) : up_2
dn_2=src2+(Multiplier2*atr_2)
dn1_2 = nz(dn_2[1], dn_2)
dn_2 := close[1] < dn1_2 ? min(dn_2, dn1_2) : dn_2
trend_2 = 1
trend_2 := nz(trend_2[1], trend_2)

// plotting
trend_2 := trend_2 == -1 and close > dn1_2 ? 1 : trend_2 == 1 and close < up1 ? -
1 : trend_2
upPlot_2 = plot(trend_2 == 1 ? up_2 : na, title="Up Trend",
style=plot.style_linebr, linewidth=2, color=color.green)
buySignal_2 = trend_2 == 1 and trend_2[1] == -1
plotshape(buySignal_2 ? up_2 : na, title="UpTrend Begins",
location=location.absolute, style=shape.circle, size=size.tiny, color=color.green,
transp=0)
dnPlot_2 = plot(trend_2 == 1 ? na : dn_2, title="Down Trend",
style=plot.style_linebr, linewidth=2, color=color.red)
sellSignal_2 = trend_2 == -1 and trend_2[1] == 1
plotshape(sellSignal_2 ? dn_2 : na, title="DownTrend Begins",
location=location.absolute, style=shape.circle, size=size.tiny, color=color.red,
transp=0)

// inputs
Periods3 = input(title="ATR Period 3", type=input.integer, defval=12)
src3 = input(hl2, title="Source 3")
Multiplier3 = input(title="ATR Multiplier 3", type=input.float, step=0.1,
defval=3.0)

// calculations
atr_3= atr(Periods3)
up_3=src3-(Multiplier3*atr_3)
up1_3 = nz(up_3[1],up_3)
up_3 := close[1] > up1_3 ? max(up_3,up1_3) : up_3
dn_3=src3+(Multiplier3*atr_3)
dn1_3 = nz(dn_3[1], dn_3)
dn_3 := close[1] < dn1_3 ? min(dn_3, dn1_3) : dn_3
trend_3 = 1
trend_3 := nz(trend_3[1], trend_3)

// plotting
trend_3 := trend_3 == -1 and close > dn1_3 ? 1 : trend_3 == 1 and close < up1 ? -
1 : trend_3
upPlot_3 = plot(trend_3 == 1 ? up_3 : na, title="Up Trend",
style=plot.style_linebr, linewidth=2, color=color.green)
buySignal_3 = trend_3 == 1 and trend_3[1] == -1
plotshape(buySignal_3 ? up_3 : na, title="UpTrend Begins",
location=location.absolute, style=shape.circle, size=size.tiny, color=color.green,
transp=0)
dnPlot_3 = plot(trend_3 == 1 ? na : dn_3, title="Down Trend",
style=plot.style_linebr, linewidth=2, color=color.red)
sellSignal_3 = trend_3 == -1 and trend_3[1] == 1
plotshape(sellSignal_3 ? dn_3 : na, title="DownTrend Begins",
location=location.absolute, style=shape.circle, size=size.tiny, color=color.red,
transp=0)

You might also like