0

If the variable barup is true, I want it to plot one series; if the variable bardown is true, I want it to plot another series value.

My current code yields the error: Cannot use "plot in local scope".

How do I change the following code to make the indicator show the number of days the lows have been above the 30 ema or below the 30 day ema based on the high or low of the current day.

Here is the code I have now:

indicator("LandryLight")
bardown = high < ta.ema(close,30)
barup = low > ta.ema(close,30)
if barup
    plot(series=ta.barssince(barup)*-1, title="Consecutive Bars Down", color=color.red, style=plot.style_histogram, linewidth=2)
if bardown
    plot(series=ta.barssince(bardown), title="Consecutive Bars Up", color=color.green, style=plot.style_histogram, linewidth=2)
hline(10,title="Threshold", color=color.white, linestyle=hline.style_dashed, linewidth=1)

1 Answer 1

0

First Use tag [pine-script]

Try going step by step, and then the plot I would do it like this:

//@version=5
indicator("LandryLight")
bardown = high < ta.ema(close,30)
barup = low > ta.ema(close,30)

barupCont = ta.barssince(barup)*-1
bardownCont = ta.barssince(bardown)
barupOK = barup ? barupCont : na
bardownOK = bardown ? bardownCont : na

plot(series= barupOK, title="Consecutive Bars Down", color=color.red, style=plot.style_histogram, linewidth=2)
plot(series= bardownOK, title="Consecutive Bars Up", color=color.green, style=plot.style_histogram, linewidth=2)
hline(10,title="Threshold", color=color.white, linestyle=hline.style_dashed, linewidth=1)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.