From 113c1367f4904f26c19e7510c20bda86696a6071 Mon Sep 17 00:00:00 2001 From: Toh4iem9 Date: Fri, 15 Aug 2025 16:35:50 +0200 Subject: [PATCH] refactor: trend direction calculation --- Indicators/MyIndicators/Supertrend.mq5 | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/Indicators/MyIndicators/Supertrend.mq5 b/Indicators/MyIndicators/Supertrend.mq5 index dcbc9ae..4ffe458 100644 --- a/Indicators/MyIndicators/Supertrend.mq5 +++ b/Indicators/MyIndicators/Supertrend.mq5 @@ -107,40 +107,26 @@ int OnCalculate(const int rates_total, else BufferLowerBand[i] = BufferLowerBand[i-1]; - // --- Trend direction + // --- Trend direction and final Supertrend value --- int trend = 0; if(BufferSupertrend[i-1] == BufferUpperBand[i-1]) - trend = (close[i] > BufferUpperBand[i]) ? 1 : -1; // Previous was Down + trend = (close[i] > BufferUpperBand[i]) ? 1 : -1; else - trend = (close[i] < BufferLowerBand[i]) ? -1 : 1; // Previous was Up + trend = (close[i] < BufferLowerBand[i]) ? -1 : 1; - // --- Set final Supertrend value and color - if(trend == 1) // Current trend is UP + if(trend == 1) // Uptrend { BufferSupertrend[i] = BufferLowerBand[i]; BufferColor[i] = 0; // Green - - // --- FIX: Create the gap on trend change --- - // If the previous trend was DOWN, invalidate its last point - if(BufferSupertrend[i-1] == BufferUpperBand[i-1]) - { - BufferSupertrend[i-1] = EMPTY_VALUE; - } } - else // Current trend is DOWN + else // Downtrend { BufferSupertrend[i] = BufferUpperBand[i]; BufferColor[i] = 1; // Red - - // --- FIX: Create the gap on trend change --- - // If the previous trend was UP, invalidate its last point - if(BufferSupertrend[i-1] == BufferLowerBand[i-1]) - { - BufferSupertrend[i-1] = EMPTY_VALUE; - } } } return(rates_total); } //+------------------------------------------------------------------+ +//+------------------------------------------------------------------+