diff --git a/Indicators/MyIndicators/MovingAverage_Pro.mq5 b/Indicators/MyIndicators/MovingAverage_Pro.mq5 index 9e47358..bc2ae62 100644 --- a/Indicators/MyIndicators/MovingAverage_Pro.mq5 +++ b/Indicators/MyIndicators/MovingAverage_Pro.mq5 @@ -1,10 +1,9 @@ //+------------------------------------------------------------------+ //| MovingAverage_Pro.mq5 | //| Copyright 2025, xxxxxxxx| -//| | //+------------------------------------------------------------------+ #property copyright "Copyright 2025, xxxxxxxx" -#property version "1.10" // Added DEMA and TEMA types +#property version "1.20" // Optimized for incremental calculation #property description "Universal Moving Average (SMA, EMA, SMMA, LWMA, TMA, DEMA, TEMA)." #property indicator_chart_window #property indicator_buffers 1 @@ -64,12 +63,27 @@ int OnInit() void OnDeinit(const int reason) { if(CheckPointer(g_calculator) != POINTER_INVALID) delete g_calculator; } //+------------------------------------------------------------------+ -int OnCalculate(const int rates_total, const int, const datetime&[], const double &open[], const double &high[], const double &low[], const double &close[], const long&[], const long&[], const int&[]) +//| Custom indicator calculation function. | +//+------------------------------------------------------------------+ +int OnCalculate(const int rates_total, + const int prev_calculated, // <--- Now used! + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[]) { if(CheckPointer(g_calculator) == POINTER_INVALID) return 0; + ENUM_APPLIED_PRICE price_type = (InpSourcePrice <= PRICE_HA_CLOSE) ? (ENUM_APPLIED_PRICE)(-(int)InpSourcePrice) : (ENUM_APPLIED_PRICE)InpSourcePrice; - g_calculator.Calculate(rates_total, price_type, open, high, low, close, BufferMA); + +//--- Delegate calculation with prev_calculated optimization + g_calculator.Calculate(rates_total, prev_calculated, price_type, open, high, low, close, BufferMA); + return(rates_total); } //+------------------------------------------------------------------+