From be3558104bc8ac61a559510522f6d0921c14b071 Mon Sep 17 00:00:00 2001 From: Toh4iem9 Date: Fri, 28 Nov 2025 19:09:11 +0100 Subject: [PATCH] refactor: Optimized for incremental calculation --- .../MyIncludes/Laguerre_Filter_Calculator.mqh | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/Include/MyIncludes/Laguerre_Filter_Calculator.mqh b/Include/MyIncludes/Laguerre_Filter_Calculator.mqh index 8cc8211..a5aa5d8 100644 --- a/Include/MyIncludes/Laguerre_Filter_Calculator.mqh +++ b/Include/MyIncludes/Laguerre_Filter_Calculator.mqh @@ -18,7 +18,9 @@ public: virtual ~CLaguerreFilterCalculator(void) { if(CheckPointer(m_engine) != POINTER_INVALID) delete m_engine; }; bool Init(double gamma, ENUM_INPUT_SOURCE source_type); - void Calculate(int rates_total, ENUM_APPLIED_PRICE price_type, const double &open[], const double &high[], const double &low[], const double &close[], + + //--- Updated: Accepts prev_calculated + void Calculate(int rates_total, int prev_calculated, ENUM_APPLIED_PRICE price_type, const double &open[], const double &high[], const double &low[], const double &close[], double &filter_buffer[], double &fir_buffer[]); }; @@ -29,20 +31,33 @@ bool CLaguerreFilterCalculator::Init(double gamma, ENUM_INPUT_SOURCE source_type } //+------------------------------------------------------------------+ -void CLaguerreFilterCalculator::Calculate(int rates_total, ENUM_APPLIED_PRICE price_type, const double &open[], const double &high[], const double &low[], const double &close[], +void CLaguerreFilterCalculator::Calculate(int rates_total, int prev_calculated, ENUM_APPLIED_PRICE price_type, const double &open[], const double &high[], const double &low[], const double &close[], double &filter_buffer[], double &fir_buffer[]) { - double L0[], L1[], L2[], L3[], filt[]; - m_engine.CalculateFilter(rates_total, price_type, open, high, low, close, L0, L1, L2, L3, filt); +// Note: The engine calculates L0..L3 internally, we just need the final output. +// But the engine's CalculateFilter method signature was designed to return all L buffers for debugging/other indicators. +// We can simplify the engine or just pass dummy buffers if we don't need them, +// OR update the engine to store them internally (which we did in the previous step!). - ArrayCopy(filter_buffer, filt, 0, 0, rates_total); +// Wait, in the previous step (Laguerre_Engine.mqh), I changed CalculateFilter to: +// void CalculateFilter(..., double &filt_buffer[]) +// It no longer returns L0..L3 as arguments because they are internal members now. +// So we update the call here. + + m_engine.CalculateFilter(rates_total, prev_calculated, price_type, open, high, low, close, filter_buffer); + +// FIR Filter Calculation (Simple Moving Average of Price) +// We can optimize this too. + int start_index = (prev_calculated > 0) ? prev_calculated - 1 : 0; + if(start_index < 3) + start_index = 3; if(rates_total > 3) { double price_data[]; - m_engine.GetPriceBuffer(price_data); + m_engine.GetPriceBuffer(price_data); // This gets the full price array - for(int i = 3; i < rates_total; i++) + for(int i = start_index; i < rates_total; i++) { fir_buffer[i] = (price_data[i] + 2.0 * price_data[i-1] + 2.0 * price_data[i-2] + price_data[i-3]) / 6.0; } @@ -61,4 +76,3 @@ public: }; }; //+------------------------------------------------------------------+ -//+------------------------------------------------------------------+