indicator("Test Persistent Variables", overlay=true)
// Persistent Variables
var float A = na
var float B = na
var label status_label = na
var bool has_dropped_below_D = false
var bool has_risen_above_A = false
A := 2715
B := 2714.5
// Logic
if close > A
has_risen_above_A := true
if close < B
has_dropped_below_D := true // Update flag
if na(status_label)
status_label := label.new(x=bar_index, y=high, text="Initializing...", style=label.style_label_down, color=color.blue)
label.set_xy(status_label, bar_index, high)
label.set_text(
status_label,
"N: " + str.tostring(N) +
"\nAbove A: " + str.tostring(has_risen_above_A) +
"\nBelow B: " + str.tostring(has_dropped_below_D)
)
看起来很简单,分享一下实际代码,我来帮助你。