From 7adb4535e9866fd3cf5304b68056bfd0fef4db8e Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Mon, 17 Mar 2025 14:42:26 +0330 Subject: [PATCH] complete consolidation Zones ... --- Classes/x-saherelm.x-bar.analyser.class.mq5 | 89 ++++++++++---- Classes/x-saherelm.x-poi.class.mq5 | 129 ++++++++++++-------- Experts/x-saherelm.xpoi.test.ea.mq5 | 40 +++--- 3 files changed, 162 insertions(+), 96 deletions(-) diff --git a/Classes/x-saherelm.x-bar.analyser.class.mq5 b/Classes/x-saherelm.x-bar.analyser.class.mq5 index fb255dd3..cf0f78ef 100644 --- a/Classes/x-saherelm.x-bar.analyser.class.mq5 +++ b/Classes/x-saherelm.x-bar.analyser.class.mq5 @@ -211,7 +211,7 @@ class XCBarAnalyser : public XCBase * * @return ( bool ) */ - bool FillPrice( + int FillPrice( double &prices[], XOHCL &bar, int loopback = 14, @@ -219,7 +219,7 @@ class XCBarAnalyser : public XCBase ) { // - bool result = false; + int result = 0; // Clean(prices); @@ -228,9 +228,9 @@ class XCBarAnalyser : public XCBase loopback = NormalizeInt(loopback, 1); // - result = IsValid(type) && + bool has = IsValid(type) && bar.IsValid(); - if (!result) + if (!has) { return result; } @@ -245,7 +245,7 @@ class XCBarAnalyser : public XCBase int start = -1; int end = -1; int count = -1; - result = CalculateLoopbackData( + has = CalculateLoopbackData( index, start, end, @@ -253,13 +253,13 @@ class XCBarAnalyser : public XCBase bar, loopback // ); - if (!result) + if (!has) { return result; } // - for (int i = index; i < count; i++) + for (int i = start; i < end; i++) { // XOHCL iBar; @@ -294,9 +294,11 @@ class XCBarAnalyser : public XCBase } // - result = ArraySize(prices) == count; - if (!result) + result = ArraySize(prices); + has = result == count; + if (!has) { + // Clean(prices); } @@ -1994,19 +1996,44 @@ class XCBarAnalyser : public XCBase } // - // Check Bar Must Be Swing ... - result = IsSwing( - bar, - dir // - ); + XOHCL pBar; + result = bar.GetPreviousBar(pBar); if (!result) { + // + pBar.Clean(); return result; } // - bool isBullish = IsBullish(dir); - bool isBearish = IsBearish(dir); + bool isBullish = + // + bar.low < pBar.low && + bar.GetShadows() > bar.GetBody() && + bar.GetLowShadow() > bar.GetBody() && + bar.GetLowShadow() > bar.GetHighShadow() + // + ; + + // + bool isBearish = + // + bar.high > pBar.high && + bar.GetShadows() > bar.GetBody() && + bar.GetHighShadow() > bar.GetBody() && + bar.GetHighShadow() > bar.GetLowShadow() + // + ; + + // + result = isBullish || + isBearish; + if (!result) + { + // + pBar.Clean(); + return result; + } // // Check Force Type ... @@ -2021,6 +2048,16 @@ class XCBarAnalyser : public XCBase isBearish = isBearish && bar.IsBearish(); + + // + result = isBullish || + isBearish; + if (!result) + { + // + pBar.Clean(); + return result; + } } // @@ -2032,7 +2069,7 @@ class XCBarAnalyser : public XCBase HasFiboPressure( bar, X_DIRECTION_BULLISH, - X_FIBO_LEVEL_270 // + X_FIBO_LEVEL_236 // ); // @@ -2040,7 +2077,7 @@ class XCBarAnalyser : public XCBase HasFiboPressure( bar, X_DIRECTION_BEARISH, - X_FIBO_LEVEL_270 // + X_FIBO_LEVEL_236 // ); // @@ -2057,11 +2094,18 @@ class XCBarAnalyser : public XCBase // result = isBullish || isBearish; - if (!result) + if (result) { - dir = X_DIRECTION_NONE; + // + dir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; } + // + pBar.Clean(); + // return result; } @@ -2072,15 +2116,13 @@ class XCBarAnalyser : public XCBase * @param bar: XOHCL instance reference, Specified Bar to Check ... * @param dir: ENUM_X_DIRECTION member, Specified Doji Direction ... * @param loopback: int, Specified Loopback ... - * @param rangeExtendMultiplier: double, a Multiplier for Checking Price Range ... * * @return ( bool ) */ bool IsMomentum( XOHCL &bar, ENUM_X_DIRECTION &dir, - int loopback = 2, - double rangeExtendMultiplier = 1.5 // + int loopback = 2 // ) { // @@ -2089,7 +2131,6 @@ class XCBarAnalyser : public XCBase // dir = X_DIRECTION_NONE; loopback = NormalizeInt(loopback, 1); - rangeExtendMultiplier = NormalizeDouble(rangeExtendMultiplier, 1); // result = bar.IsValid(); diff --git a/Classes/x-saherelm.x-poi.class.mq5 b/Classes/x-saherelm.x-poi.class.mq5 index 0f376dc6..df1deeb2 100644 --- a/Classes/x-saherelm.x-poi.class.mq5 +++ b/Classes/x-saherelm.x-poi.class.mq5 @@ -207,30 +207,6 @@ class XCPOIDetector : public XCBaseAlert mMomentumLoopback = value; } - /** - * Get Momentum Detecting Range Extend Multiplier ... - * - * @return ( double ) - */ - double MomentumRangeExtendMultiplier() - { - return mMomentumRangeExtendMultiplier; - } - - /** - * Set Momentum Detecting Range Extend Multiplier ... - * - * @param value: double ... - */ - void MomentumRangeExtendMultiplier(double value) - { - // - value = NormalizeDouble(value, 1.5); - - // - mMomentumRangeExtendMultiplier = value; - } - /** * Get Rejection Detecting Force Bar Type State ... * @@ -685,7 +661,6 @@ class XCPOIDetector : public XCBaseAlert // MomentumLoopback(2); - MomentumRangeExtendMultiplier(1.5); // RejectionForceBarType(true); @@ -795,17 +770,17 @@ class XCPOIDetector : public XCBaseAlert // // Rejection ... - // DetectRejection( - // iBar, - // iEvent // - // ); + DetectRejection( + iBar, + iEvent // + ); // // Consolidation Zone ... - // DetectConsolidationZone( - // iBar, - // iEvent // - // ); + DetectConsolidationZone( + iBar, + iEvent // + ); // // Spike ... @@ -967,10 +942,10 @@ class XCPOIDetector : public XCBaseAlert // // Rejection ... - // has = DetectRejection( - // iBar, - // iEvent // - // ); + has = DetectRejection( + iBar, + iEvent // + ); if (has) { // @@ -982,10 +957,10 @@ class XCPOIDetector : public XCBaseAlert // // Consolidation Zone ... - // has = DetectConsolidationZone( - // iBar, - // iEvent // - // ); + has = DetectConsolidationZone( + iBar, + iEvent // + ); if (has) { // @@ -1202,7 +1177,7 @@ class XCPOIDetector : public XCBaseAlert // Copy( - mBullishRejections, + mBearishRejections, state.bearishRejections // ); @@ -1597,8 +1572,7 @@ class XCPOIDetector : public XCBaseAlert result = mBarAnalyser.IsMomentum( sBar, iDir, - mMomentumLoopback, - mMomentumRangeExtendMultiplier // + mMomentumLoopback // ); // @@ -1714,10 +1688,32 @@ class XCPOIDetector : public XCBaseAlert return result; } + // + XOHCL sBar; + if (bar.Index() == 0) + { + // + result = sBar.Init( + bar.symbol, + bar.period, + bar.Index() + 1 // + ); + if (!result) + { + // + sBar.Clean(); + return result; + } + } + else + { + sBar = bar; + } + // ENUM_X_DIRECTION iDir; result = mBarAnalyser.IsRejected( - bar, + sBar, iDir, mRejectionForceBarType, mRejectionForceFiboPressure // @@ -1728,6 +1724,8 @@ class XCPOIDetector : public XCBaseAlert HasDirection(iDir); if (!result) { + // + sBar.Clean(); return result; } @@ -1746,10 +1744,12 @@ class XCPOIDetector : public XCBaseAlert XCRejectionBar *rejection; rejection = new XCRejectionBar(); result = rejection.Init( - bar // + sBar // ); if (!result) { + // + sBar.Clean(); return result; } @@ -1761,6 +1761,8 @@ class XCPOIDetector : public XCBaseAlert result = !IsValidIndex(idx); if (!result) { + // + sBar.Clean(); return result; } @@ -1819,10 +1821,32 @@ class XCPOIDetector : public XCBaseAlert // state = X_POI_EVENT_NONE; + // + XOHCL sBar; + if (bar.Index() == 0) + { + // + result = sBar.Init( + bar.symbol, + bar.period, + bar.Index() + 1 // + ); + if (!result) + { + // + sBar.Clean(); + return result; + } + } + else + { + sBar = bar; + } + // XConsolidationZone cZone; result = mBarAnalyser.HasConsolidationZone( - bar, + sBar, cZone, mConsolidationZoneMinLoopback, mConsolidationZoneRangeInPoint, @@ -1832,6 +1856,7 @@ class XCPOIDetector : public XCBaseAlert if (!result) { // + sBar.Clean(); cZone.Clean(); // @@ -1854,6 +1879,7 @@ class XCPOIDetector : public XCBaseAlert if (!result) { // + sBar.Clean(); cZone.Clean(); // @@ -3069,11 +3095,10 @@ class XCPOIDetector : public XCBaseAlert // // Momentums ... - XCMomentumBar *mMomentums[]; // Holds Founded Momentum Bars ... - XCMomentumBar *mBullishMomentums[]; // Holds Founded Bullish Momentum Bars ... - XCMomentumBar *mBearishMomentums[]; // Holds Founded Bearish Momentum Bars ... - int mMomentumLoopback; // Momentum Detecting Loopback ... - double mMomentumRangeExtendMultiplier; // Momentum Detecting Range Extend Multiplier ... + XCMomentumBar *mMomentums[]; // Holds Founded Momentum Bars ... + XCMomentumBar *mBullishMomentums[]; // Holds Founded Bullish Momentum Bars ... + XCMomentumBar *mBearishMomentums[]; // Holds Founded Bearish Momentum Bars ... + int mMomentumLoopback; // Momentum Detecting Loopback ... // // Rejections ... diff --git a/Experts/x-saherelm.xpoi.test.ea.mq5 b/Experts/x-saherelm.xpoi.test.ea.mq5 index e0c44ca2..d8dc88f3 100644 --- a/Experts/x-saherelm.xpoi.test.ea.mq5 +++ b/Experts/x-saherelm.xpoi.test.ea.mq5 @@ -343,33 +343,33 @@ void DetectPOIState() // // Bullish ... showBullishPOIs && true, // SwingLows - showBullishPOIs && true, // DemandZones - showBullishPOIs && true, // SupportZones - showBullishPOIs && true, // BullishSharps - showBullishPOIs && true, // BullishSpikes - showBullishPOIs && false, // BullishMomentums - showBullishPOIs && true, // BullishRejections - showBullishPOIs && true, // BullishOrderBlocks - showBullishPOIs && true, // BullishFairValueGaps - showBullishPOIs && true, // BullishConsolidationZones + showBullishPOIs && true, // DemandZones + showBullishPOIs && true, // SupportZones + showBullishPOIs && true, // BullishSharps + showBullishPOIs && true, // BullishSpikes + showBullishPOIs && true, // BullishMomentums + showBullishPOIs && true, // BullishRejections + showBullishPOIs && true, // BullishOrderBlocks + showBullishPOIs && true, // BullishFairValueGaps + showBullishPOIs && true, // BullishConsolidationZones // // Bearish ... showBearishPOIs && true, // SwingHighs - showBearishPOIs && true, // SupplyZones - showBearishPOIs && true, // BearishSharps - showBearishPOIs && true, // BearishSpikes - showBearishPOIs && true, // ResistanceZones - showBearishPOIs && false, // BearishMomentums - showBearishPOIs && true, // BearishRejections - showBearishPOIs && true, // BearishOrderBlocks - showBearishPOIs && true, // BearishFairValueGaps - showBearishPOIs && true // BearishConsolidationZones + showBearishPOIs && true, // SupplyZones + showBearishPOIs && true, // BearishSharps + showBearishPOIs && true, // BearishSpikes + showBearishPOIs && true, // ResistanceZones + showBearishPOIs && true, // BearishMomentums + showBearishPOIs && true, // BearishRejections + showBearishPOIs && true, // BearishOrderBlocks + showBearishPOIs && true, // BearishFairValueGaps + showBearishPOIs && true // BearishConsolidationZones ); // - if (poiEventNotifier.hasNewMomentum) + if (poiEventNotifier.hasNewConsolidationZone) { - Print("Momentum ..."); + Print("Consolidation ..."); } //