CS4115
hint This level is set only on the last bar; scripts that link to it see it only there.
#What it means
A level shared only inside if (barstate.islast) exists only on the last bar. A script that links this one sees every value as of the bar it was shared, so on all earlier bars it sees no level. That is right for a value that only exists now, and wrong for a level that was known earlier. This is a hint: the script compiles and runs.
#Typical cause
- Levels worked out and shared in a last-bar block, the way drawings are often made.
#How to fix it
Share a level on the bar it becomes known, outside the last-bar block, and keep only the drawing work inside if (barstate.islast). If the value really exists only on the last bar, leave it. See Point in time.
#Example
//@chartscript 1
indicator("Range high", { overlay: true })
const hi = ta.highest(high, 50)
if (barstate.islast) {
share.level("range", "high", hi, { name: "High 50", kind: "R", side: -1 })
}
plot(hi, "High 50")Fixed
//@chartscript 1
indicator("Range high", { overlay: true })
const hi = ta.highest(high, 50)
share.level("range", "high", hi, { name: "High 50", kind: "R", side: -1 })
plot(hi, "High 50")