From e0b216451551d23e1ddd690f0f5905bca341a281 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Fri, 15 Nov 2024 15:30:54 +0330 Subject: [PATCH] Last Works ... --- .../Classes/x-121.smc.base.strategy.class.mq5 | 96 +++++---- .../x-121.smc.test.strategy.class.mq5 | 190 +++++++++++++++++- 2 files changed, 247 insertions(+), 39 deletions(-) diff --git a/X121SMCEA/Classes/x-121.smc.base.strategy.class.mq5 b/X121SMCEA/Classes/x-121.smc.base.strategy.class.mq5 index 690e89f8..f3d9895e 100644 --- a/X121SMCEA/Classes/x-121.smc.base.strategy.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.base.strategy.class.mq5 @@ -1418,6 +1418,42 @@ class XCX121SMCBaseStrategy : public XCBaseAlert } } + /** + * Add Specified Object to Drawn Objects if not Exists ... + */ + void AddObjectIfNotExists(XCBaseObject *object) + { + // + string name = object.ObjName(); + + // + bool canAdd = true; + int count = mDrawnObjects.Total(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + string iName = ((XCBaseObject *)mDrawnObjects.At(i)).ObjName(); + + // + if (name == iName) + { + // + canAdd = false; + break; + } + } + } + + // + if (canAdd) + { + mDrawnObjects.Add(object); + } + } + // // Private ... private: @@ -1491,6 +1527,9 @@ class XCX121SMCBaseStrategy : public XCBaseAlert // // Initialize POIs ... + // + int poiRequired = 10; + // // 1D Period ... // POI Detector ... @@ -1499,6 +1538,9 @@ class XCX121SMCBaseStrategy : public XCBaseAlert PERIOD_D1 // ); + // + m1DPOI.MaxNumberOfRequiredPOIs(poiRequired); + // m1DPOI.Init(); @@ -1510,6 +1552,9 @@ class XCX121SMCBaseStrategy : public XCBaseAlert PERIOD_H4 // ); + // + m4HPOI.MaxNumberOfRequiredPOIs(poiRequired); + // m4HPOI.Init(); @@ -1521,6 +1566,9 @@ class XCX121SMCBaseStrategy : public XCBaseAlert PERIOD_H2 // ); + // + m2HPOI.MaxNumberOfRequiredPOIs(poiRequired); + // m2HPOI.Init(); @@ -1532,6 +1580,9 @@ class XCX121SMCBaseStrategy : public XCBaseAlert PERIOD_H1 // ); + // + m1HPOI.MaxNumberOfRequiredPOIs(poiRequired); + // m1HPOI.Init(); @@ -1543,6 +1594,9 @@ class XCX121SMCBaseStrategy : public XCBaseAlert PERIOD_M15 // ); + // + m15MPOI.MaxNumberOfRequiredPOIs(poiRequired); + // m15MPOI.Init(); @@ -1554,6 +1608,9 @@ class XCX121SMCBaseStrategy : public XCBaseAlert PERIOD_M5 // ); + // + m5MPOI.MaxNumberOfRequiredPOIs(poiRequired); + // m5MPOI.Init(); @@ -1565,6 +1622,9 @@ class XCX121SMCBaseStrategy : public XCBaseAlert PERIOD_M1 // ); + // + m1MPOI.MaxNumberOfRequiredPOIs(poiRequired); + // m1MPOI.Init(); @@ -1682,42 +1742,6 @@ class XCX121SMCBaseStrategy : public XCBaseAlert } } - /** - * Add Specified Object to Drawn Objects if not Exists ... - */ - void AddObjectIfNotExists(XCBaseObject *object) - { - // - string name = object.ObjName(); - - // - bool canAdd = true; - int count = mDrawnObjects.Total(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - string iName = ((XCBaseObject *)mDrawnObjects.At(i)).ObjName(); - - // - if (name == iName) - { - // - canAdd = false; - break; - } - } - } - - // - if (canAdd) - { - mDrawnObjects.Add(object); - } - } - // }; diff --git a/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 index 71c51f7e..f047802b 100644 --- a/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 @@ -348,18 +348,202 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy return result; } + /** + * Detect Specified States Market Structure ... + * + * @param dir: ENUM_X_DIRECTION member, Refrence ... + * @param state: XPOIState instance ... + * + * @return ( bool ) + */ bool DetectMarketStructure( ENUM_X_DIRECTION &dir, XPOIState &state // - ) { + ) + { // bool result = false; // - DrawState(state); + // DrawState(state); // - Print("Salam"); + // Print("Salam"); + + // + int count = 0; + + // + // Filter Untouched Supports ... + XCSupportZone *untouchedSupportZones[]; + count = ArraySize(state.supportZones); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCSupportZone *item = state.supportZones[i]; + + // + // Find Breakout Bar + XOHCL iBar; + bool isFilled = item.FillBar(iBar); + if (!isFilled) + { + break; + } + + // + int iBarIndex = iBar.Index(); + int iBarUnTouchedCount = 0; + for (int j = 0; j < iBarIndex; j++) + { + // + XOHCL jBar; + bool isInited = jBar.Init( + iBar.symbol, + iBar.period, + j // + ); + if (!isInited) + { + break; + } + + // + bool isUntouched = + jBar.low > item.Upper(); + if (isUntouched) + { + iBarUnTouchedCount++; + } + else + { + iBarUnTouchedCount--; + } + } + + // + if (iBarUnTouchedCount > 0) + { + // + Add( + item, + untouchedSupportZones // + ); + } + } + + // + int untouchedSupportsCount = ArraySize(untouchedSupportZones); + if (IsValidSize(untouchedSupportsCount)) + { + // + for (int i = 0; i < untouchedSupportsCount; i++) + { + // + XCSupportZone *item = untouchedSupportZones[i]; + + // + XCSupportZoneObject *iObj; + bool isCreated = mPOIDrawer.CreateSupportZone( + item, + iObj // + ); + if (isCreated) + { + AddObjectIfNotExists(iObj); + } + } + } + } + + // + // Filter Untouched Resistances ... + XCResistanceZone *untouchedResistanceZones[]; + count = ArraySize(state.resistanceZones); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCResistanceZone *item = state.resistanceZones[i]; + + // + // Find Breakout Bar + XOHCL iBar; + bool isFilled = item.FillBar(iBar); + if (!isFilled) + { + break; + } + + // + int iBarIndex = iBar.Index(); + int iBarUnTouchedCount = 0; + for (int j = 0; j < iBarIndex; j++) + { + // + XOHCL jBar; + bool isInited = jBar.Init( + iBar.symbol, + iBar.period, + j // + ); + if (!isInited) + { + break; + } + + // + bool isUntouched = + jBar.high < item.Lower(); + if (isUntouched) + { + iBarUnTouchedCount++; + } + else + { + iBarUnTouchedCount--; + } + } + + // + if (iBarUnTouchedCount > 0) + { + // + Add( + item, + untouchedResistanceZones // + ); + } + } + + // + int untouchedResistancesCount = ArraySize(untouchedResistanceZones); + if (IsValidSize(untouchedResistancesCount)) + { + // + for (int i = 0; i < untouchedResistancesCount; i++) + { + // + XCResistanceZone *item = untouchedResistanceZones[i]; + + // + XCResistanceZoneObject *iObj; + bool isCreated = mPOIDrawer.CreateResistanceZone( + item, + iObj // + ); + if (isCreated) + { + AddObjectIfNotExists(iObj); + } + } + } + } // return result;