mirror of
https://github.com/softwaredevelop/mql5.git
synced 2026-08-21 16:28:06 +00:00
refactor: Optimized FIR calculation using direct getter
This commit is contained in:
@@ -1,12 +1,16 @@
|
|||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
//| Laguerre_Filter_Calculator.mqh |
|
//| Laguerre_Filter_Calculator.mqh |
|
||||||
//| Adapter for the Laguerre Filter indicator. |
|
//| Adapter for the Laguerre Filter indicator. |
|
||||||
//| Copyright 2025, xxxxxxxx |
|
//| VERSION 1.30: Optimized FIR calculation using direct getter |
|
||||||
|
//| Copyright 2026, xxxxxxxx |
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
#property copyright "Copyright 2025, xxxxxxxx"
|
#property copyright "Copyright 2026, xxxxxxxx"
|
||||||
|
#property version "1.30"
|
||||||
|
|
||||||
#include <MyIncludes\Laguerre_Engine.mqh>
|
#include <MyIncludes\Laguerre_Engine.mqh>
|
||||||
|
|
||||||
|
//+==================================================================+
|
||||||
|
//| CLASS: CLaguerreFilterCalculator |
|
||||||
//+==================================================================+
|
//+==================================================================+
|
||||||
class CLaguerreFilterCalculator
|
class CLaguerreFilterCalculator
|
||||||
{
|
{
|
||||||
@@ -24,36 +28,39 @@ public:
|
|||||||
double &filter_buffer[], double &fir_buffer[]);
|
double &filter_buffer[], double &fir_buffer[]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
//| Init |
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
bool CLaguerreFilterCalculator::Init(double gamma, ENUM_INPUT_SOURCE source_type)
|
bool CLaguerreFilterCalculator::Init(double gamma, ENUM_INPUT_SOURCE source_type)
|
||||||
{
|
{
|
||||||
return m_engine.Init(gamma, source_type);
|
return m_engine.Init(gamma, source_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
//| Calculate (Optimized) |
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
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[],
|
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 &filter_buffer[], double &fir_buffer[])
|
||||||
{
|
{
|
||||||
m_engine.CalculateFilter(rates_total, prev_calculated, price_type, open, high, low, close, filter_buffer);
|
m_engine.CalculateFilter(rates_total, prev_calculated, price_type, open, high, low, close, filter_buffer);
|
||||||
|
|
||||||
// FIR Filter Calculation (Simple Moving Average of Price)
|
// FIR Filter Calculation (Optimized using the dynamic inline GetPrice getter)
|
||||||
// We can optimize this too.
|
|
||||||
int start_index = (prev_calculated > 0) ? prev_calculated - 1 : 0;
|
int start_index = (prev_calculated > 0) ? prev_calculated - 1 : 0;
|
||||||
if(start_index < 3)
|
if(start_index < 3)
|
||||||
start_index = 3;
|
start_index = 3;
|
||||||
|
|
||||||
if(rates_total > 3)
|
if(rates_total > 3)
|
||||||
{
|
{
|
||||||
double price_data[];
|
// FIXED: Uses direct m_engine.GetPrice() to prevent massive memory copy overhead per tick!
|
||||||
m_engine.GetPriceBuffer(price_data); // This gets the full price array
|
|
||||||
|
|
||||||
for(int i = start_index; 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;
|
fir_buffer[i] = (m_engine.GetPrice(i) + 2.0 * m_engine.GetPrice(i-1) + 2.0 * m_engine.GetPrice(i-2) + m_engine.GetPrice(i-3)) / 6.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//+==================================================================+
|
||||||
|
//| CLASS 2: CLaguerreFilterCalculator_HA |
|
||||||
//+==================================================================+
|
//+==================================================================+
|
||||||
class CLaguerreFilterCalculator_HA : public CLaguerreFilterCalculator
|
class CLaguerreFilterCalculator_HA : public CLaguerreFilterCalculator
|
||||||
{
|
{
|
||||||
@@ -66,3 +73,4 @@ public:
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
|||||||
Reference in New Issue
Block a user