From eea3013e0d25c94a85bf796399e520ebc1ab5dcf Mon Sep 17 00:00:00 2001 From: "Bobby (aider)" Date: Sat, 8 Feb 2025 09:12:25 -0800 Subject: [PATCH] fix: Move stop plots to global scope with conditional visibility --- pinescripts/Three_ATR_EMA.pine | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pinescripts/Three_ATR_EMA.pine b/pinescripts/Three_ATR_EMA.pine index 9bd244e..1c919a7 100644 --- a/pinescripts/Three_ATR_EMA.pine +++ b/pinescripts/Three_ATR_EMA.pine @@ -42,19 +42,20 @@ if bullish_entry strategy.entry("Long", strategy.long, qty=position_size()) // Stop Management +var float current_stop = na +var float display_max_stop = na + if strategy.position_size > 0 - // Update trailing stop trail_price := math.max(high, nz(trail_price, high)) - trail_stop = trail_price * 0.98 // 2% trailing - - // Active stop is best of: initial 7% stop OR current trailing stop - current_stop = math.max(max_stop_price, trail_stop) + trail_stop = trail_price * 0.98 + current_stop := math.max(max_stop_price, trail_stop) + display_max_stop := max_stop_price strategy.exit("Stop Exit", "Long", stop=current_stop) - - // Plot stops - plot(current_stop, "Active Stop", color=color.red, style=plot.style_linebr) - plot(max_stop_price, "Max Stop", color=color.gray, style=plot.style_circles) + +// Move plots to global scope with conditional visibility +plot(strategy.position_size > 0 ? current_stop : na, "Active Stop", color=color.red, style=plot.style_linebr) +plot(strategy.position_size > 0 ? display_max_stop : na, "Max Stop", color=color.gray, style=plot.style_circles) // Visualization plot(ema, "EMA", color=color.new(#4A90E2, 0))