mirror of
https://github.com/softwaredevelop/mql5.git
synced 2026-08-22 16:58:07 +00:00
refactor: Full Engine Integration
This commit is contained in:
@@ -7,103 +7,95 @@
|
|||||||
|
|
||||||
#include <MyIncludes\TSI_Calculator.mqh>
|
#include <MyIncludes\TSI_Calculator.mqh>
|
||||||
|
|
||||||
//--- Base class for polymorphism
|
//+==================================================================+
|
||||||
|
//| CLASS: CTSICalculatorOscillator |
|
||||||
|
//+==================================================================+
|
||||||
class CTSICalculatorOscillator
|
class CTSICalculatorOscillator
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
//--- Composition: Use the main TSI Calculator
|
||||||
|
CTSICalculator *m_tsi_engine;
|
||||||
|
|
||||||
//--- Persistent Buffers for Incremental Calculation
|
//--- Persistent Buffers for Incremental Calculation
|
||||||
double m_tsi_buffer[];
|
double m_tsi_buffer[];
|
||||||
double m_signal_buffer[];
|
double m_signal_buffer[];
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual bool Init(int slow_p, int fast_p, int signal_p, ENUM_MA_METHOD signal_ma)=0;
|
CTSICalculatorOscillator(void);
|
||||||
|
virtual ~CTSICalculatorOscillator(void);
|
||||||
|
|
||||||
//--- Updated: Accepts prev_calculated
|
//--- Init now takes all MA types and HA flag
|
||||||
virtual 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[],
|
bool Init(int slow_p, ENUM_MA_TYPE slow_ma, int fast_p, ENUM_MA_TYPE fast_ma, int signal_p, ENUM_MA_TYPE signal_ma, bool use_ha);
|
||||||
double &osc_buffer[])=0;
|
|
||||||
|
|
||||||
virtual ~CTSICalculatorOscillator() {};
|
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 &osc_buffer[]);
|
||||||
};
|
};
|
||||||
|
|
||||||
//--- Standard version
|
//+------------------------------------------------------------------+
|
||||||
class CTSICalculatorOscillator_Std : public CTSICalculatorOscillator
|
//| Constructor |
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
CTSICalculatorOscillator::CTSICalculatorOscillator(void) : m_tsi_engine(NULL)
|
||||||
{
|
{
|
||||||
protected:
|
}
|
||||||
CTSICalculator *m_engine;
|
|
||||||
public:
|
|
||||||
CTSICalculatorOscillator_Std(void) { m_engine = new CTSICalculator(); }
|
|
||||||
~CTSICalculatorOscillator_Std(void) { if(CheckPointer(m_engine)!=POINTER_INVALID) delete m_engine; }
|
|
||||||
|
|
||||||
virtual bool Init(int slow_p, int fast_p, int signal_p, ENUM_MA_METHOD signal_ma) override
|
//+------------------------------------------------------------------+
|
||||||
{
|
//| Destructor |
|
||||||
return m_engine.Init(slow_p, fast_p, signal_p, signal_ma);
|
//+------------------------------------------------------------------+
|
||||||
}
|
CTSICalculatorOscillator::~CTSICalculatorOscillator(void)
|
||||||
|
{
|
||||||
|
if(CheckPointer(m_tsi_engine) != POINTER_INVALID)
|
||||||
|
delete m_tsi_engine;
|
||||||
|
}
|
||||||
|
|
||||||
virtual 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 &osc_buffer[]) override
|
//| Init |
|
||||||
{
|
//+------------------------------------------------------------------+
|
||||||
if(CheckPointer(m_engine)==POINTER_INVALID)
|
bool CTSICalculatorOscillator::Init(int slow_p, ENUM_MA_TYPE slow_ma, int fast_p, ENUM_MA_TYPE fast_ma, int signal_p, ENUM_MA_TYPE signal_ma, bool use_ha)
|
||||||
return;
|
{
|
||||||
|
// Instantiate correct engine
|
||||||
// Resize internal buffers
|
if(use_ha)
|
||||||
if(ArraySize(m_tsi_buffer) != rates_total)
|
m_tsi_engine = new CTSICalculator_HA(); // Ensure CTSICalculator_HA is visible from TSI_Calculator.mqh
|
||||||
ArrayResize(m_tsi_buffer, rates_total);
|
else
|
||||||
if(ArraySize(m_signal_buffer) != rates_total)
|
m_tsi_engine = new CTSICalculator();
|
||||||
ArrayResize(m_signal_buffer, rates_total);
|
|
||||||
|
|
||||||
// Calculate TSI and Signal (Incremental)
|
|
||||||
m_engine.Calculate(rates_total, prev_calculated, price_type, open, high, low, close, m_tsi_buffer, m_signal_buffer);
|
|
||||||
|
|
||||||
// Calculate Oscillator (Incremental Loop)
|
// Initialize engine
|
||||||
int start_pos = m_engine.GetPeriodSlow() + m_engine.GetPeriodFast() + m_engine.GetPeriodSignal() - 1;
|
// Ensure the Init method signature matches exactly what is in TSI_Calculator.mqh
|
||||||
int start_index = (prev_calculated > 0) ? prev_calculated - 1 : 0;
|
return m_tsi_engine.Init(slow_p, slow_ma, fast_p, fast_ma, signal_p, signal_ma);
|
||||||
int loop_start = MathMax(start_pos, start_index);
|
}
|
||||||
|
|
||||||
for(int i = loop_start; i < rates_total; i++)
|
//+------------------------------------------------------------------+
|
||||||
{
|
//| Main Calculation |
|
||||||
osc_buffer[i] = m_tsi_buffer[i] - m_signal_buffer[i];
|
//+------------------------------------------------------------------+
|
||||||
}
|
void CTSICalculatorOscillator::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 &osc_buffer[])
|
||||||
};
|
|
||||||
|
|
||||||
//--- HA version
|
|
||||||
class CTSICalculatorOscillator_HA : public CTSICalculatorOscillator
|
|
||||||
{
|
{
|
||||||
protected:
|
if(CheckPointer(m_tsi_engine) == POINTER_INVALID)
|
||||||
CTSICalculator_HA *m_engine;
|
return;
|
||||||
public:
|
|
||||||
CTSICalculatorOscillator_HA(void) { m_engine = new CTSICalculator_HA(); }
|
|
||||||
~CTSICalculatorOscillator_HA(void) { if(CheckPointer(m_engine)!=POINTER_INVALID) delete m_engine; }
|
|
||||||
|
|
||||||
virtual bool Init(int slow_p, int fast_p, int signal_p, ENUM_MA_METHOD signal_ma) override
|
// Resize internal buffers
|
||||||
{
|
if(ArraySize(m_tsi_buffer) != rates_total)
|
||||||
return m_engine.Init(slow_p, fast_p, signal_p, signal_ma);
|
ArrayResize(m_tsi_buffer, rates_total);
|
||||||
}
|
if(ArraySize(m_signal_buffer) != rates_total)
|
||||||
|
ArrayResize(m_signal_buffer, rates_total);
|
||||||
|
|
||||||
virtual 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[],
|
// Calculate TSI and Signal (Incremental)
|
||||||
double &osc_buffer[]) override
|
// The TSI engine handles its own incremental logic
|
||||||
{
|
m_tsi_engine.Calculate(rates_total, prev_calculated, price_type, open, high, low, close, m_tsi_buffer, m_signal_buffer);
|
||||||
if(CheckPointer(m_engine)==POINTER_INVALID)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Resize internal buffers
|
// Calculate Oscillator (TSI - Signal)
|
||||||
if(ArraySize(m_tsi_buffer) != rates_total)
|
// Valid from: Slow + Fast + Signal - 2 (approx)
|
||||||
ArrayResize(m_tsi_buffer, rates_total);
|
int start_pos = m_tsi_engine.GetPeriodSlow() + m_tsi_engine.GetPeriodFast() + m_tsi_engine.GetPeriodSignal() - 1;
|
||||||
if(ArraySize(m_signal_buffer) != rates_total)
|
|
||||||
ArrayResize(m_signal_buffer, rates_total);
|
|
||||||
|
|
||||||
// Calculate TSI and Signal (Incremental)
|
int start_index = (prev_calculated > 0) ? prev_calculated - 1 : 0;
|
||||||
m_engine.Calculate(rates_total, prev_calculated, price_type, open, high, low, close, m_tsi_buffer, m_signal_buffer);
|
int loop_start = MathMax(start_pos, start_index);
|
||||||
|
|
||||||
// Calculate Oscillator (Incremental Loop)
|
if(prev_calculated == 0)
|
||||||
int start_pos = m_engine.GetPeriodSlow() + m_engine.GetPeriodFast() + m_engine.GetPeriodSignal() - 1;
|
ArrayInitialize(osc_buffer, 0.0);
|
||||||
int start_index = (prev_calculated > 0) ? prev_calculated - 1 : 0;
|
|
||||||
int loop_start = MathMax(start_pos, start_index);
|
|
||||||
|
|
||||||
for(int i = loop_start; i < rates_total; i++)
|
for(int i = loop_start; i < rates_total; i++)
|
||||||
{
|
{
|
||||||
osc_buffer[i] = m_tsi_buffer[i] - m_signal_buffer[i];
|
osc_buffer[i] = m_tsi_buffer[i] - m_signal_buffer[i];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
|
|||||||
Reference in New Issue
Block a user