From 3f26a75e2e083179a26cd28cd0394076bf239e21 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Mon, 17 Mar 2025 23:02:12 +0330 Subject: [PATCH] Fix Order Blocks ... --- Classes/x-saherelm.x-bar.analyser.class.mq5 | 105 +++++++++++++++++++- Classes/x-saherelm.x-poi.class.mq5 | 66 ++++++------ Experts/x-saherelm.xpoi.test.ea.mq5 | 15 +-- Libraries/x-saherelm.x-poi.state.lib.mq5 | 16 +-- 4 files changed, 146 insertions(+), 56 deletions(-) diff --git a/Classes/x-saherelm.x-bar.analyser.class.mq5 b/Classes/x-saherelm.x-bar.analyser.class.mq5 index 6a00c2b2..1fe7ae04 100644 --- a/Classes/x-saherelm.x-bar.analyser.class.mq5 +++ b/Classes/x-saherelm.x-bar.analyser.class.mq5 @@ -1336,6 +1336,24 @@ class XCBarAnalyser : public XCBase return result; } + // + XOHCL sBar; + if (bar.Index() == 0) + { + // + result = bar.GetPreviousBar(sBar); + if (!result) + { + // + sBar.Clean(); + return result; + } + } + else + { + sBar = bar; + } + // // First Step We Have to Check Same Bars ... int spikeRootIDX = -1; @@ -1365,7 +1383,7 @@ class XCBarAnalyser : public XCBase spikeRootIDX, // Spike Root Index ... X_PRICE_CLOSE, // Price Type ... true, // Force Body ... - 1.0, // Range Extend Multiplier ... + 1.5, // Range Extend Multiplier ... sameBars // ); result = @@ -1380,12 +1398,69 @@ class XCBarAnalyser : public XCBase } // - // Select Order Block Bar ... - result = ob.Init( + // Select OB Candidate Bars ... + + XOHCL sameBar; + XOHCL rootBar; + XOHCL rootPBar; + result = sameBar.Init( bar.symbol, bar.period, sameBarsIndex + 1 // ); + if (!result) + { + // + sBar.Clean(); + sameBar.Clean(); + return result; + } + result = rootBar.Init( + bar.symbol, + bar.period, + spikeRootIDX // + ); + if (!result) + { + // + sBar.Clean(); + rootBar.Clean(); + sameBar.Clean(); + return result; + } + result = rootBar.GetPreviousBar(rootPBar); + if (!result) + { + // + sBar.Clean(); + rootBar.Clean(); + sameBar.Clean(); + rootPBar.Clean(); + return result; + } + + // + // Select ob Bar ... + if (rootBar.GetDirection() == Opposit(dir)) + { + ob = rootBar; + } + else if (rootPBar.GetDirection() == Opposit(dir)) + { + ob = rootPBar; + } + else if (sameBar.GetDirection() == Opposit(dir)) + { + ob = sameBar; + } + else + { + ob.Clean(); + } + + // + // Select Order Block Bar ... + result = ob.IsValid(); ENUM_X_DIRECTION obDir = ob.GetDirection(); result = result && @@ -1393,7 +1468,12 @@ class XCBarAnalyser : public XCBase if (!result) { // - ob.Clean(); + sBar.Clean(); + rootBar.Clean(); + sameBar.Clean(); + rootPBar.Clean(); + + // return result; } @@ -1432,7 +1512,15 @@ class XCBarAnalyser : public XCBase // if (!result) { + // ob.Clean(); + sBar.Clean(); + rootBar.Clean(); + sameBar.Clean(); + rootPBar.Clean(); + + // + return result; } } @@ -1463,6 +1551,15 @@ class XCBarAnalyser : public XCBase fromBar.Clean(); } + // + // Cleanup Resource ... + + // + sBar.Clean(); + rootBar.Clean(); + sameBar.Clean(); + rootPBar.Clean(); + // return result; } diff --git a/Classes/x-saherelm.x-poi.class.mq5 b/Classes/x-saherelm.x-poi.class.mq5 index 70937831..d3338fa1 100644 --- a/Classes/x-saherelm.x-poi.class.mq5 +++ b/Classes/x-saherelm.x-poi.class.mq5 @@ -717,7 +717,7 @@ class XCPOIDetector : public XCBaseAlert OrderBlockSameBars(3); OrderBlockForceSpike(true); OrderBlockForceFairValueGap(true); - OrderBlockForceSupportResistance(true); + OrderBlockForceSupportResistance(false); } /** @@ -846,31 +846,31 @@ class XCPOIDetector : public XCBaseAlert // // Supply ... - // DetectSupplyZone( - // iBar, - // iEvent // - // ); + DetectSupplyZone( + iBar, + iEvent // + ); // // Demand ... - // DetectDemandZone( - // iBar, - // iEvent // - // ); + DetectDemandZone( + iBar, + iEvent // + ); // // FairValueGap ... - // DetectFairValueGap( - // iBar, - // iEvent // - // ); + DetectFairValueGap( + iBar, + iEvent // + ); // // OrderBlock ... - // DetectOrderBlock( - // iBar, - // iEvent // - // ); + DetectOrderBlock( + iBar, + iEvent // + ); // canContinue = @@ -1081,10 +1081,10 @@ class XCPOIDetector : public XCBaseAlert // // Supply ... - // has = DetectSupplyZone( - // iBar, - // iEvent // - // ); + has = DetectSupplyZone( + iBar, + iEvent // + ); if (has) { // @@ -1096,10 +1096,10 @@ class XCPOIDetector : public XCBaseAlert // // Demand ... - // has = DetectDemandZone( - // iBar, - // iEvent // - // ); + has = DetectDemandZone( + iBar, + iEvent // + ); if (has) { // @@ -1111,10 +1111,10 @@ class XCPOIDetector : public XCBaseAlert // // FairValueGap ... - // has = DetectFairValueGap( - // iBar, - // iEvent // - // ); + has = DetectFairValueGap( + iBar, + iEvent // + ); if (has) { // @@ -1126,10 +1126,10 @@ class XCPOIDetector : public XCBaseAlert // // OrderBlock ... - // has = DetectOrderBlock( - // iBar, - // iEvent // - // ); + has = DetectOrderBlock( + iBar, + iEvent // + ); if (has) { // diff --git a/Experts/x-saherelm.xpoi.test.ea.mq5 b/Experts/x-saherelm.xpoi.test.ea.mq5 index ef4ee3fb..811b49dc 100644 --- a/Experts/x-saherelm.xpoi.test.ea.mq5 +++ b/Experts/x-saherelm.xpoi.test.ea.mq5 @@ -344,37 +344,30 @@ void DetectPOIState() // Bullish ... showBullishPOIs && true, // SwingLows showBullishPOIs && true, // DemandZones - showBullishPOIs && false, // SupportZones + showBullishPOIs && true, // SupportZones showBullishPOIs && true, // BullishSharps showBullishPOIs && true, // BullishSpikes showBullishPOIs && true, // BullishPullbacks showBullishPOIs && true, // BullishMomentums showBullishPOIs && true, // BullishRejections - showBullishPOIs && true, // BullishOrderBlocks + showBullishPOIs && false, // BullishOrderBlocks showBullishPOIs && true, // BullishFairValueGaps showBullishPOIs && true, // BullishConsolidationZones // // Bearish ... showBearishPOIs && true, // SwingHighs showBearishPOIs && true, // SupplyZones - showBearishPOIs && false, // ResistanceZones + showBearishPOIs && true, // ResistanceZones showBearishPOIs && true, // BearishSharps showBearishPOIs && true, // BearishSpikes showBearishPOIs && true, // BearishPullbacks showBearishPOIs && true, // BearishMomentums showBearishPOIs && true, // BearishRejections - showBearishPOIs && true, // BearishOrderBlocks + showBearishPOIs && false, // BearishOrderBlocks showBearishPOIs && true, // BearishFairValueGaps showBearishPOIs && true // BearishConsolidationZones ); - // - if (poiEventNotifier.hasNewSupportZone || - poiEventNotifier.hasNewResistanceZone) - { - Print("Support/Resistance ..."); - } - // Clean(poiEvents); poiEventNotifier.Clean(); diff --git a/Libraries/x-saherelm.x-poi.state.lib.mq5 b/Libraries/x-saherelm.x-poi.state.lib.mq5 index e5dbfa82..c3becd37 100644 --- a/Libraries/x-saherelm.x-poi.state.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.state.lib.mq5 @@ -680,8 +680,8 @@ struct XPOIStateEvents // // Supply/Demand (s) ... - bool hasSupplyZone; - bool hasDemandZone; + bool hasNewSupplyZone; + bool hasNewDemandZone; // // Fair Value Gaps ... @@ -748,8 +748,8 @@ struct XPOIStateEvents hasNewResistanceZone = false; // - hasSupplyZone = false; - hasDemandZone = false; + hasNewSupplyZone = false; + hasNewDemandZone = false; // hasNewFairValueGap = false; @@ -812,8 +812,8 @@ struct XPOIStateEvents hasNewResistanceZone = HasNewResistanceZone(events); // - hasSupplyZone = HasSupplyZone(events); - hasDemandZone = HasDemandZone(events); + hasNewSupplyZone = HasNewSupplyZone(events); + hasNewDemandZone = HasNewDemandZone(events); // hasNewFairValueGap = HasNewFairValueGap(events); @@ -4981,7 +4981,7 @@ bool HasNewResistanceZone(ENUM_XPOI_EVENTS &events[]) // Supply / Demand Zones ... // -bool HasSupplyZone(ENUM_XPOI_EVENTS &events[]) +bool HasNewSupplyZone(ENUM_XPOI_EVENTS &events[]) { return Contains( X_SUPPLY_ZONE_DETECTED, @@ -4990,7 +4990,7 @@ bool HasSupplyZone(ENUM_XPOI_EVENTS &events[]) } // -bool HasDemandZone(ENUM_XPOI_EVENTS &events[]) +bool HasNewDemandZone(ENUM_XPOI_EVENTS &events[]) { return Contains( X_DEMAND_ZONE_DETECTED,