diff --git a/Include/MyIncludes/MovingAverage_Engine.mqh b/Include/MyIncludes/MovingAverage_Engine.mqh index ca6e278..ae64964 100644 --- a/Include/MyIncludes/MovingAverage_Engine.mqh +++ b/Include/MyIncludes/MovingAverage_Engine.mqh @@ -1,19 +1,20 @@ //+------------------------------------------------------------------+ //| MovingAverage_Engine.mqh | -//| VERSION 1.11: Added public GetPeriod() method. | +//| VERSION 1.20: Added Triangular Moving Average (TMA). | //| Copyright 2025, xxxxxxxx | //+------------------------------------------------------------------+ #property copyright "Copyright 2025, xxxxxxxx" #include -//--- Enum to select the MA type for calculation --- +//--- UPDATED: Enum to select the MA type for calculation --- enum ENUM_MA_TYPE { SMA, EMA, SMMA, - LWMA + LWMA, + TMA // New type added }; //+==================================================================+ @@ -32,12 +33,12 @@ public: bool Init(int period, ENUM_MA_TYPE ma_type); void Calculate(int rates_total, ENUM_APPLIED_PRICE price_type, const double &open[], const double &high[], const double &low[], const double &close[], double &ma_buffer[]); - - //--- NEW: Public getter for the period int GetPeriod(void) const { return m_period; } }; -//--- Derived class for Heikin Ashi version --- +//+------------------------------------------------------------------+ +//| | +//+------------------------------------------------------------------+ class CMovingAverageCalculator_HA : public CMovingAverageCalculator { private: @@ -108,6 +109,33 @@ void CMovingAverageCalculator::Calculate(int rates_total, ENUM_APPLIED_PRICE pri ma_buffer[i]=sum/w_sum; } break; + case TMA: + { + // A TMA is a double-smoothed SMA. This is the most common and efficient calculation method. + // First SMA period + int period1 = (int)ceil((m_period + 1.0) / 2.0); + // Second SMA period + int period2 = m_period - period1 + 1; + + // Calculate first SMA pass + double sum1 = 0; + for(int j = 0; j < period1; j++) + sum1 += m_price[i - j]; + double sma1 = sum1 / period1; + + // Calculate second SMA pass on the results of the first + // We need to calculate the previous SMA1 values as well + double sum2 = 0; + for(int k=0; k