refactor: Optimized for incremental calculation

This commit is contained in:
Toh4iem9
2025-11-28 16:57:08 +01:00
parent 8f13d876a4
commit 9be974a2e4
@@ -1,6 +1,6 @@
//+------------------------------------------------------------------+
//| MovingAverage_Ribbon_Calculator.mqh|
//| VERSION 2.01: Corrected method definition placement. |
//| VERSION 2.10: Optimized for incremental calculation. |
//| Copyright 2025, xxxxxxxx |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, xxxxxxxx"
@@ -21,7 +21,8 @@ public:
bool Init(int p1, ENUM_MA_TYPE t1, int p2, ENUM_MA_TYPE t2,
int p3, ENUM_MA_TYPE t3, int p4, ENUM_MA_TYPE t4);
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 &ma1_buffer[], double &ma2_buffer[], double &ma3_buffer[], double &ma4_buffer[]);
};
@@ -37,7 +38,7 @@ protected:
//+==================================================================+
//+------------------------------------------------------------------+
//| |
//| Constructor |
//+------------------------------------------------------------------+
CMovingAverageRibbonCalculator::CMovingAverageRibbonCalculator(void)
{
@@ -48,7 +49,7 @@ CMovingAverageRibbonCalculator::CMovingAverageRibbonCalculator(void)
}
//+------------------------------------------------------------------+
//| |
//| Destructor |
//+------------------------------------------------------------------+
CMovingAverageRibbonCalculator::~CMovingAverageRibbonCalculator(void)
{
@@ -63,7 +64,7 @@ CMovingAverageRibbonCalculator::~CMovingAverageRibbonCalculator(void)
}
//+------------------------------------------------------------------+
//| |
//| Factory Method |
//+------------------------------------------------------------------+
CMovingAverageCalculator *CMovingAverageRibbonCalculator::CreateMAInstance(void)
{
@@ -71,7 +72,7 @@ CMovingAverageCalculator *CMovingAverageRibbonCalculator::CreateMAInstance(void)
}
//+------------------------------------------------------------------+
//| |
//| Initialization |
//+------------------------------------------------------------------+
bool CMovingAverageRibbonCalculator::Init(int p1, ENUM_MA_TYPE t1, int p2, ENUM_MA_TYPE t2,
int p3, ENUM_MA_TYPE t3, int p4, ENUM_MA_TYPE t4)
@@ -91,26 +92,25 @@ bool CMovingAverageRibbonCalculator::Init(int p1, ENUM_MA_TYPE t1, int p2, ENUM_
}
//+------------------------------------------------------------------+
//| |
//| Main Calculation (Optimized) |
//+------------------------------------------------------------------+
void CMovingAverageRibbonCalculator::Calculate(int rates_total, ENUM_APPLIED_PRICE price_type, const double &open[], const double &high[], const double &low[], const double &close[],
void CMovingAverageRibbonCalculator::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 &ma1_buffer[], double &ma2_buffer[], double &ma3_buffer[], double &ma4_buffer[])
{
if(CheckPointer(m_ma1) == POINTER_INVALID || CheckPointer(m_ma2) == POINTER_INVALID ||
CheckPointer(m_ma3) == POINTER_INVALID || CheckPointer(m_ma4) == POINTER_INVALID)
return;
m_ma1.Calculate(rates_total, price_type, open, high, low, close, ma1_buffer);
m_ma2.Calculate(rates_total, price_type, open, high, low, close, ma2_buffer);
m_ma3.Calculate(rates_total, price_type, open, high, low, close, ma3_buffer);
m_ma4.Calculate(rates_total, price_type, open, high, low, close, ma4_buffer);
//--- Delegate to individual MA calculators, passing prev_calculated
m_ma1.Calculate(rates_total, prev_calculated, price_type, open, high, low, close, ma1_buffer);
m_ma2.Calculate(rates_total, prev_calculated, price_type, open, high, low, close, ma2_buffer);
m_ma3.Calculate(rates_total, prev_calculated, price_type, open, high, low, close, ma3_buffer);
m_ma4.Calculate(rates_total, prev_calculated, price_type, open, high, low, close, ma4_buffer);
}
//+==================================================================+
//| METHOD IMPLEMENTATIONS: CMovingAverageRibbonCalculator_HA |
//+==================================================================+
//--- CORRECTED: This method definition now belongs to the _HA class ---
CMovingAverageCalculator *CMovingAverageRibbonCalculator_HA::CreateMAInstance(void)
{
return new CMovingAverageCalculator_HA();