From c38bb621821626cd12852b104b05b96370c19e2b Mon Sep 17 00:00:00 2001 From: Toh4iem9 Date: Mon, 1 Dec 2025 18:52:14 +0100 Subject: [PATCH] refactor: Optimized for incremental calculation --- Indicators/MyIndicators/MACD_Pro.mq5 | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/Indicators/MyIndicators/MACD_Pro.mq5 b/Indicators/MyIndicators/MACD_Pro.mq5 index 7714ce2..8474542 100644 --- a/Indicators/MyIndicators/MACD_Pro.mq5 +++ b/Indicators/MyIndicators/MACD_Pro.mq5 @@ -1,11 +1,9 @@ //+------------------------------------------------------------------+ //| MACD_Pro.mq5 | //| Copyright 2025, xxxxxxxx| -//| | //+------------------------------------------------------------------+ #property copyright "Copyright 2025, xxxxxxxx" -#property link "" -#property version "9.00" +#property version "9.10" // Optimized for incremental calculation #property description "Professional MACD with selectable MA types and price source" #property description "(Standard and Heikin Ashi)." @@ -109,10 +107,10 @@ void OnDeinit(const int reason) } //+------------------------------------------------------------------+ -//| Custom indicator calculation function. | +//| Custom indicator calculation function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, - const int prev_calculated, + const int prev_calculated, // <--- Now used! const datetime &time[], const double &open[], const double &high[], @@ -122,21 +120,18 @@ int OnCalculate(const int rates_total, const long &volume[], const int &spread[]) { -//--- Ensure the calculator object is valid if(CheckPointer(g_calculator) == POINTER_INVALID) return 0; -//--- Convert our custom enum to the standard ENUM_APPLIED_PRICE ENUM_APPLIED_PRICE price_type; if(InpSourcePrice <= PRICE_HA_CLOSE) price_type = (ENUM_APPLIED_PRICE)(-(int)InpSourcePrice); else price_type = (ENUM_APPLIED_PRICE)InpSourcePrice; -//--- Delegate the entire calculation to our calculator object - g_calculator.Calculate(rates_total, open, high, low, close, price_type, BufferMACDLine, BufferSignalLine, BufferMACD_Histogram); +//--- Delegate calculation with prev_calculated optimization + g_calculator.Calculate(rates_total, prev_calculated, open, high, low, close, price_type, BufferMACDLine, BufferSignalLine, BufferMACD_Histogram); -//--- Return rates_total for a full recalculation, ensuring stability return(rates_total); } //+------------------------------------------------------------------+