How to use label.new() function in a Pane?

Viewed 13

I use labels very well in overlayed indicators but now I'm stuck when trying to use it in a Pane (in a basic v5 MACD code I customized).

label.new(hist[0] < hist[1] and hist[2] < hist[1] and ShowLabels ? bar_index : na, high, color=#FF0000, text="S", textcolor=color.white, tooltip = "MACD Sell", style=label.style_label_down)

It returns with the following error message:

The 'timeframe' argument is incompatible with functions that have side effects

I have a suspicion that bar_index and/or high is problematic but didn't find how to make label.new() functions Pane-compliant.

1 Answers

It's the label.new() function that causes the issue.

The timeframe argument of the indicator() is there to provide a quick and easy way to do MTF. When you get this error, it means that calculating your script for the other timeframes simply failed.

This will happen when you have drawings as they are not so easy to calculate on other tiemframes.

Even the followings will trigger this error:

label.new(na, na, na)
line.new(na, na, na, na)
box.new(na, na, na, na)

The workaround is, simply remove the timeframe argument from your indicator() and use the security() function to calculate the values you need from the other timeframes. And then use those values in your drawing function calls.

Related