Code: Select all
//@version=4
study("Supertrend Bands", overlay=true)
//inputs
tf = input("Current", "🕒 Indicator Timeframe", options=["Current", "5min", "15min", "30min", "1H", "2H", "3H", "4H", "12H", "1D", "2D", "3D", "4D", "1W", "2W", "1M", "2M", "3M"], tooltip="This is designed for looking at higher timeframes. Choosing lower timeframes may give inaccurate results" )
tfmenu = tf == "Current"?'':tf=="5min"?'5':tf=="15min"?'15':tf=="30min"?'30':tf=="1H"?'60':tf=="2H"?'120':tf=="3H"?'180':tf=="4H"?'240':tf=="12H"?'720':tf=="1D"?'D':tf=="2D"?'2D':tf=="3D"?'3D':tf=="4D"?'4D':tf=="1W"?'W':tf=="2W"?'2W':tf=="1M"?'M':tf=="2M"?'2M':tf=="3M"?'3M':na
fills = input(true, "Fills? | ", input.bool, inline="opts")
anti = input (true, "Remove Anti-trend? | ", input.bool, inline="opts")
lwidth = input("1", "Linewidth", options=["1", "2", "3", "4"], inline="opts")
var width = lwidth == "1" ? 1 : lwidth == "2" ? 2 : lwidth == "3" ? 3 : lwidth == "4" ? 4 : na
b1 = input(true, "Band 1 | ", input.bool, inline="b1", group="Lengths and Multipliers 🔨")
len1 = input(10, "Length", input.integer, inline="b1", group="Lengths and Multipliers 🔨")
mult1 = input(1, "Mult", input.float, inline="b1", group="Lengths and Multipliers 🔨" )
b2 = input(true, "Band 2 | ", input.bool, inline="b2", group="Lengths and Multipliers 🔨")
len2 = input(11, "Length", input.integer, inline="b2", group="Lengths and Multipliers 🔨")
mult2 = input(2, "Mult", input.float, inline="b2", group="Lengths and Multipliers 🔨")
b3 = input(true, "Band 3 | ", input.bool, inline="b3", group="Lengths and Multipliers 🔨")
len3 = input(12, "Length", input.integer, inline="b3", group="Lengths and Multipliers 🔨")
mult3 = input(3, "Mult", input.float, inline="b3", group="Lengths and Multipliers 🔨")
b4 = input(true, "Band 4 | ", input.bool, inline="b4", group="Lengths and Multipliers 🔨")
len4 = input(13, "Length", input.integer, inline="b4", group="Lengths and Multipliers 🔨")
mult4 = input(4, "Mult", input.float, inline="b4", group="Lengths and Multipliers 🔨")
//colors
// colors b1
dcol1 = input(color.new(#e20404, 0), "Band 1 Color", input.color, inline="c1", group="Colors and Fills 🎨")
ucol1 = input(color.new(#00cc9c, 0), "", input.color, inline="c1", group="Colors and Fills 🎨")
dfill1 = input(color.new(#e20404, 90), " | Fills", input.color, inline="c1", group="Colors and Fills 🎨")
ufill1 = input(color.new(#00cc9c, 90), "", input.color, inline="c1", group="Colors and Fills 🎨")
//colors b2
dcol2 = input(color.new(#fb3131, 0), "Band 2 Color", input.color, inline="c2", group="Colors and Fills 🎨")
ucol2 = input(color.new(#00e3ff, 0), "", input.color, inline="c2", group="Colors and Fills 🎨")
dfill2 = input(color.new(#fb3131, 90), " | Fills", input.color, inline="c2", group="Colors and Fills 🎨")
ufill2 = input(color.new(#00e3ff, 90), "", input.color, inline="c2", group="Colors and Fills 🎨")
//colors b3
dcol3 = input(color.new(#f5459e, 0), "Band 3 Color", input.color, inline="c3", group="Colors and Fills 🎨")
ucol3 = input(color.new(#008dff, 0), "", input.color, inline="c3", group="Colors and Fills 🎨")
dfill3 = input(color.new(#f5459e, 90), " | Fills", input.color, inline="c3", group="Colors and Fills 🎨")
ufill3 = input(color.new(#008dff, 90), "", input.color, inline="c3", group="Colors and Fills 🎨")
//colors b4
dcol4 = input(color.new(#e02dff, 0), "Band 4 Color", input.color, inline="c4", group="Colors and Fills 🎨")
ucol4 = input(color.new(#5000ff, 0), "", input.color, inline="c4", group="Colors and Fills 🎨")
dfill4 = input(color.new(#e02dff, 90), " | Fills", input.color, inline="c4", group="Colors and Fills 🎨")
ufill4 = input(color.new(#5000ff, 90), "", input.color, inline="c4", group="Colors and Fills 🎨")
i_bc = input(true, "Bar Colors?", input.bool, inline="bc", group="Bar Colors 📊")
i_bt = input(30, "| Transparency", input.integer, inline="bc", group="Bar Colors 📊")
[st1, dir1] = security(syminfo.tickerid, tfmenu, supertrend(mult1, len1), barmerge.gaps_off, barmerge.lookahead_on)
res1 = dir1 == 1 and dir1 == dir1[1]
sup1 = dir1 == -1 and dir1 == dir1[1]
[st2, dir2] = security(syminfo.tickerid, tfmenu, supertrend(mult2, len2), barmerge.gaps_off, barmerge.lookahead_on)
res2 = dir2 == 1 and dir2 == dir2[1]
sup2 = dir2 == -1 and dir2 == dir2[1]
[st3, dir3] = security(syminfo.tickerid, tfmenu, supertrend(mult3, len3), barmerge.gaps_off, barmerge.lookahead_on)
res3 = dir3 == 1 and dir3 == dir3[1]
sup3 = dir3 == -1 and dir3 == dir3[1]
[st4, dir4] = security(syminfo.tickerid, tfmenu, supertrend(mult4, len4), barmerge.gaps_off, barmerge.lookahead_on)
res4 = dir4 == 1 and dir4 == dir4[1]
sup4 = dir4 == -1 and dir4 == dir4[1]
cond1 = anti ? close < st4 : res1 and b1
cond2 = anti ? close > st4 : sup1 and b1
cond3 = anti ? close < st4 : res2 and b1
cond4 = anti ? close > st4 : sup2 and b1
cond5 = anti ? close < st4 : res3 and b1
cond6 = anti ? close > st4 : sup3 and b1
hl = plot(ohlc4, display=display.none, editable=false)
b1p1 = plot(res1 and b1 and cond1 ? st1 : na, color = dcol1, linewidth=width, style=plot.style_linebr, editable=false)
fill (hl, b1p1, color = fills ? dfill1 : na, editable=false)
b1p2 = plot(sup1 and b1 and cond2 ? st1 : na, color = ucol1, linewidth=width, style=plot.style_linebr, editable=false)
fill (hl, b1p2, color = fills ? ufill1 : na, editable=false)
//
b2p1 = plot(res2 and b2 and cond3 ? st2 : na, color = dcol2, linewidth=width, style=plot.style_linebr, editable=false)
fill (b1p1, b2p1, color = fills ? dfill2 : na, editable=false)
b2p2 = plot(sup2 and b2 and cond4 ? st2 : na, color = ucol2, linewidth=width, style=plot.style_linebr, editable=false)
fill (b1p2, b2p2, color = fills ? ufill2 : na, editable=false)
//
b3p1 = plot(res3 and b3 and cond5 ? st3 : na, color = dcol3, linewidth=width, style=plot.style_linebr, editable=false)
fill (b2p1, b3p1, color = fills ? dfill3 : na, editable=false)
b3p2 = plot(sup3 and b3 and cond6 ? st3 : na, color = ucol3, linewidth=width, style=plot.style_linebr, editable=false)
fill (b2p2, b3p2, color = fills ? ufill3 : na, editable=false)
//
b4p1 = plot(res4 and b4 ? st4 : na, color = dcol4, linewidth=width, style=plot.style_linebr, editable=false)
fill (b3p1, b4p1, color = fills ? dfill4 : na, editable=false)
b4p2 = plot(sup4 and b4 ? st4 : na, color = ucol4, linewidth=width, style=plot.style_linebr, editable=false)
fill (b3p2, b4p2, color = fills ? ufill4 : na, editable=false)
// barcolor
c1 = input(#ff0000, "🔴 Bear Colors", input.color, inline="bear")
c2 = input(#ed5300, "", input.color, inline="bear")
c3 = input(#fb9c2d, "", input.color, inline="bear")
c4 = input(#ffec44, "", input.color, inline="bear")
c5 = input(#00e983, "🟢 Bull Colors", input.color, inline="bull")
c6 = input(#00eed8, "", input.color, inline="bull")
c7 = input(#008dff, "", input.color, inline="bull")
c8 = input(#5000ff, "", input.color, inline="bull")
bc1 = close < st1 and close < st4 ? color.new(c1, i_bt) : close > st1 and close <st2 and close <st4 ? color.new(c2, i_bt) : close > st1 and close > st2 and close < st3 and close < st4 ? color.new(c3, i_bt) : close < st4 and close > st3 ? color.new(c4, i_bt) : na
bc2 = close > st4 and close > st1 ? color.new(c5, i_bt) : close > st4 and close > st2 and close < st1 ? color.new(c6, i_bt) : close > st4 and close > st3 and close < st2 ? color.new(c7, i_bt) : close >st4 and close <st3 ? color.new(c8, i_bt) : bc1
barcolor(i_bc ? bc2 : na)
alertcondition(close > st4, "Close Above Band 4", "Close Above Band 4")
alertcondition(close < st4, "Close Below Band 4", "Close Below Band 4")
alertcondition(close > st3, "Close Above Band 3", "Close Above Band 3")
alertcondition(close < st3, "Close Below Band 3", "Close Below Band 3")
alertcondition(close > st2, "Close Above Band 2", "Close Above Band 2")
alertcondition(close < st2, "Close Below Band 2", "Close Below Band 2")
alertcondition(close > st1, "Close Above Band 1", "Close Above Band 1")
alertcondition(close < st1, "Close Below Band 1", "Close Below Band 1")