From 1fe27d41dafbf8892a967e4e91c75faf950ad9a2 Mon Sep 17 00:00:00 2001 From: "Bobby (aider)" Date: Sat, 8 Feb 2025 09:37:41 -0800 Subject: [PATCH] fix: Properly declare and initialize `trail_price` with correct reassignment --- pinescripts/Three_ATR_EMA.pine | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pinescripts/Three_ATR_EMA.pine b/pinescripts/Three_ATR_EMA.pine index 0ab2873..40cda8e 100644 --- a/pinescripts/Three_ATR_EMA.pine +++ b/pinescripts/Three_ATR_EMA.pine @@ -24,6 +24,7 @@ var float entry_price = na var float target_1 = na var float target_2 = na var float trail_stop = na +var float trail_price = na var bool trail_active = false if bullish_entry @@ -38,7 +39,9 @@ profit_target_reached = close >= target_2 // Trailing stop logic (activated by upper band touch) trail_active := trail_active or trail_activation -trail_price = math.max(high, nz(trail_price[1], high)) +if trail_active and na(trail_price) + trail_price := high +trail_price := math.max(high, nz(trail_price[1], high)) trail_stop := trail_price * (1 - trail_percent/100) // Exit strategy