Search code examples
alertpine-scriptindicator

Indicator alert not working because of "side effects"


this is my first post! I´m trying to write a Pine script, actually just adding an alert when the price crosses over a lower band of a slightly modified BB indicator. When I try to add it to the chart I´m getting the following error:

"Add to Chart operation failed, reason: line 18: The 'timeframe' argument is incompatible with functions that have side effects."

Here's my code, can somebody help me understand what am I doing wrong? Thanks a lot in advance!

//@version=5
indicator(shorttitle="BB_WMA", title="Bollinger Bands WMA", overlay=true, timeframe="", timeframe_gaps=true)
length = input.int(20, minval=1)
src = input(close, title="Source")
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")
basis = ta.wma(src, length)
dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev
offset = input.int(0, "Offset", minval = -500, maxval = 500)
plot(basis, "Basis", color=#FF6D00, offset = offset)
p1 = plot(upper, "Upper", color=#2962FF, offset = offset)
p2 = plot(lower, "Lower", color=#2962FF, offset = offset)
fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 95))
//Buy Alert
BAlert = ta.crossover(volume,lower)
if BAlert
    alert("Buy", alert.freq_once_per_bar)

I already tried deleting the timeframe argument, changing "volume" to "close", but it didn't solve the problem.


Solution

  • Remove (timeframe="", timeframe_gaps=true) from your declaration

    Set your timeframe arguments elsewhere in your script if you need them