Reputation: 31
I have a script that I am trying to plot an X where the 2 mA's cross with line.new I have tried the line.new in another script and it seems to work so I am at a loss as to why is does not work in this script. I am just setting the y but getting the error.
//@version=5
indicator(title="My MACD with crosses", shorttitle="My MACD", timeframe="", timeframe_gaps=true)
// Get User Input
i_showCross = input.bool(title="Show MA Crossovers", defval=true)
// Calculate MA's using user input selections
fast_ma = i_sma_source == "SMA" ? ta.sma(i_src, i_fast_length) : ta.ema(i_src, i_fast_length)
slow_ma = i_sma_source == "SMA" ? ta.sma(i_src, i_slow_length) : ta.ema(i_src, i_slow_length)
crossOver = ta.crossover(fast_ma, slow_ma)
crossUnder = ta.crossunder(slow_ma, fast_ma)
// show label
crossX = label.new(bar_index, na, str.tostring(fast_ma) + "crossed under " + str.tostring(slow_ma), style=label.style_xcross, size=size.small, color=color.red, textcolor=color.red)
label.set_y(crossX,slow_ma)
Upvotes: 3
Views: 8728
Reputation: 21121
Read the error message carefully.
The 'timeframe' argument is incompatible with functions that have side effects
The timeframe
argument is in your indicator()
call so you shouldn't be looking at somewhere else.
If you don't need to change the timeframe, just remove timeframe="", timeframe_gaps=true
from your indicator()
call.
So it should be:
indicator(title="My MACD with crosses", shorttitle="My MACD")
If you need multi timeframe analysis, you should use the security() function.
Upvotes: 6