Cause
Inside the if block, stopLevel = low uses =, which declares a new local variable with the same name. The outer stopLevel is never updated, so the plot stays empty.
Broken code
This script compiles, but TradingView shows the warning on line 5.
//@version=6
indicator("Stop level", overlay = true)
var float stopLevel = na
if ta.crossover(close, ta.sma(close, 20))
stopLevel = low
plot(stopLevel, "Stop", color.red, style = plot.style_linebr)Fixed code
The same script, corrected for Pine Script v6. Paste it into the Pine Editor and save.
//@version=6
indicator("Stop level", overlay = true)
var float stopLevel = na
if ta.crossover(close, ta.sma(close, 20))
stopLevel := low
plot(stopLevel, "Stop", color.red, style = plot.style_linebr)Why it works
:= assigns a new value to the existing variable instead of declaring another one. Because stopLevel is declared with var, it keeps its value from bar to bar, so the plot shows the low of the bar where the last crossover happened.
When the warning is harmless
If you really wanted a separate variable that exists only inside the block, give it a different name. The warning disappears and the code says what it does. Reusing the outer name is almost always a missing :.
Questions
What is the difference between = and := in Pine Script?
= declares a new variable; := assigns a new value to a variable that already exists. Inside a local block, = creates a separate variable that disappears at the end of the block.
Can I ignore the shadowing warning?
Only if you really meant a separate local variable. In that case, rename it: the warning goes away and the code is clearer.
The scripts on this page are minimal examples written to show the error and its fix, not trading systems. Trading involves substantial risk of loss and is not suitable for every investor. Edgoro is a software tool, not a broker or financial adviser: nothing it produces is investment advice, and past or backtested performance does not guarantee future results.