fix: Move stop plots to global scope with conditional visibility
This commit is contained in:
parent
5260a15b6f
commit
eea3013e0d
@ -42,19 +42,20 @@ if bullish_entry
|
|||||||
strategy.entry("Long", strategy.long, qty=position_size())
|
strategy.entry("Long", strategy.long, qty=position_size())
|
||||||
|
|
||||||
// Stop Management
|
// Stop Management
|
||||||
|
var float current_stop = na
|
||||||
|
var float display_max_stop = na
|
||||||
|
|
||||||
if strategy.position_size > 0
|
if strategy.position_size > 0
|
||||||
// Update trailing stop
|
|
||||||
trail_price := math.max(high, nz(trail_price, high))
|
trail_price := math.max(high, nz(trail_price, high))
|
||||||
trail_stop = trail_price * 0.98 // 2% trailing
|
trail_stop = trail_price * 0.98
|
||||||
|
current_stop := math.max(max_stop_price, trail_stop)
|
||||||
// Active stop is best of: initial 7% stop OR current trailing stop
|
display_max_stop := max_stop_price
|
||||||
current_stop = math.max(max_stop_price, trail_stop)
|
|
||||||
|
|
||||||
strategy.exit("Stop Exit", "Long", stop=current_stop)
|
strategy.exit("Stop Exit", "Long", stop=current_stop)
|
||||||
|
|
||||||
// Plot stops
|
// Move plots to global scope with conditional visibility
|
||||||
plot(current_stop, "Active Stop", color=color.red, style=plot.style_linebr)
|
plot(strategy.position_size > 0 ? current_stop : na, "Active Stop", color=color.red, style=plot.style_linebr)
|
||||||
plot(max_stop_price, "Max Stop", color=color.gray, style=plot.style_circles)
|
plot(strategy.position_size > 0 ? display_max_stop : na, "Max Stop", color=color.gray, style=plot.style_circles)
|
||||||
|
|
||||||
// Visualization
|
// Visualization
|
||||||
plot(ema, "EMA", color=color.new(#4A90E2, 0))
|
plot(ema, "EMA", color=color.new(#4A90E2, 0))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user