From 06317c70cc0dda5e5f3cd7f5bdb666ee79565a71 Mon Sep 17 00:00:00 2001 From: Toh4iem9 Date: Fri, 28 Nov 2025 22:49:17 +0100 Subject: [PATCH] refactor: Optimized for incremental calculation --- .../MACD_Laguerre_Histogram_Pro.mq5 | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/Indicators/MyIndicators/Authors/Ehlers/5_Ehlers_Hybrids/MACD_Laguerre_Histogram_Pro.mq5 b/Indicators/MyIndicators/Authors/Ehlers/5_Ehlers_Hybrids/MACD_Laguerre_Histogram_Pro.mq5 index cafabb9..01b3493 100644 --- a/Indicators/MyIndicators/Authors/Ehlers/5_Ehlers_Hybrids/MACD_Laguerre_Histogram_Pro.mq5 +++ b/Indicators/MyIndicators/Authors/Ehlers/5_Ehlers_Hybrids/MACD_Laguerre_Histogram_Pro.mq5 @@ -1,11 +1,9 @@ //+------------------------------------------------------------------+ //| MACD_Laguerre_Histogram_Pro.mq5 | //| Copyright 2025, xxxxxxxx| -//| | //+------------------------------------------------------------------+ #property copyright "Copyright 2025, xxxxxxxx" -#property link "" -#property version "1.10" // Added selectable signal line type +#property version "1.20" // Optimized for incremental calculation #property description "Histogram for the Laguerre MACD with a selectable signal line." #property indicator_separate_window @@ -72,12 +70,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, open, high, low, close, price_type, BufferHistogram); + +//--- Delegate calculation with prev_calculated optimization + g_calculator.Calculate(rates_total, prev_calculated, open, high, low, close, price_type, BufferHistogram); + return(rates_total); } //+------------------------------------------------------------------+