//+------------------------------------------------------------------+ //| StructureState.mqh | //| Copyright 2025, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2025, MetaQuotes Ltd." #property link "https://www.mql5.com" #property version "1.00" #include #include "../Utils/CommonHelper.mqh" enum StructureType { SWING_HIGH, SWING_LOW, PROTECTED_HIGH, PROTECTED_LOW, CONFIRMED_HIGH, CONFIRMED_LOW, BOS_BULL, BOS_BEAR, CHOCH }; struct StructurePoint { datetime time; double level; StructureType type; int timeframeMinutes; // for fractality double strength; // 1.0 initially, decays with age }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class StructureState { private: CArrayList m_swings; CArrayList m_protectedHighs; CArrayList m_protectedLows; CArrayList m_confirmedHighs; CArrayList m_confirmedLows; CArrayList m_bosBull; CArrayList m_bosBear; CArrayList m_choch; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int FindPoint(CArrayList &arrayList, datetime time, StructureType type) { int size = arrayList.Size(); for(int i = 0; i < size; i++) { StructurePoint point = arrayList.At(i); if(point.time == time && point.type == type) return i; } return -1; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ public: StructureState() {} void AddSwing(StructureType type, double level, datetime time, int tf, double strength = 1.0) { StructurePoint p; p.time = time; p.level = level; p.type = type; p.timeframeMinutes = tf; p.strength = strength; m_swings.Add(p); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void ApplyDecay(datetime currentTime, int halflifeHours = 48) { double decayFactor = MathExp(-MathLog(2) * 1.0 / halflifeHours); for(int i = 0; i < m_swings.Size(); i++) m_swings.At(i).strength *= 0.99; //--- for(int i = 0; i < m_protectedLows.Size(); i++) m_protectedLows.At(i).strength *= 0.99; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int GetSwingsCount() { return m_swings.Size(); } StructurePoint GetSwing(int idx) { return m_swings.At(idx); } StructurePoint GetLastSwing() { return m_swings.At(GetSwingsCount() - 1); } // StructurePoint GetLastProtectedHigh() { return m_protectedHighs[ArraySize(m_protectedHighs) - 1]; } // StructurePoint GetLastProtectedLow() { return m_protectedLows[ArraySize(m_protectedLows) - 1]; } // StructurePoint GetLastBOSBull() { return m_bosBull[ArraySize(m_bosBull) - 1]; } // StructurePoint GetLastBOSBear() { return m_bosBear[ArraySize(m_bosBear) - 1]; } // bool IsBullish() { return ArraySize(m_bosBull) > ArraySize(m_bosBear); } }; //+------------------------------------------------------------------+