From 20aea8f6c18b0beb2a4db6fd18622ce93721bffe Mon Sep 17 00:00:00 2001 From: Toh4iem9 Date: Fri, 29 Aug 2025 00:06:27 +0200 Subject: [PATCH] refactor: calculate the signal line --- Indicators/MyIndicators/CutlerRSI_MA.mq5 | 47 +++++++++++++++--------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/Indicators/MyIndicators/CutlerRSI_MA.mq5 b/Indicators/MyIndicators/CutlerRSI_MA.mq5 index 93930a8..187ddaf 100644 --- a/Indicators/MyIndicators/CutlerRSI_MA.mq5 +++ b/Indicators/MyIndicators/CutlerRSI_MA.mq5 @@ -164,40 +164,53 @@ int OnCalculate(const int rates_total, } //--- STEP 3: Calculate the signal line (MA of Cutler's RSI) - for(int i = start_pos; i < rates_total; i++) + int ma_start_pos = g_ExtPeriodRSI + g_ExtPeriodMA - 1; + for(int i = ma_start_pos; i < rates_total; i++) { + // --- FIX: Full, robust switch block for all MA types --- switch(InpMethodMA) { case MODE_EMA: case MODE_SMMA: - if(i == start_pos) + if(i == ma_start_pos) { - double sum = 0; - for(int j = 0; j < g_ExtPeriodMA; j++) - sum += BufferCutlerRSI[i - j]; - BufferCutlerRSI_MA[i] = sum / g_ExtPeriodMA; + double sum=0; + for(int j=0; j0) + BufferCutlerRSI_MA[i]=lwma_sum/weight_sum; + } + break; default: // MODE_SMA - // Standard library function is safe here as it's not recursive - BufferCutlerRSI_MA[i] = SimpleMA(i, g_ExtPeriodMA, BufferCutlerRSI); - break; + { + double sum=0; + for(int j=0; j