0

I have no idea why I keep getting this error on the line with the longFillColor… I tried adding the colon & I tried splitting the code across multiple lines, but to no avail. It says that it is a syntax error, but I'm unable to locate the inconsistency.

//@version=5
indicator("Supertrend", overlay=true, format=format.price, precision=2)

Periods = input.int(title="ATR Period", defval=10, minval=1)
src = input(close, title="Source")
Multiplier = input.float(title="ATR Multiplier", defval=3.0, minval=0.1, step=0.1)
changeATR = input.bool(title="Change ATR Calculation Method?", defval=true)
showsignals = input.bool(title="Show Buy/Sell Signals?", defval=true)
highlighting = input.bool(title="Highlighter On/Off?", defval=true)

atr2 = ta.sma(ta.tr, Periods)
atr = changeATR ? ta.atr(Periods) : atr2

up = src - (Multiplier * atr)
up1 = ta.valuewhen(ta.close[1] > up[1], up, 1)
up := ta.close[1] > up1 ? math.max(up, up1) : up

dn = src + (Multiplier * atr)
dn1 = ta.valuewhen(ta.close[1] < dn[1], dn, 1)
dn := ta.close[1] < dn1 ? math.min(dn, dn1) : dn

trend = 1
trend := ta.valuewhen(trend[1] == -1 and ta.close > dn1, 1, 1)
trend := ta.valuewhen(trend[1] == 1 and ta.close < up1, -1, 1)

upPlot = plot(trend == 1 ? up : na, title="Up Trend", color=color.new(color.green, 0), linewidth=2)
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.new(color.green, 0))

dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", color=color.new(color.red, 0), linewidth=2)
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.new(color.red, 0))

mPlot = plot(ta.ohlc4, title="", style=plot.style_circles, linewidth=0)
longFillColor = highlighting ? (trend == 1 ? color.new(color.green, 80) : color.new(color.white, 0))
shortFillColor = highlighting ? (trend == -1 ? color.new(color.red, 80) : color.new(color.white, 0))
fill(mPlot, upPlot, title="UpTrend Highlighter", color=longFillColor) :
fill(mPlot, dnPlot, title="DownTrend Highlighter", color=shortFillColor) :

alertcondition(buySignal, title="SuperTrend Buy", message="SuperTrend Buy!")
alertcondition(sellSignal, title="SuperTrend Sell", message="SuperTrend Sell!")

changeCond = trend != ta.valuewhen(trend[1] != trend[1], trend, 1)
alertcondition(changeCond, title="SuperTrend Direction Change", message="SuperTrend has changed direction!")
W3C0d3
  • 3
  • 3

1 Answers1

0

You've got some other errors in there as well. There is no ta.close or ta.ohlc4 its just simply close or ohlc4 regardless this should work now. You needed to add another : and condition to your longfillcolor and shortfillcolor arguments

//@version=5
indicator("Supertrend", overlay=true, format=format.price, precision=2)

Periods = input.int(title="ATR Period", defval=10, minval=1)
src = input(close, title="Source")
Multiplier = input.float(title="ATR Multiplier", defval=3.0, minval=0.1, step=0.1)
changeATR = input.bool(title="Change ATR Calculation Method?", defval=true)
showsignals = input.bool(title="Show Buy/Sell Signals?", defval=true)
highlighting = input.bool(title="Highlighter On/Off?", defval=true)

atr2 = ta.sma(ta.tr, Periods)
atr = changeATR ? ta.atr(Periods) : atr2

up = src - (Multiplier * atr)
up1 = ta.valuewhen(close[1] > up[1], up, 1)
up := close[1] > up1 ? math.max(up, up1) : up

dn = src + (Multiplier * atr)
dn1 = ta.valuewhen(close[1] < dn[1], dn, 1)
dn := close[1] < dn1 ? math.min(dn, dn1) : dn

trend = 1
trend := ta.valuewhen(trend[1] == -1 and close > dn1, 1, 1)
trend := ta.valuewhen(trend[1] == 1 and close < up1, -1, 1)

upPlot = plot(trend == 1 ? up : na, title="Up Trend", color=color.new(color.green, 0), linewidth=2)
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.new(color.green, 0))

dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", color=color.new(color.red, 0), linewidth=2)
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.new(color.red, 0))

mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)
longFillColor = highlighting ? trend == 1 ? color.new(color.green, 80) : color.new(color.white, 0) : na
shortFillColor = highlighting ? trend == -1 ? color.new(color.red, 80) : color.new(color.white, 0) : na
fill(mPlot, upPlot, title="UpTrend Highlighter", color=longFillColor)
fill(mPlot, dnPlot, title="DownTrend Highlighter", color=shortFillColor)

alertcondition(buySignal, title="SuperTrend Buy", message="SuperTrend Buy!")
alertcondition(sellSignal, title="SuperTrend Sell", message="SuperTrend Sell!")

changeCond = trend != ta.valuewhen(trend[1] != trend[1], trend, 1)
alertcondition(changeCond, title="SuperTrend Direction Change", message="SuperTrend has changed direction!")
smashapalooza
  • 932
  • 2
  • 2
  • 12