mirror of
https://github.com/softwaredevelop/mql5.git
synced 2026-08-13 04:18:04 +00:00
refactor: Optimized for incremental calculation
This commit is contained in:
@@ -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:
|
||||
};
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//+------------------------------------------------------------------+
|
||||
|
||||
Reference in New Issue
Block a user