diff --git a/Include/MyIncludes/Ehlers_Bands_Calculator.mqh b/Include/MyIncludes/Ehlers_Bands_Calculator.mqh index 7d6888e..02f5d80 100644 --- a/Include/MyIncludes/Ehlers_Bands_Calculator.mqh +++ b/Include/MyIncludes/Ehlers_Bands_Calculator.mqh @@ -1,9 +1,12 @@ //+------------------------------------------------------------------+ //| Ehlers_Bands_Calculator.mqh | -//| VERSION 1.20: Optimized for incremental calculation. | -//| Copyright 2025, xxxxxxxx | +//| Copyright 2026, xxxxxxxx| //+------------------------------------------------------------------+ -#property copyright "Copyright 2025, xxxxxxxx" +#property copyright "Copyright 2026, xxxxxxxx" +#property version "1.30" // Upgraded with strict internal chronological sorting safeguards + +#ifndef EHLERS_BANDS_CALCULATOR_MQH +#define EHLERS_BANDS_CALCULATOR_MQH #include @@ -18,7 +21,6 @@ protected: //--- Persistent Buffer for Price double m_price[]; - //--- Updated: Accepts start_index virtual bool PreparePriceSeries(int rates_total, int start_index, ENUM_APPLIED_PRICE price_type, const double &open[], const double &high[], const double &low[], const double &close[]); public: @@ -27,7 +29,6 @@ public: bool Init(int period, double multiplier, ENUM_SMOOTHER_TYPE smoother_type); - //--- 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 &upper_buffer[], double &lower_buffer[], double &middle_buffer[]); }; @@ -37,12 +38,14 @@ CEhlersBandsCalculator::CEhlersBandsCalculator(void) { m_calc_center = NULL; } + //+------------------------------------------------------------------+ CEhlersBandsCalculator::~CEhlersBandsCalculator(void) { if(CheckPointer(m_calc_center) != POINTER_INVALID) delete m_calc_center; } + //+------------------------------------------------------------------+ bool CEhlersBandsCalculator::Init(int period, double multiplier, ENUM_SMOOTHER_TYPE smoother_type) { @@ -65,16 +68,18 @@ void CEhlersBandsCalculator::Calculate(int rates_total, int prev_calculated, ENU if(rates_total < m_period) return; -//--- 1. Determine Start Index - int start_index; - if(prev_calculated == 0) - start_index = 0; - else - start_index = prev_calculated - 1; + if(CheckPointer(m_calc_center) == POINTER_INVALID) + return; -//--- 2. Resize Internal Buffer +//--- 1. Determine Start Index + int start_index = (prev_calculated == 0) ? 0 : prev_calculated - 1; + +//--- 2. Resize Internal Buffer and force chronological indexing if(ArraySize(m_price) != rates_total) + { ArrayResize(m_price, rates_total); + ArraySetAsSeries(m_price, false); // Fixed: strict chronological safety on internal buffers + } //--- 3. Prepare Price (Optimized) if(!PreparePriceSeries(rates_total, start_index, price_type, open, high, low, close)) @@ -108,7 +113,6 @@ void CEhlersBandsCalculator::Calculate(int rates_total, int prev_calculated, ENU //+------------------------------------------------------------------+ bool CEhlersBandsCalculator::PreparePriceSeries(int rates_total, int start_index, ENUM_APPLIED_PRICE price_type, const double &open[], const double &high[], const double &low[], const double &close[]) { -// Optimized copy loop for(int i = start_index; i < rates_total; i++) { switch(price_type) @@ -132,7 +136,7 @@ bool CEhlersBandsCalculator::PreparePriceSeries(int rates_total, int start_index m_price[i] = (high[i]+low[i]+close[i])/3.0; break; case PRICE_WEIGHTED: - m_price[i] = (high[i]+low[i]+2*close[i])/4.0; + m_price[i] = (high[i]+low[i]+2.0*close[i])/4.0; break; default: m_price[i] = close[i]; @@ -147,7 +151,6 @@ class CEhlersBandsCalculator_HA : public CEhlersBandsCalculator { private: CHeikinAshi_Calculator m_ha_calculator; - // Internal HA buffers double m_ha_open[], m_ha_high[], m_ha_low[], m_ha_close[]; public: @@ -164,20 +167,23 @@ protected: //+------------------------------------------------------------------+ bool CEhlersBandsCalculator_HA::PreparePriceSeries(int rates_total, int start_index, ENUM_APPLIED_PRICE price_type, const double &open[], const double &high[], const double &low[], const double &close[]) { -// Resize internal HA buffers +// Resize internal HA buffers and force chronological indexing if(ArraySize(m_ha_open) != rates_total) { ArrayResize(m_ha_open, rates_total); ArrayResize(m_ha_high, rates_total); ArrayResize(m_ha_low, rates_total); ArrayResize(m_ha_close, rates_total); + + ArraySetAsSeries(m_ha_open, false); + ArraySetAsSeries(m_ha_high, false); + ArraySetAsSeries(m_ha_low, false); + ArraySetAsSeries(m_ha_close, false); } -//--- STRICT CALL: Use the optimized 10-param HA calculation m_ha_calculator.Calculate(rates_total, start_index, open, high, low, close, m_ha_open, m_ha_high, m_ha_low, m_ha_close); -//--- Copy to m_price (Optimized loop) for(int i = start_index; i < rates_total; i++) { switch(price_type) @@ -201,7 +207,7 @@ bool CEhlersBandsCalculator_HA::PreparePriceSeries(int rates_total, int start_in m_price[i] = (m_ha_high[i]+m_ha_low[i]+m_ha_close[i])/3.0; break; case PRICE_WEIGHTED: - m_price[i] = (m_ha_high[i]+m_ha_low[i]+2*m_ha_close[i])/4.0; + m_price[i] = (m_ha_high[i]+m_ha_low[i]+2.0*m_ha_close[i])/4.0; break; default: m_price[i] = m_ha_close[i]; @@ -210,4 +216,5 @@ bool CEhlersBandsCalculator_HA::PreparePriceSeries(int rates_total, int start_in } return true; } +#endif // EHLERS_BANDS_CALCULATOR_MQH //+------------------------------------------------------------------+