From 2c3a07b4ef6fe0e986c3d695b175700ce236b077 Mon Sep 17 00:00:00 2001 From: Toh4iem9 Date: Sun, 7 Dec 2025 13:28:18 +0100 Subject: [PATCH] refactor: Optimized for incremental calculation --- Indicators/MyIndicators/ALMA_Pro.mq5 | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/Indicators/MyIndicators/ALMA_Pro.mq5 b/Indicators/MyIndicators/ALMA_Pro.mq5 index b6e827b..88dff5d 100644 --- a/Indicators/MyIndicators/ALMA_Pro.mq5 +++ b/Indicators/MyIndicators/ALMA_Pro.mq5 @@ -1,11 +1,9 @@ //+------------------------------------------------------------------+ //| ALMA_Pro.mq5 | //| Copyright 2025, xxxxxxxx| -//| | //+------------------------------------------------------------------+ #property copyright "Copyright 2025, xxxxxxxx" -#property link "" -#property version "3.00" +#property version "3.10" // Optimized for incremental calculation #property description "Professional Arnaud Legoux Moving Average (ALMA) with selectable" #property description "price source, including standard and Heikin Ashi candles." @@ -82,10 +80,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[], @@ -95,21 +93,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); // Convert e.g. -1 to 1 (PRICE_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, price_type, open, high, low, close, BufferALMA); +//--- Delegate calculation with prev_calculated optimization + g_calculator.Calculate(rates_total, prev_calculated, price_type, open, high, low, close, BufferALMA); -//--- Return rates_total for a full recalculation, ensuring stability return(rates_total); } //+------------------------------------------------------------------+