tradingview pine script error "cannot use 'plot' in a local scope"

Viewed 9991

I am trying to write a simple if-then-else statement using the Pine language under Tradingview. What the code does is based upon user input.

If the box is checked, the plot the line.

If the box is not checked do not plot the line.

This is the code I have:

notPlot = -2000
var ch382= input(true, ".382")
if ch382
    plot( ch382? bottom + diff * .382:   noPlot, title="fib-.236", linewidth=3, color=color.orange )

How can I write this in a proper way?

If I try to run it, I get: “cannot use 'plot' in a local scope”

Any assistance would be greatly appreciated.

ETA: I found this thread below

How to put plot statement inside if statement

  • but -

what I need to do is to plot if the box is checked and ~not plot~ if the box is not checked.

1 Answers

ETA: figured out the issue. One would use "na" (in the case of plotting) to note that the line should not be displayed - my mistake ...

var ch382 = input(true, ".382")
plot( ch382? bottom + diff * .382:  na, title="fib-.382", linewidth=3, color=color.orange )
Related