'Could you make Supertrend line without break
//@version=4
study("Supertrend1", overlay = true, format=format.price, precision=2, resolution="")
PeriodsA = input(title="ATR Period", type=input.integer, defval=7)
srcA = input(hl2, title="Source")
MultiplierA = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)
changeATRA= input(title="Change ATR Calculation Method ?", type=input.bool, defval=true)
showsignalsA = input(title="Show Buy/Sell Signals ?", type=input.bool, defval=true)
highlightingA = input(title="Highlighter On/Off ?", type=input.bool, defval=true)
atr2A = sma(tr, PeriodsA)
atrA= changeATRA ? atr(PeriodsA) : atr2A
upA=srcA-(MultiplierA*atrA)
up1A = nz(upA[1],upA)
upA := close[1] > up1A ? max(upA,up1A) : upA
dnA=srcA+(MultiplierA*atrA)
dn1A = nz(dnA[1], dnA)
dnA := close[1] < dn1A ? min(dnA, dn1A) : dnA
trendA = 1
trendA := nz(trendA[1], trendA)
trendA := trendA == -1 and close > dn1A ? 1 : trendA == 1 and close < up1A ? -1 : trendA
upPlotA = plot(trendA == 1 ? upA : na, title="Up Trend", style=plot.style_linebr, linewidth=2, color=color.green)
buySignalA = trendA == 1 and trendA[1] == -1
plotshape(buySignalA ? upA : na, title="Up Arrow", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)
dnPlotA = plot(trendA == 1 ? na : dnA, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red)
sellSignalA = trendA == -1 and trendA[1] == 1
plotshape(sellSignalA ? dnA : na, title="Down Arrow", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0)
mPlotA = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)
longFillColorA = highlightingA ? (trendA == 1 ? color.green : color.white) : color.white
shortFillColorA = highlightingA ? (trendA == -1 ? color.red : color.white) : color.white
plotarrow(buySignalA ? upA : na, title="Up Arrow", colorup=color.green, maxheight=60, minheight=50, transp=0)
plotarrow(sellSignalA ? dnA : na, title="Down Arrow", colorup=color.red, maxheight=60, minheight=50, transp=0)
Supertrend line forming with break. If i change style to line from line with break, it connects with previous green line end. I want this to connect with end of red. It should be a continuous line without any break. Thanks.
Want to make Supertrend line without break like in the picture.
Solution 1:[1]
Comment lines 21 and 25, replace them with a single plot() call and include a ternary condition in both series= and color= arguments.
//@version=4
study("Supertrend1", overlay = true, format=format.price, precision=2, resolution="")
PeriodsA = input(title="ATR Period", type=input.integer, defval=7)
srcA = input(hl2, title="Source")
MultiplierA = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)
changeATRA= input(title="Change ATR Calculation Method ?", type=input.bool, defval=true)
showsignalsA = input(title="Show Buy/Sell Signals ?", type=input.bool, defval=true)
highlightingA = input(title="Highlighter On/Off ?", type=input.bool, defval=true)
atr2A = sma(tr, PeriodsA)
atrA= changeATRA ? atr(PeriodsA) : atr2A
upA=srcA-(MultiplierA*atrA)
up1A = nz(upA[1],upA)
upA := close[1] > up1A ? max(upA,up1A) : upA
dnA=srcA+(MultiplierA*atrA)
dn1A = nz(dnA[1], dnA)
dnA := close[1] < dn1A ? min(dnA, dn1A) : dnA
trendA = 1
trendA := nz(trendA[1], trendA)
trendA := trendA == -1 and close > dn1A ? 1 : trendA == 1 and close < up1A ? -1 : trendA
// upPlotA = plot(trendA == 1 ? upA : na, title="Up Trend", style=plot.style_linebr, linewidth=2, color=color.green)
buySignalA = trendA == 1 and trendA[1] == -1
plotshape(buySignalA ? upA : na, title="Up Arrow", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)
// dnPlotA = plot(trendA == 1 ? na : dnA, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red)
sellSignalA = trendA == -1 and trendA[1] == 1
plotshape(sellSignalA ? dnA : na, title="Down Arrow", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0)
mPlotA = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)
longFillColorA = highlightingA ? (trendA == 1 ? color.green : color.white) : color.white
shortFillColorA = highlightingA ? (trendA == -1 ? color.red : color.white) : color.white
plotarrow(buySignalA ? upA : na, title="Up Arrow", colorup=color.green, maxheight=60, minheight=50, transp=0)
plotarrow(sellSignalA ? dnA : na, title="Down Arrow", colorup=color.red, maxheight=60, minheight=50, transp=0)
plot(trendA == 1 ? upA : dnA, 'TrendLine', trendA == 1 ? color.green : color.red, 2, plot.style_line)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |

