diff --git a/Indicators/MyIndicators/RSIMa.mq5 b/Indicators/MyIndicators/RSIMa.mq5 index a408e3a..8e21e27 100644 --- a/Indicators/MyIndicators/RSIMa.mq5 +++ b/Indicators/MyIndicators/RSIMa.mq5 @@ -121,43 +121,53 @@ int OnCalculate(const int rates_total, } //--- STEP 2: Calculate the Moving Average on the RSI buffer - for(int i = start_pos; i < rates_total; i++) + int ma_start_pos = g_ExtPeriodRSI + g_ExtPeriodMA - 1; // Correct start pos + for(int i = ma_start_pos; i < rates_total; i++) { + // --- FIX: Full, robust switch block for all MA types --- switch(InpMethod) { case MODE_EMA: - if(i == start_pos) // Initialization with manual SMA - { - double sum = 0; - for(int j = 0; j < g_ExtPeriodMA; j++) - sum += BufferRawRSI[i - j]; - BufferRSIMA[i] = sum / g_ExtPeriodMA; - } - else // Recursive calculation - { - double pr = 2.0 / (g_ExtPeriodMA + 1.0); - BufferRSIMA[i] = BufferRawRSI[i] * pr + BufferRSIMA[i-1] * (1.0 - pr); - } - break; case MODE_SMMA: - if(i == start_pos) // Initialization with manual SMA + if(i == ma_start_pos) { - double sum = 0; - for(int j = 0; j < g_ExtPeriodMA; j++) - sum += BufferRawRSI[i - j]; - BufferRSIMA[i] = sum / g_ExtPeriodMA; + double sum=0; + for(int j=0; j0) + BufferRSIMA[i]=lwma_sum/weight_sum; + } + break; default: // MODE_SMA - BufferRSIMA[i] = SimpleMA(i, g_ExtPeriodMA, BufferRawRSI); - break; + { + double sum=0; + for(int j=0; j