2026-06-09 05:44:15 +02:00 | | | //+------------------------------------------------------------------+
|
| | | //| 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"
|
| | |
|
2026-06-10 18:31:08 +02:00 | | | #include <Collection\DynamicArrayList.mqh>
|
| | | #include "../Utils/CommonHelper.mqh"
|
2026-06-09 05:44:15 +02:00 | | |
|
2026-06-10 18:31:08 +02:00 | | | enum StructureType
|
| | | {
|
| | | SWING_HIGH,
|
| | | SWING_LOW,
|
| | | PROTECTED_HIGH,
|
| | | PROTECTED_LOW,
|
| | | CONFIRMED_HIGH,
|
| | | CONFIRMED_LOW,
|
| | | BOS_BULL,
|
| | | BOS_BEAR,
|
| | | CHOCH
|
| | | };
|
2026-06-09 05:44:15 +02:00 | | |
|
2026-06-10 18:31:08 +02:00 | | | struct StructurePoint
|
| | | {
|
| | | datetime time;
|
| | | double level;
|
| | | StructureType type;
|
| | | int timeframeMinutes; // for fractality
|
| | | double strength; // 1.0 initially, decays with age
|
| | | };
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | class StructureState
|
| | | {
|
| | | private:
|
| | | CArrayList<StructurePoint> m_swings;
|
| | | CArrayList<StructurePoint> m_protectedHighs;
|
| | | CArrayList<StructurePoint> m_protectedLows;
|
| | | CArrayList<StructurePoint> m_confirmedHighs;
|
| | | CArrayList<StructurePoint> m_confirmedLows;
|
| | | CArrayList<StructurePoint> m_bosBull;
|
| | | CArrayList<StructurePoint> m_bosBear;
|
| | | CArrayList<StructurePoint> m_choch;
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | |
|
| | | int FindPoint(CArrayList<StructurePoint> &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); }
|
| | |
|
| | | };
|
| | | //+------------------------------------------------------------------+
|