From af9c3983385a43ce74343c78316894844f51aab5 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Wed, 26 Feb 2025 22:34:40 +0330 Subject: [PATCH] add support of Consolidation Zone ibside XPOIDetector and XPOIState ... --- Classes/x-saherelm.x-bar.analyser.class.mq5 | 185 ++ Classes/x-saherelm.x-cobject.class.mq5 | 4 +- Classes/x-saherelm.x-poi.class.mq5 | 376 +++- Classes/x-saherelm.x-poi.drawer.class.mq5 | 64 +- Documents/BKP/1.mq5 | 26 +- Helpers/x-saherelm.x121.helper.mq5 | 1 + Libraries/x-saherelm.common.lib.mq5 | 130 +- Libraries/x-saherelm.x-poi.extensions.lib.mq5 | 1634 +++++++++-------- Libraries/x-saherelm.x-poi.lib.mq5 | 436 +---- Libraries/x-saherelm.x-poi.state.lib.mq5 | 171 +- .../x-121.smc.market.cycle.helper.class.mq5 | 269 +-- X121SMCEA/Libraries/x-121.smc.guard.lib.mq5 | 446 ++--- .../Signals/x-121.smc.xwz.signal.class.mq5 | 228 +-- .../Strategy/x-121.smc.strategy.class.mq5 | 9 +- 14 files changed, 1993 insertions(+), 1986 deletions(-) diff --git a/Classes/x-saherelm.x-bar.analyser.class.mq5 b/Classes/x-saherelm.x-bar.analyser.class.mq5 index 3c7eb165..dbe53f3a 100644 --- a/Classes/x-saherelm.x-bar.analyser.class.mq5 +++ b/Classes/x-saherelm.x-bar.analyser.class.mq5 @@ -447,6 +447,191 @@ class XCBarAnalyser : public XCBase return result; } + bool HasConsolidationZone( + XOHCL &bar, + XConsolidationZone &zone, + int minLoopback = 3, + double range = 50, + ENUM_APPLIED_PRICE upperAppliedTo = PRICE_HIGH, + ENUM_APPLIED_PRICE lowerAppliedTo = PRICE_LOW // + ) + { + // + bool result = false; + + // + zone.Clean(); + + // + result = bar.IsValid() && + minLoopback > 0 && + range > 0; + if (!result) + { + return result; + } + + // + double points = GetPoints(bar.symbol); + int index = bar.Index() + 1; + int length = minLoopback; + + // + double upperPrice[]; + int upperPriceCount = FillPrice( + upperPrice, + upperAppliedTo, + bar.symbol, + bar.period, + index, + length // + ); + + // + double lowerPrice[]; + int lowerPriceCount = FillPrice( + lowerPrice, + lowerAppliedTo, + bar.symbol, + bar.period, + index, + length // + ); + + // + result = upperPriceCount == lowerPriceCount && + lowerPriceCount == length; + if (!result) + { + // + Clean(upperPrice); + Clean(lowerPrice); + + // + return result; + } + + // + double upper = upperPrice[ArrayMaximum(upperPrice)]; + double lower = lowerPrice[ArrayMinimum(lowerPrice)]; + + // + bool isBullishBreake = + bar.low > lower && + bar.high > upper && + bar.GetUp() > upper; + bool isBearishBreake = + bar.high < upper && + bar.low < lower && + bar.GetDown() < lower; + result = isBullishBreake || + isBearishBreake; + if (!result) + { + // + Clean(upperPrice); + Clean(lowerPrice); + + // + return result; + } + + // + double delta = upper - lower; + result = delta <= range * points; + if (!result) + { + // + Clean(upperPrice); + Clean(lowerPrice); + + // + return result; + } + + // + while (delta <= range * points) + { + // + length++; + + // + upperPriceCount = FillPrice( + upperPrice, + upperAppliedTo, + bar.symbol, + bar.period, + index, + length // + ); + + // + lowerPriceCount = FillPrice( + lowerPrice, + lowerAppliedTo, + bar.symbol, + bar.period, + index, + length // + ); + + // + bool isValid = upperPriceCount == lowerPriceCount && + lowerPriceCount == length; + if (!isValid) + { + break; + } + + // + double iUpper = upperPrice[ArrayMaximum(upperPrice)]; + double iLower = lowerPrice[ArrayMinimum(lowerPrice)]; + + // + delta = iUpper - iLower; + if (delta <= range * points) + { + // + upper = iUpper; + lower = iLower; + } + } + + // + Clean(upperPrice); + Clean(lowerPrice); + + // + // Filling Zone ... + zone.upper = upper; + zone.lower = lower; + zone.symbol = bar.symbol; + zone.period = bar.period; + zone.to = iTime( + bar.symbol, + bar.period, + bar.Index() + 1 // + ); + zone.from = iTime( + bar.symbol, + bar.period, + bar.Index() + length // + ); + zone.dir = isBullishBreake + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + result = zone.IsValid(); + if (!result) + { + zone.Clean(); + } + + // + return result; + } + /** * Check Bar Has Bullish Trend or not ... * diff --git a/Classes/x-saherelm.x-cobject.class.mq5 b/Classes/x-saherelm.x-cobject.class.mq5 index 1ab0f7d0..2666968f 100644 --- a/Classes/x-saherelm.x-cobject.class.mq5 +++ b/Classes/x-saherelm.x-cobject.class.mq5 @@ -1594,9 +1594,9 @@ class XCConsolidationZoneObject : public XCBaseObject chart_id, name, window, - zone.From(), + zone.from, zone.upper, - TimeCurrent(), + zone.to, zone.lower // ); diff --git a/Classes/x-saherelm.x-poi.class.mq5 b/Classes/x-saherelm.x-poi.class.mq5 index 429b7bd7..282255b2 100644 --- a/Classes/x-saherelm.x-poi.class.mq5 +++ b/Classes/x-saherelm.x-poi.class.mq5 @@ -405,6 +405,100 @@ class XCPOIDetector : public XCBaseAlert mFairValueGapSameBars = value; } + /** + * Get Minimum Length of Cnsolidation Zone ... + * + * @return ( int ) + */ + int ConsolidationZoneMinLoopback() + { + return mConsolidationZoneMinLoopback; + } + + /** + * Set Minimum Length of Cnsolidation Zone ... + * + * @param value: int ... + */ + void ConsolidationZoneMinLoopback(int value) + { + // + if (value < 1) + { + value = 1; + } + + // + mConsolidationZoneMinLoopback = value; + } + + /** + * Get Consolidation Zone Range in Point ... + * + * @return ( double ) + */ + double ConsolidationZoneRangeInPoint() + { + return mConsolidationZoneRangeInPoint; + } + + /** + * Set Consolidation Zone Range in Point ... + * + * @param value: double + */ + void ConsolidationZoneRangeInPoint(double value) + { + // + if (value < 50) + { + value = 50; + } + + // + mConsolidationZoneRangeInPoint = value; + } + + /** + * Get Consolidation Zone Upper Applied To ... + * + * @return ( ENUM_APPLIED_PRICE ) + */ + ENUM_APPLIED_PRICE ConsolidationZonesLowerAppliedTo() + { + return mConsolidationZonesLowerAppliedTo; + } + + /** + * Set Consolidation Zone Upper Applied To ... + * + * @param value: ENUM_APPLIED_PRICE + */ + void ConsolidationZonesLowerAppliedTo(ENUM_APPLIED_PRICE value = PRICE_LOW) + { + mConsolidationZonesLowerAppliedTo = value; + } + + /** + * Get Consolidation Zone Lower Applied To ... + * + * @return ( ENUM_APPLIED_PRICE ) + */ + ENUM_APPLIED_PRICE ConsolidationZonesUpperAppliedTo() + { + return mConsolidationZonesUpperAppliedTo; + } + + /** + * Set Consolidation Zone Lower Applied To ... + * + * @param value: ENUM_APPLIED_PRICE + */ + void ConsolidationZonesUpperAppliedTo(ENUM_APPLIED_PRICE value = PRICE_HIGH) + { + mConsolidationZonesUpperAppliedTo = value; + } + // // Actions ... @@ -426,6 +520,10 @@ class XCPOIDetector : public XCBaseAlert SupResRangeAsStart(true); RejectionShadowPercent(70); MaxAllowedLoopbackForInit(578); + ConsolidationZoneMinLoopback(5); + ConsolidationZoneRangeInPoint(50); + ConsolidationZonesLowerAppliedTo(PRICE_LOW); + ConsolidationZonesUpperAppliedTo(PRICE_HIGH); } /** @@ -560,6 +658,14 @@ class XCPOIDetector : public XCBaseAlert false // ); + // + // Consolidation Zone ... + DetectConsolidationZone( + iBar, + iEvent, + false // + ); + // canContinue = has && @@ -1027,6 +1133,20 @@ class XCPOIDetector : public XCBaseAlert } } + // + has = DetectConsolidationZone( + iBar, + iEvent // + ); + if (has) + { + // + Add( + iEvent, + events // + ); + } + // iBar.Clean(); mLock = false; @@ -1169,6 +1289,24 @@ class XCPOIDetector : public XCBaseAlert state.bearishFairValueGaps // ); + // + Copy( + mConsolidationZones, + state.consolidationZones // + ); + + // + Copy( + mBullishConsolidationZones, + state.bullishConsolidationZones // + ); + + // + Copy( + mBearishConsolidationZones, + state.bearishConsolidationZones // + ); + // } @@ -1193,51 +1331,58 @@ class XCPOIDetector : public XCBaseAlert void CleanCollections() { // - Clean(mEventListeners); Clean(mSwings); Clean(mSwingLows); Clean(mSwingHighs); - Clean(mMomentumBars); - Clean(mBullishMomentumBars); - Clean(mBearishMomentumBars); - Clean(mRejectionBars); - Clean(mBullishRejectionBars); - Clean(mBearishRejectionBars); - Clean(mSupportZones); Clean(mDemandZones); Clean(mSupplyZones); - Clean(mResistanceZones); - Clean(mFairValueGaps); - Clean(mBullishFairValueGaps); - Clean(mBearishFairValueGaps); Clean(mOrderBlocks); + Clean(mMomentumBars); + Clean(mSupportZones); + Clean(mRejectionBars); + Clean(mFairValueGaps); + Clean(mEventListeners); + Clean(mResistanceZones); Clean(mBullishOrderBlocks); Clean(mBearishOrderBlocks); + Clean(mConsolidationZones); + Clean(mBullishMomentumBars); + Clean(mBearishMomentumBars); + Clean(mBullishRejectionBars); + Clean(mBearishRejectionBars); + Clean(mBullishFairValueGaps); + Clean(mBearishFairValueGaps); + Clean(mBullishConsolidationZones); + Clean(mBearishConsolidationZones); } // - void ReverseCollections() { + void ReverseCollections() + { // - ArrayReverse(mEventListeners); ArrayReverse(mSwings); ArrayReverse(mSwingLows); ArrayReverse(mSwingHighs); - ArrayReverse(mMomentumBars); - ArrayReverse(mBullishMomentumBars); - ArrayReverse(mBearishMomentumBars); - ArrayReverse(mRejectionBars); - ArrayReverse(mBullishRejectionBars); - ArrayReverse(mBearishRejectionBars); - ArrayReverse(mSupportZones); ArrayReverse(mDemandZones); ArrayReverse(mSupplyZones); - ArrayReverse(mResistanceZones); - ArrayReverse(mFairValueGaps); - ArrayReverse(mBullishFairValueGaps); - ArrayReverse(mBearishFairValueGaps); ArrayReverse(mOrderBlocks); + ArrayReverse(mMomentumBars); + ArrayReverse(mSupportZones); + ArrayReverse(mRejectionBars); + ArrayReverse(mFairValueGaps); + ArrayReverse(mEventListeners); + ArrayReverse(mResistanceZones); ArrayReverse(mBullishOrderBlocks); ArrayReverse(mBearishOrderBlocks); + ArrayReverse(mConsolidationZones); + ArrayReverse(mBullishMomentumBars); + ArrayReverse(mBearishMomentumBars); + ArrayReverse(mBullishRejectionBars); + ArrayReverse(mBearishRejectionBars); + ArrayReverse(mBullishFairValueGaps); + ArrayReverse(mBearishFairValueGaps); + ArrayReverse(mBullishConsolidationZones); + ArrayReverse(mBearishConsolidationZones); } // @@ -1374,6 +1519,24 @@ class XCPOIDetector : public XCBaseAlert maxAllowed // ); + // + CleanupArray( + mConsolidationZones, + maxAllowed // + ); + + // + CleanupArray( + mBullishConsolidationZones, + maxAllowed // + ); + + // + CleanupArray( + mBearishConsolidationZones, + maxAllowed // + ); + // } @@ -2928,6 +3091,160 @@ class XCPOIDetector : public XCBaseAlert return result; } + /** + * Detect Consolidation Zones ... + * + * @param bar: XOHCL instance ... + * @param reversal: boolean reversal add to collection ... + * + * @return ( bool ) + */ + bool DetectConsolidationZone( + XOHCL &bar, + ENUM_XPOI_EVENTS &state, + bool reversal = false // + ) + { + // + bool result = false; + + // + state = X_POI_EVENT_NONE; + + // + XConsolidationZone cZone; + result = mBarAnalyser.HasConsolidationZone( + bar, + cZone, + mConsolidationZoneMinLoopback, + mConsolidationZoneRangeInPoint, + mConsolidationZonesUpperAppliedTo, + mConsolidationZonesLowerAppliedTo // + ); + if (!result) + { + // + cZone.Clean(); + + // + return result; + } + + // + // Add ... + + // + bool isBullish = IsBullish(cZone.dir); + bool isBearish = IsBearish(cZone.dir); + + // + int idx = FindIndex( + cZone, + mConsolidationZones // + ); + result = !IsValidIndex(idx); + if (!result) + { + // + cZone.Clean(); + + // + return result; + } + + // + if (reversal) + { + // + ArrayReverse(mConsolidationZones); + + // + AddRef( + cZone, + mConsolidationZones // + ); + + // + ArrayReverse(mConsolidationZones); + } + else + { + // + AddRef( + cZone, + mConsolidationZones // + ); + } + + // + if (isBullish) + { + // + // Add Swings ... + if (reversal) + { + // + ArrayReverse(mBullishConsolidationZones); + + // + AddRef( + cZone, + mBullishConsolidationZones // + ); + + // + ArrayReverse(mBullishConsolidationZones); + } + else + { + // + AddRef( + cZone, + mBullishConsolidationZones // + ); + } + } + else if (isBearish) + { + // + // Add Swings ... + if (reversal) + { + // + ArrayReverse(mBearishConsolidationZones); + + // + AddRef( + cZone, + mBearishConsolidationZones // + ); + + // + ArrayReverse(mBearishConsolidationZones); + } + else + { + // + AddRef( + cZone, + mBearishConsolidationZones // + ); + } + } + + // + state = + IsBullish(cZone.dir) + ? X_BULLISH_CONSOLIDATION_ZONE_DETECTED + : X_BEARISH_CONSOLIDATION_ZONE_DETECTED; + + // + cZone.Clean(); + + // + return result; + } + // private: // @@ -2991,6 +3308,15 @@ class XCPOIDetector : public XCBaseAlert XCOrderBlock *mBearishOrderBlocks[]; // Holds Founded Bearish OrderBlocks ... int mOrderBlockSameBars; // OrderBlock Detection Same Bars ... + // + int mConsolidationZoneMinLoopback; // Minimum Length of Cnsolidation Zone ... + double mConsolidationZoneRangeInPoint; // Consolidation Zone Range in Point ... + XConsolidationZone mConsolidationZones[]; // Holds Founded Consolidation Zones ... + XConsolidationZone mBullishConsolidationZones[]; // Holds Founded Bullish Consolidation Zones ... + XConsolidationZone mBearishConsolidationZones[]; // Holds Founded Bearish Consolidation Zones ... + ENUM_APPLIED_PRICE mConsolidationZonesLowerAppliedTo; // Consolidation Zone Upper Applied To ... + ENUM_APPLIED_PRICE mConsolidationZonesUpperAppliedTo; // Consolidation Zone Lower Applied To ... + // }; diff --git a/Classes/x-saherelm.x-poi.drawer.class.mq5 b/Classes/x-saherelm.x-poi.drawer.class.mq5 index dad0249b..a3eb244d 100644 --- a/Classes/x-saherelm.x-poi.drawer.class.mq5 +++ b/Classes/x-saherelm.x-poi.drawer.class.mq5 @@ -2964,7 +2964,7 @@ class XCPOIDrawer : public XCBase int window = SubWindowIdentification(); // - color czColor = IsBullish(zone.breakDir) + color czColor = IsBullish(zone.dir) ? BarBullishColor() : BarBearishColor(); @@ -3460,7 +3460,9 @@ class XCPOIDrawer : public XCBase bool ignoreBullishRejectionBars = false, bool ignoreBearishRejectionBars = false, bool ignoreBullishMomentumBars = false, - bool ignoreBearishMomentumBars = false // + bool ignoreBearishMomentumBars = false, + bool ignoreBullishConsolidationZones = false, + bool ignoreBearishConsolidationZones = false // ) { // @@ -3924,6 +3926,64 @@ class XCPOIDrawer : public XCBase } } + // + // Bullish Consolidation Zones ... + if (!ignoreBullishConsolidationZones) + { + // + int count = state.CountBullishConsolidationZones(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCConsolidationZoneObject *iObj; + bool isCreated = CreateConsolidationZone( + state.bullishConsolidationZones[i], + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + drawnObjects // + ); + } + } + } + } + + // + // Bearish Consolidation Zones ... + if (!ignoreBearishConsolidationZones) + { + // + int count = state.CountBearishConsolidationZones(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCConsolidationZoneObject *iObj; + bool isCreated = CreateConsolidationZone( + state.bearishConsolidationZones[i], + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + drawnObjects // + ); + } + } + } + } + // result = ArraySize(drawnObjects); diff --git a/Documents/BKP/1.mq5 b/Documents/BKP/1.mq5 index 90ea9d4b..18a50421 100644 --- a/Documents/BKP/1.mq5 +++ b/Documents/BKP/1.mq5 @@ -212,4 +212,28 @@ // } - \ No newline at end of file + // + XCBaseObject *stateObjects[]; + int stateObjectsCount = drawer.DrawState( + decisionState, + stateObjects, + false, // + true, // ignoreSwingHighs + true, // ignoreSwingLows + true, // ignoreSupportZones + true, // ignoreResistanceZones + true, // ignoreSupplyZones + true, // ignoreDemandZones + true, // ignoreBullishOrderBlocks + true, // ignoreBearishOrderBlocks + true, // ignoreBullishFairValueGaps + true, // ignoreBearishFairValueGaps + true, // ignoreBullishRejectionBars + true, // ignoreBearishRejectionBars + true, // ignoreBullishMomentumBars + true, // ignoreBearishMomentumBars + false, // ignoreBullishConsolidationZones + false // ignoreBearishConsolidationZones + ); + + \ No newline at end of file diff --git a/Helpers/x-saherelm.x121.helper.mq5 b/Helpers/x-saherelm.x121.helper.mq5 index 8862d4eb..8f566976 100644 --- a/Helpers/x-saherelm.x121.helper.mq5 +++ b/Helpers/x-saherelm.x121.helper.mq5 @@ -90,6 +90,7 @@ struct X121Inputs xstrInputs.Default(); xcheInputs.Default(); xdonInputs.Default(); + x3maInputs.Default(); xvwapInputs.Default(); xtrendInputs.Default(); } diff --git a/Libraries/x-saherelm.common.lib.mq5 b/Libraries/x-saherelm.common.lib.mq5 index 343da303..1b68dabc 100644 --- a/Libraries/x-saherelm.common.lib.mq5 +++ b/Libraries/x-saherelm.common.lib.mq5 @@ -3754,6 +3754,132 @@ int ExtractSwings( return result; } +// +// Consolidation Zone ... +struct XConsolidationZone +{ + // + // Props ... + + // + string symbol; // Symbol ... + ENUM_TIMEFRAMES period; // Period ... + + // + double upper; // Upper ... + double lower; // Lower ... + + // + datetime from; // Start Date + datetime to; // Breake Date + + // + ENUM_X_DIRECTION dir; // Break Direction ... + + // + // Constructor ... + XConsolidationZone() + { + Clean(); + } + + // + // Tools ... + + /** + * Cleanup ... + */ + void Clean() + { + // + upper = 0; + lower = 0; + + // + to = NULL; + from = NULL; + symbol = NULL; + period = NULL; + dir = X_DIRECTION_NONE; + + // + ZeroMemory(this); + } + + /** + * Validate ... + * + * @return ( bool ) + */ + bool IsValid() + { + // + bool result = false; + + // + result = + // + upper > 0 && + lower > 0 && + IsValid(to) && + IsValid(from) && + IsValid(symbol) && + IsValid(period) && + HasDirection(dir) + // + ; + + // + return result; + } + + bool IsSameAs( + XConsolidationZone &item // + ) + { + // + bool result = false; + + // + result = IsValid() && + item.IsValid() && + dir == item.dir && + from == item.from && + upper == item.upper && + lower == item.lower && + symbol == item.symbol && + period == item.period; + + // + return result; + } + + /** + * Retrieve Unique Identifier ... + * + * @return ( string ) + */ + string GetTag() + { + // + string result = + // + "XCZONE" + "_" + + ToString(dir) + "_" + + symbol + "_" + + ToString(period) + "_" + + ToString(upper) + "_" + + ToString(lower) + // + ; + + // + return result; + } + + // +}; + // // Functions ... @@ -5255,9 +5381,9 @@ int FillPrice( } // - if (_mLoopback < 7) + if (_mLoopback < 1) { - _mLoopback = 7; + _mLoopback = 1; } // diff --git a/Libraries/x-saherelm.x-poi.extensions.lib.mq5 b/Libraries/x-saherelm.x-poi.extensions.lib.mq5 index c91b5f6e..57e91262 100644 --- a/Libraries/x-saherelm.x-poi.extensions.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.extensions.lib.mq5 @@ -1539,14 +1539,16 @@ bool ToBox( } // + box.to = item.to; + box.dir = item.dir; + box.from = item.from; box.upper = item.upper; box.lower = item.lower; - box.dir = item.breakDir; - box.from = item.From(); box.symbol = item.symbol; box.period = item.period; - box.to = item.breakerBar.time; - box.type = "X_CONSOLIDATION_ZONE"; + box.type = IsBullish(item.dir) + ? ToString(X_BULLISH_CONSOLIDATION_ZONE) + : ToString(X_BEARISH_CONSOLIDATION_ZONE); // result = box.IsValid(); @@ -2619,815 +2621,815 @@ int FilterZones( // // -/** - * Check Trading Conditions based on Specified Box ... - * - * @param box: XBoxZone instance Reference, specified Box for Checking Conditions ... - * @param appliedBox: XBoxZone instance Reference, hold's Selected Box inside Parent which trading conditions happens on it ... - * @param swingBar: XOHCL instance Reference, holds Swing Bar if Exists ... - * @param breakerBar: XOHCL instance Reference, holds Breaker Bar if Exists ... - * @param rejectionBar: XOHCL instance Reference, holds Rejection Bar if Exists ... - * @param momentumBar: XOHCL instance Reference, holds Momentum Bar if Exists ... - * @param state: XPOIState instance Reference, provides requirement zone's for check Conditions ... - * @param barIndex: int, Specified Bar Index ... - * @param forPeriod: ENUM_TIMEFRAMES member, Specified Conditions Checking Period ... - * - * @return ( bool ) - */ -bool CheckBoxForTradeConditions( - XBoxZone &box, - XBoxZone &appliedBox, - XOHCL &swingBar, - XOHCL &breakerBar, - XOHCL &rejectionBar, - XOHCL &momentumBar, - XPOIState &state, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // -) -{ - // - bool result = false; - - // - swingBar.Clean(); - appliedBox.Clean(); - breakerBar.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - result = box.IsValid() && - state.IsValid() && - state.HasChild(); - if (!result) - { - return result; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = box.period; - } - - // - string symbol = box.symbol; - datetime cTime = iTime( - symbol, - forPeriod, - barIndex // - ); - - // - ENUM_X_DIRECTION forDir = box.dir; - result = HasDirection(forDir); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - int supportsCount = 0; - bool hasSupports = false; - XCSupportZone *supports[]; - - // - int resistancesCount = 0; - bool hasResistances = false; - XCResistanceZone *resistances[]; - - // - XBoxZone supResBoxes[]; - int supresBoxesCount = 0; - bool hasSupResBoxes = false; - - // - int count = 0; - bool has = false; - - // - has = state.HasSupportZones(); - if (has) - { - // - count = state.CountSupportZones(); - for (int i = 0; i < count; i++) - { - // - XCSupportZone *iZone = state.supportZones[i]; - - // - iZone.To(cTime); - - // - XBoxZone iBox; - bool hasBox = ToBox( - iBox, - iZone // - ); - if (!hasBox) - { - // - iBox.Clean(); - continue; - } - - // - // Check From ... - bool isInside = IsBoxInside( - iBox, - box // - ); - if (!isInside) - { - // - iBox.Clean(); - continue; - } - - // - Add( - iZone, - supports // - ); - - // - AddRef( - iBox, - supResBoxes // - ); - - // - iBox.Clean(); - } - - // - supportsCount = ArraySize(supports); - hasSupports = IsValidSize(supportsCount); - - // - supresBoxesCount = ArraySize(supResBoxes); - hasSupResBoxes = IsValidSize(supresBoxesCount); - } - - // - has = state.HasResistanceZones(); - if (has) - { - // - count = state.CountResistanceZones(); - for (int i = 0; i < count; i++) - { - // - XCResistanceZone *iZone = state.resistanceZones[i]; - - // - iZone.To(cTime); - - // - XBoxZone iBox; - bool hasBox = ToBox( - iBox, - iZone // - ); - if (!hasBox) - { - // - iBox.Clean(); - continue; - } - - // - // Check From ... - bool isInside = IsBoxInside( - iBox, - box // - ); - if (!isInside) - { - // - iBox.Clean(); - continue; - } - - // - Add( - iZone, - resistances // - ); - - // - AddRef( - iBox, - supResBoxes // - ); - - // - iBox.Clean(); - } - - // - resistancesCount = ArraySize(resistances); - hasResistances = IsValidSize(resistancesCount); - - // - supresBoxesCount = ArraySize(supResBoxes); - hasSupResBoxes = IsValidSize(supresBoxesCount); - } - - // - result = hasSupResBoxes; - if (!result) - { - // - Clean(supports); - Clean(resistances); - Clean(supResBoxes); - - // - return result; - } - - // - // Detect Bars ... - - // - XOHCL zBar; - result = zBar.Init( - symbol, - forPeriod, - barIndex // - ); - if (!result) - { - // - zBar.Clean(); - Clean(supports); - Clean(resistances); - Clean(supResBoxes); - - // - return result; - } - - // - XOHCL cBar; - result = zBar.GetPreviousBar(cBar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - Clean(supports); - Clean(resistances); - Clean(supResBoxes); - - // - return result; - } - - // - XOHCL pBar; - result = cBar.GetPreviousBar(pBar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - Clean(supports); - Clean(resistances); - Clean(supResBoxes); - - // - return result; - } - - // - XOHCL ppBar; - result = pBar.GetPreviousBar(ppBar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - ppBar.Clean(); - Clean(supports); - Clean(resistances); - Clean(supResBoxes); - - // - return result; - } - // - // Check Conditions ... - - // - // Detect Start Senario ... - - // - double fiboPressureLevel = GetFiboLevelValue(X_FIBO_LEVEL_382); - - // - double fiboUpDown = GetFibonacciLevel( - pBar.high, - pBar.low, - X_FIBO_LEVEL_382, - X_DIRECTION_BEARISH // - ); - double fiboDownUp = GetFibonacciLevel( - pBar.high, - pBar.low, - X_FIBO_LEVEL_382, - X_DIRECTION_BULLISH // - ); - - // - bool hasFiboToUpPressure = - fiboDownUp > 0 && - fiboDownUp <= pBar.GetDown(); - bool hasFiboToDownPressure = - fiboUpDown > 0 && - fiboUpDown >= pBar.GetUp(); - - // - int selectedBoxIDX = -1; - for (int j = 0; j < supresBoxesCount; j++) - { - // - double appliedPrice = - isBullish - ? supResBoxes[j].lower - : supResBoxes[j].upper; - - // - // Check Swing Low ... - bool isSwingLow = - // - pBar.low < ppBar.low && - pBar.low < cBar.low && - zBar.open > pBar.low && - // - appliedPrice > pBar.low && - appliedPrice < pBar.GetDown() - // - ; - bool isPressuredSwingLow = - isSwingLow && - hasFiboToUpPressure; - bool isPressuredStrongSwingLow = - pBar.IsBullish() && - isPressuredSwingLow; - - // - bool isSwingHigh = - // - pBar.high > ppBar.high && - pBar.high > cBar.high && - zBar.open < pBar.high && - // - appliedPrice < pBar.high && - appliedPrice > pBar.GetUp() - // - ; - bool isPressuredSwingHigh = - isSwingHigh && - hasFiboToDownPressure; - bool isPressuredStrongSwingHigh = - pBar.IsBearish() && - isPressuredSwingHigh; - - // - bool hasValidSwing = - isBullish - ? isSwingLow - : isSwingHigh; - bool hasValidPressuredSwing = - isBullish - ? isPressuredSwingLow - : isPressuredSwingHigh; - bool hasValidPressuredStrongSwing = - isBullish - ? isPressuredStrongSwingLow - : isPressuredStrongSwingHigh; - if (hasValidSwing) - { - swingBar = pBar; - } - if (hasValidPressuredSwing) - { - swingBar = pBar; - } - if (hasValidPressuredStrongSwing) - { - swingBar = pBar; - } - - // - bool isCBarBreaked = IsBarBreak( - appliedPrice, - forDir, - cBar // - ); - if (isCBarBreaked) - { - breakerBar = cBar; - } - bool isPBarBreaked = IsBarBreak( - appliedPrice, - forDir, - pBar // - ); - if (!isCBarBreaked && isPBarBreaked) - { - breakerBar = pBar; - } - else - { - isPBarBreaked = false; - } - bool isPPBarBreaked = IsBarBreak( - appliedPrice, - forDir, - ppBar // - ); - if (!isCBarBreaked && - !isPBarBreaked && - isPPBarBreaked) - { - breakerBar = ppBar; - } - else - { - isPPBarBreaked = false; - } - bool isBoxBreaked = isCBarBreaked || - isPBarBreaked || - isPPBarBreaked; - - // - bool isCBarRejected = IsBarReject( - appliedPrice, - forDir, - cBar // - ); - if (isCBarRejected) - { - rejectionBar = cBar; - } - bool isPBarRejected = IsBarReject( - appliedPrice, - forDir, - pBar // - ); - if (!isCBarRejected && isPBarRejected) - { - rejectionBar = pBar; - } - else - { - isPBarRejected = false; - } - bool isPPBarRejected = IsBarReject( - appliedPrice, - forDir, - ppBar // - ); - if (!isCBarRejected && - !isPBarRejected && - isPPBarRejected) - { - rejectionBar = ppBar; - } - else - { - isPPBarRejected = false; - } - bool isBoxRejected = isCBarRejected || - isPBarRejected || - isPPBarRejected; - - // - bool hasRejectionBar = false; - if (isBullish) - { - // - count = state.CountBullishRejectionBars(); - for (int i = 0; i < count; i++) - { - // - XCRejectionBar *iZone = state.bullishRejectionBars[i]; - - // - XOHCL iBar; - bool isFilled = iZone.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasRejectionBar = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasRejectionBar) - { - // - if (!rejectionBar.IsValid()) - { - rejectionBar = iBar; - } - - // - break; - } - } - } - else - { - // - count = state.CountBearishRejectionBars(); - for (int i = 0; i < count; i++) - { - // - XCRejectionBar *iZone = state.bearishRejectionBars[i]; - - // - XOHCL iBar; - bool isFilled = iZone.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasRejectionBar = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasRejectionBar) - { - // - if (!rejectionBar.IsValid()) - { - rejectionBar = iBar; - } - - // - break; - } - } - } - - // - bool hasMomentumBar = false; - if (isBullish) - { - // - count = state.CountBullishMomentumBars(); - for (int i = 0; i < count; i++) - { - // - XCMomentumBar *iZone = state.bullishMomentumBars[i]; - - // - XOHCL iBar; - bool isFilled = iZone.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasMomentumBar = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasMomentumBar) - { - // - if (!momentumBar.IsValid()) - { - momentumBar = iBar; - } - - // - break; - } - } - } - else - { - // - count = state.CountBearishMomentumBars(); - for (int i = 0; i < count; i++) - { - // - XCMomentumBar *iZone = state.bearishMomentumBars[i]; - - // - XOHCL iBar; - bool isFilled = iZone.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasMomentumBar = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasMomentumBar) - { - // - if (!momentumBar.IsValid()) - { - momentumBar = iBar; - } - - // - break; - } - } - } - - // - bool hasSwing = false; - if (isBullish) - { - // - count = state.CountSwingLows(); - for (int i = 0; i < count; i++) - { - // - XCSwing *iSwing = state.swingLows[i]; - - // - XOHCL iBar; - bool isFilled = iSwing.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasSwing = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasSwing) - { - // - if (!swingBar.IsValid()) - { - swingBar = iBar; - } - - // - break; - } - } - } - else - { - // - count = state.CountSwingHighs(); - for (int i = 0; i < count; i++) - { - // - XCSwing *iSwing = state.swingHighs[i]; - - // - XOHCL iBar; - bool isFilled = iSwing.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasSwing = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasSwing) - { - // - if (!swingBar.IsValid()) - { - swingBar = iBar; - } - - // - break; - } - } - } - - // - bool hasRequiredValidations = - // - (hasRejectionBar || - hasMomentumBar) - // - || - // - (hasRejectionBar || - hasSwing) - // - || - // - (hasMomentumBar || - hasSwing) - // - ; - - // - result = - // - (isBoxBreaked && - (hasRequiredValidations || - hasValidPressuredSwing)) - // - || - // - (isBoxRejected && - (hasRequiredValidations || - hasValidPressuredSwing)) - // - ; - if (result) - { - // - selectedBoxIDX = j; - break; - } - } - - // - result = - result && - (isBullish - ? zBar.open > box.upper - : zBar.open < box.lower) && - IsValidIndex(selectedBoxIDX); - if (result) - { - appliedBox = supResBoxes[selectedBoxIDX]; - } - - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - ppBar.Clean(); - Clean(supports); - Clean(resistances); - Clean(supResBoxes); - - // - return result; -} +// /** +// * Check Trading Conditions based on Specified Box ... +// * +// * @param box: XBoxZone instance Reference, specified Box for Checking Conditions ... +// * @param appliedBox: XBoxZone instance Reference, hold's Selected Box inside Parent which trading conditions happens on it ... +// * @param swingBar: XOHCL instance Reference, holds Swing Bar if Exists ... +// * @param breakerBar: XOHCL instance Reference, holds Breaker Bar if Exists ... +// * @param rejectionBar: XOHCL instance Reference, holds Rejection Bar if Exists ... +// * @param momentumBar: XOHCL instance Reference, holds Momentum Bar if Exists ... +// * @param state: XPOIState instance Reference, provides requirement zone's for check Conditions ... +// * @param barIndex: int, Specified Bar Index ... +// * @param forPeriod: ENUM_TIMEFRAMES member, Specified Conditions Checking Period ... +// * +// * @return ( bool ) +// */ +// bool CheckBoxForTradeConditions( +// XBoxZone &box, +// XBoxZone &appliedBox, +// XOHCL &swingBar, +// XOHCL &breakerBar, +// XOHCL &rejectionBar, +// XOHCL &momentumBar, +// XPOIState &state, +// int barIndex = 0, +// ENUM_TIMEFRAMES forPeriod = NULL // +// ) +// { +// // +// bool result = false; + +// // +// swingBar.Clean(); +// appliedBox.Clean(); +// breakerBar.Clean(); +// momentumBar.Clean(); +// rejectionBar.Clean(); + +// // +// if (barIndex < 0) +// { +// barIndex = 0; +// } + +// // +// result = box.IsValid() && +// state.IsValid() && +// state.HasChild(); +// if (!result) +// { +// return result; +// } + +// // +// if (!IsValid(forPeriod)) +// { +// forPeriod = box.period; +// } + +// // +// string symbol = box.symbol; +// datetime cTime = iTime( +// symbol, +// forPeriod, +// barIndex // +// ); + +// // +// ENUM_X_DIRECTION forDir = box.dir; +// result = HasDirection(forDir); +// if (!result) +// { +// return result; +// } + +// // +// bool isBullish = IsBullish(forDir); + +// // +// int supportsCount = 0; +// bool hasSupports = false; +// XCSupportZone *supports[]; + +// // +// int resistancesCount = 0; +// bool hasResistances = false; +// XCResistanceZone *resistances[]; + +// // +// XBoxZone supResBoxes[]; +// int supresBoxesCount = 0; +// bool hasSupResBoxes = false; + +// // +// int count = 0; +// bool has = false; + +// // +// has = state.HasSupportZones(); +// if (has) +// { +// // +// count = state.CountSupportZones(); +// for (int i = 0; i < count; i++) +// { +// // +// XCSupportZone *iZone = state.supportZones[i]; + +// // +// iZone.To(cTime); + +// // +// XBoxZone iBox; +// bool hasBox = ToBox( +// iBox, +// iZone // +// ); +// if (!hasBox) +// { +// // +// iBox.Clean(); +// continue; +// } + +// // +// // Check From ... +// bool isInside = IsBoxInside( +// iBox, +// box // +// ); +// if (!isInside) +// { +// // +// iBox.Clean(); +// continue; +// } + +// // +// Add( +// iZone, +// supports // +// ); + +// // +// AddRef( +// iBox, +// supResBoxes // +// ); + +// // +// iBox.Clean(); +// } + +// // +// supportsCount = ArraySize(supports); +// hasSupports = IsValidSize(supportsCount); + +// // +// supresBoxesCount = ArraySize(supResBoxes); +// hasSupResBoxes = IsValidSize(supresBoxesCount); +// } + +// // +// has = state.HasResistanceZones(); +// if (has) +// { +// // +// count = state.CountResistanceZones(); +// for (int i = 0; i < count; i++) +// { +// // +// XCResistanceZone *iZone = state.resistanceZones[i]; + +// // +// iZone.To(cTime); + +// // +// XBoxZone iBox; +// bool hasBox = ToBox( +// iBox, +// iZone // +// ); +// if (!hasBox) +// { +// // +// iBox.Clean(); +// continue; +// } + +// // +// // Check From ... +// bool isInside = IsBoxInside( +// iBox, +// box // +// ); +// if (!isInside) +// { +// // +// iBox.Clean(); +// continue; +// } + +// // +// Add( +// iZone, +// resistances // +// ); + +// // +// AddRef( +// iBox, +// supResBoxes // +// ); + +// // +// iBox.Clean(); +// } + +// // +// resistancesCount = ArraySize(resistances); +// hasResistances = IsValidSize(resistancesCount); + +// // +// supresBoxesCount = ArraySize(supResBoxes); +// hasSupResBoxes = IsValidSize(supresBoxesCount); +// } + +// // +// result = hasSupResBoxes; +// if (!result) +// { +// // +// Clean(supports); +// Clean(resistances); +// Clean(supResBoxes); + +// // +// return result; +// } + +// // +// // Detect Bars ... + +// // +// XOHCL zBar; +// result = zBar.Init( +// symbol, +// forPeriod, +// barIndex // +// ); +// if (!result) +// { +// // +// zBar.Clean(); +// Clean(supports); +// Clean(resistances); +// Clean(supResBoxes); + +// // +// return result; +// } + +// // +// XOHCL cBar; +// result = zBar.GetPreviousBar(cBar); +// if (!result) +// { +// // +// zBar.Clean(); +// cBar.Clean(); +// Clean(supports); +// Clean(resistances); +// Clean(supResBoxes); + +// // +// return result; +// } + +// // +// XOHCL pBar; +// result = cBar.GetPreviousBar(pBar); +// if (!result) +// { +// // +// zBar.Clean(); +// cBar.Clean(); +// pBar.Clean(); +// Clean(supports); +// Clean(resistances); +// Clean(supResBoxes); + +// // +// return result; +// } + +// // +// XOHCL ppBar; +// result = pBar.GetPreviousBar(ppBar); +// if (!result) +// { +// // +// zBar.Clean(); +// cBar.Clean(); +// pBar.Clean(); +// ppBar.Clean(); +// Clean(supports); +// Clean(resistances); +// Clean(supResBoxes); + +// // +// return result; +// } +// // +// // Check Conditions ... + +// // +// // Detect Start Senario ... + +// // +// double fiboPressureLevel = GetFiboLevelValue(X_FIBO_LEVEL_382); + +// // +// double fiboUpDown = GetFibonacciLevel( +// pBar.high, +// pBar.low, +// X_FIBO_LEVEL_382, +// X_DIRECTION_BEARISH // +// ); +// double fiboDownUp = GetFibonacciLevel( +// pBar.high, +// pBar.low, +// X_FIBO_LEVEL_382, +// X_DIRECTION_BULLISH // +// ); + +// // +// bool hasFiboToUpPressure = +// fiboDownUp > 0 && +// fiboDownUp <= pBar.GetDown(); +// bool hasFiboToDownPressure = +// fiboUpDown > 0 && +// fiboUpDown >= pBar.GetUp(); + +// // +// int selectedBoxIDX = -1; +// for (int j = 0; j < supresBoxesCount; j++) +// { +// // +// double appliedPrice = +// isBullish +// ? supResBoxes[j].lower +// : supResBoxes[j].upper; + +// // +// // Check Swing Low ... +// bool isSwingLow = +// // +// pBar.low < ppBar.low && +// pBar.low < cBar.low && +// zBar.open > pBar.low && +// // +// appliedPrice > pBar.low && +// appliedPrice < pBar.GetDown() +// // +// ; +// bool isPressuredSwingLow = +// isSwingLow && +// hasFiboToUpPressure; +// bool isPressuredStrongSwingLow = +// pBar.IsBullish() && +// isPressuredSwingLow; + +// // +// bool isSwingHigh = +// // +// pBar.high > ppBar.high && +// pBar.high > cBar.high && +// zBar.open < pBar.high && +// // +// appliedPrice < pBar.high && +// appliedPrice > pBar.GetUp() +// // +// ; +// bool isPressuredSwingHigh = +// isSwingHigh && +// hasFiboToDownPressure; +// bool isPressuredStrongSwingHigh = +// pBar.IsBearish() && +// isPressuredSwingHigh; + +// // +// bool hasValidSwing = +// isBullish +// ? isSwingLow +// : isSwingHigh; +// bool hasValidPressuredSwing = +// isBullish +// ? isPressuredSwingLow +// : isPressuredSwingHigh; +// bool hasValidPressuredStrongSwing = +// isBullish +// ? isPressuredStrongSwingLow +// : isPressuredStrongSwingHigh; +// if (hasValidSwing) +// { +// swingBar = pBar; +// } +// if (hasValidPressuredSwing) +// { +// swingBar = pBar; +// } +// if (hasValidPressuredStrongSwing) +// { +// swingBar = pBar; +// } + +// // +// bool isCBarBreaked = IsBarBreak( +// appliedPrice, +// forDir, +// cBar // +// ); +// if (isCBarBreaked) +// { +// breakerBar = cBar; +// } +// bool isPBarBreaked = IsBarBreak( +// appliedPrice, +// forDir, +// pBar // +// ); +// if (!isCBarBreaked && isPBarBreaked) +// { +// breakerBar = pBar; +// } +// else +// { +// isPBarBreaked = false; +// } +// bool isPPBarBreaked = IsBarBreak( +// appliedPrice, +// forDir, +// ppBar // +// ); +// if (!isCBarBreaked && +// !isPBarBreaked && +// isPPBarBreaked) +// { +// breakerBar = ppBar; +// } +// else +// { +// isPPBarBreaked = false; +// } +// bool isBoxBreaked = isCBarBreaked || +// isPBarBreaked || +// isPPBarBreaked; + +// // +// bool isCBarRejected = IsBarReject( +// appliedPrice, +// forDir, +// cBar // +// ); +// if (isCBarRejected) +// { +// rejectionBar = cBar; +// } +// bool isPBarRejected = IsBarReject( +// appliedPrice, +// forDir, +// pBar // +// ); +// if (!isCBarRejected && isPBarRejected) +// { +// rejectionBar = pBar; +// } +// else +// { +// isPBarRejected = false; +// } +// bool isPPBarRejected = IsBarReject( +// appliedPrice, +// forDir, +// ppBar // +// ); +// if (!isCBarRejected && +// !isPBarRejected && +// isPPBarRejected) +// { +// rejectionBar = ppBar; +// } +// else +// { +// isPPBarRejected = false; +// } +// bool isBoxRejected = isCBarRejected || +// isPBarRejected || +// isPPBarRejected; + +// // +// bool hasRejectionBar = false; +// if (isBullish) +// { +// // +// count = state.CountBullishRejectionBars(); +// for (int i = 0; i < count; i++) +// { +// // +// XCRejectionBar *iZone = state.bullishRejectionBars[i]; + +// // +// XOHCL iBar; +// bool isFilled = iZone.FillBar(iBar); +// if (!isFilled) +// { +// continue; +// } + +// // +// int iBarIndex = iBar.Index(); + +// // +// hasRejectionBar = +// // +// (iBarIndex == cBar.Index() || +// iBarIndex == pBar.Index()) +// // +// ; +// if (hasRejectionBar) +// { +// // +// if (!rejectionBar.IsValid()) +// { +// rejectionBar = iBar; +// } + +// // +// break; +// } +// } +// } +// else +// { +// // +// count = state.CountBearishRejectionBars(); +// for (int i = 0; i < count; i++) +// { +// // +// XCRejectionBar *iZone = state.bearishRejectionBars[i]; + +// // +// XOHCL iBar; +// bool isFilled = iZone.FillBar(iBar); +// if (!isFilled) +// { +// continue; +// } + +// // +// int iBarIndex = iBar.Index(); + +// // +// hasRejectionBar = +// // +// (iBarIndex == cBar.Index() || +// iBarIndex == pBar.Index()) +// // +// ; +// if (hasRejectionBar) +// { +// // +// if (!rejectionBar.IsValid()) +// { +// rejectionBar = iBar; +// } + +// // +// break; +// } +// } +// } + +// // +// bool hasMomentumBar = false; +// if (isBullish) +// { +// // +// count = state.CountBullishMomentumBars(); +// for (int i = 0; i < count; i++) +// { +// // +// XCMomentumBar *iZone = state.bullishMomentumBars[i]; + +// // +// XOHCL iBar; +// bool isFilled = iZone.FillBar(iBar); +// if (!isFilled) +// { +// continue; +// } + +// // +// int iBarIndex = iBar.Index(); + +// // +// hasMomentumBar = +// // +// (iBarIndex == cBar.Index() || +// iBarIndex == pBar.Index()) +// // +// ; +// if (hasMomentumBar) +// { +// // +// if (!momentumBar.IsValid()) +// { +// momentumBar = iBar; +// } + +// // +// break; +// } +// } +// } +// else +// { +// // +// count = state.CountBearishMomentumBars(); +// for (int i = 0; i < count; i++) +// { +// // +// XCMomentumBar *iZone = state.bearishMomentumBars[i]; + +// // +// XOHCL iBar; +// bool isFilled = iZone.FillBar(iBar); +// if (!isFilled) +// { +// continue; +// } + +// // +// int iBarIndex = iBar.Index(); + +// // +// hasMomentumBar = +// // +// (iBarIndex == cBar.Index() || +// iBarIndex == pBar.Index()) +// // +// ; +// if (hasMomentumBar) +// { +// // +// if (!momentumBar.IsValid()) +// { +// momentumBar = iBar; +// } + +// // +// break; +// } +// } +// } + +// // +// bool hasSwing = false; +// if (isBullish) +// { +// // +// count = state.CountSwingLows(); +// for (int i = 0; i < count; i++) +// { +// // +// XCSwing *iSwing = state.swingLows[i]; + +// // +// XOHCL iBar; +// bool isFilled = iSwing.FillBar(iBar); +// if (!isFilled) +// { +// continue; +// } + +// // +// int iBarIndex = iBar.Index(); + +// // +// hasSwing = +// // +// (iBarIndex == cBar.Index() || +// iBarIndex == pBar.Index()) +// // +// ; +// if (hasSwing) +// { +// // +// if (!swingBar.IsValid()) +// { +// swingBar = iBar; +// } + +// // +// break; +// } +// } +// } +// else +// { +// // +// count = state.CountSwingHighs(); +// for (int i = 0; i < count; i++) +// { +// // +// XCSwing *iSwing = state.swingHighs[i]; + +// // +// XOHCL iBar; +// bool isFilled = iSwing.FillBar(iBar); +// if (!isFilled) +// { +// continue; +// } + +// // +// int iBarIndex = iBar.Index(); + +// // +// hasSwing = +// // +// (iBarIndex == cBar.Index() || +// iBarIndex == pBar.Index()) +// // +// ; +// if (hasSwing) +// { +// // +// if (!swingBar.IsValid()) +// { +// swingBar = iBar; +// } + +// // +// break; +// } +// } +// } + +// // +// bool hasRequiredValidations = +// // +// (hasRejectionBar || +// hasMomentumBar) +// // +// || +// // +// (hasRejectionBar || +// hasSwing) +// // +// || +// // +// (hasMomentumBar || +// hasSwing) +// // +// ; + +// // +// result = +// // +// (isBoxBreaked && +// (hasRequiredValidations || +// hasValidPressuredSwing)) +// // +// || +// // +// (isBoxRejected && +// (hasRequiredValidations || +// hasValidPressuredSwing)) +// // +// ; +// if (result) +// { +// // +// selectedBoxIDX = j; +// break; +// } +// } + +// // +// result = +// result && +// (isBullish +// ? zBar.open > box.upper +// : zBar.open < box.lower) && +// IsValidIndex(selectedBoxIDX); +// if (result) +// { +// appliedBox = supResBoxes[selectedBoxIDX]; +// } + +// // +// zBar.Clean(); +// cBar.Clean(); +// pBar.Clean(); +// ppBar.Clean(); +// Clean(supports); +// Clean(resistances); +// Clean(supResBoxes); + +// // +// return result; +// } diff --git a/Libraries/x-saherelm.x-poi.lib.mq5 b/Libraries/x-saherelm.x-poi.lib.mq5 index cd7f29a4..449e7ee2 100644 --- a/Libraries/x-saherelm.x-poi.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.lib.mq5 @@ -67,6 +67,9 @@ enum ENUM_XPOIS // Fair Value Gaps ... X_POI_BULLISH_FVG, // Bullish Order Block ... X_POI_BEARISH_FVG, // Bearish Order Block ... + // + X_BULLISH_CONSOLIDATION_ZONE, + X_BEARISH_CONSOLIDATION_ZONE, }; // @@ -111,6 +114,8 @@ enum ENUM_XPOI_EVENTS // Fair Value Gaps ... X_BULLISH_FVG_DETECTED, // Bullish Fair Value Gapّ ... X_BEARISH_FVG_DETECTED, // Bearish Fair Value Gapّ ... + X_BULLISH_CONSOLIDATION_ZONE_DETECTED, + X_BEARISH_CONSOLIDATION_ZONE_DETECTED, }; // @@ -222,6 +227,16 @@ string ToString(ENUM_XPOIS value) case X_POI_TICKS_ZONES: result = "XTKSZ"; break; + + // + case X_BULLISH_CONSOLIDATION_ZONE: + result = "XBULLCZ"; + break; + + // + case X_BEARISH_CONSOLIDATION_ZONE: + result = "XBEARCZ"; + break; } // @@ -5175,427 +5190,6 @@ class XCSession : public XCFromToZone // }; -// -// Consolidation Zone ... -struct XConsolidationZone -{ - // - // Props ... - - // - string symbol; // Symbol ... - ENUM_TIMEFRAMES period; // Period ... - - // - double upper; // Upper ... - double lower; // Lower ... - - // - datetime initTime; - int loopback; // Loopback ... - - // - ENUM_X_DIRECTION breakDir; // Break Direction ... - XOHCL breakerBar; // Breaker Bar ... - - // - // Constructor ... - XConsolidationZone() - { - Clean(); - } - - // - // Tools ... - - /** - * Initialize Zone ... - * - * @param _symbol: String ... - * @param _period: ENUM_TIMEFRAMES member ... - * @param _upper: Double ... - * @param _lower: Double ... - * @param _loopback: Integer ... - * - * @return ( bool ) - */ - bool Init( - string _symbol, - ENUM_TIMEFRAMES _period, - double _upper, - double _lower, - int _loopback // - ) - { - // - bool result = false; - - // - _symbol = NormalizeSymbol(_symbol); - _period = NormalizePeriod(_period); - - // - result = - // - _upper > 0 && - _lower > 0 && - _loopback > 0 - // - ; - if (!result) - { - return result; - } - - // - upper = _upper; - lower = _lower; - symbol = _symbol; - period = _period; - loopback = _loopback; - - // - result = IsValid(); - if (result) - { - initTime = TimeCurrent(); - } - - // - return result; - } - - /** - * Update Breaked State ... - */ - void Update() - { - // - if (!IsValid()) - { - return; - } - - // - if (IsBreaked()) - { - return; - } - - // - XOHCL cBar; - bool isInited = cBar.Init( - symbol, - period, - 0 // - ); - if (!isInited) - { - return; - } - - // - XOHCL pBar; - isInited = cBar.GetPreviousBar(pBar); - if (!isInited) - { - return; - } - - // - // Check Consolidation Hounts ... - bool isHountTop = cBar.high > upper && - cBar.low < upper && - cBar.GetUp() < upper; - bool isHountBottom = cBar.low < lower && - cBar.high > lower && - cBar.GetDown() > lower; - bool isHounted = isHountTop || - isHountBottom; - if (isHounted) - { - // - if (isHountTop) - { - upper = cBar.high; - } - - // - if (isHountBottom) - { - lower = cBar.low; - } - - // - return; - } - - // - // Check Consolidation Breaks ... - bool isBreakTop = (cBar.GetUp() > upper && - cBar.GetDown() < upper) || - (cBar.low > upper && - cBar.high > upper); - bool isBreakBottom = (cBar.GetDown() < lower && - cBar.GetUp() > lower) || - (cBar.high < lower && - cBar.low < lower); - bool isBreaked = isBreakTop || - isBreakBottom; - if (!isBreaked) - { - return; - } - - // - // Calculate Break Direction ... - breakerBar = cBar; - breakDir = isBreakTop - ? X_DIRECTION_BULLISH - : isBreakBottom - ? X_DIRECTION_BEARISH - : X_DIRECTION_NONE; - } - - /** - * Cleanup ... - */ - void Clean() - { - // - upper = 0; - lower = 0; - loopback = 0; - symbol = NULL; - period = NULL; - initTime = NULL; - breakerBar.Clean(); - breakDir = X_DIRECTION_NONE; - - // - ZeroMemory(this); - } - - /** - * Validate ... - * - * @return ( bool ) - */ - bool IsValid() - { - // - bool result = false; - - // - result = - // - IsValid(symbol) && - IsValid(period) && - upper > 0 && - lower > 0 && - loopback > 0 - // - ; - - // - return result; - } - - /** - * Check Zone is Breaked or not ... - * - * @return ( bool ) - */ - bool IsBreaked() - { - // - bool result = false; - - // - result = breakerBar.IsValid() && - HasDirection(breakDir); - - // - return result; - } - - /** - * Detect Supply Zone if Exists ... - * - * @return ( bool ) - */ - bool HasSupplyZone( - XCSupplyZone *&zone // - ) - { - // - bool result = false; - - // - result = IsBreaked() && - breakDir == X_DIRECTION_BEARISH; - if (!result) - { - return result; - } - - // - // Implment Zone Finding ... - int index = breakerBar.Index(); - int hhIDX = iHighest( - symbol, - period, - MODE_HIGH, - loopback, - index // - ); - result = IsValidIndex(hhIDX); - if (!result) - { - return result; - } - - // - XOHCL hhBar; - result = hhBar.Init( - symbol, - period, - hhIDX // - ); - if (!result) - { - return result; - } - - // - zone = new XCSupplyZone(); - result = zone.Init( - hhBar, - loopback // - ); - - // - return result; - } - - /** - * Detect Demand Zone if Exists ... - * - * @return ( bool ) - */ - bool HasDemandZone( - XCDemandZone *&zone // - ) - { - // - bool result = false; - - // - result = IsBreaked() && - breakDir == X_DIRECTION_BULLISH; - if (!result) - { - return result; - } - - // - // Implment Zone Finding ... - int index = breakerBar.Index(); - int llIDX = iLowest( - symbol, - period, - MODE_LOW, - loopback, - index // - ); - result = IsValidIndex(llIDX); - if (!result) - { - return result; - } - - // - XOHCL llBar; - result = llBar.Init( - symbol, - period, - llIDX // - ); - if (!result) - { - return result; - } - - // - zone = new XCDemandZone(); - result = zone.Init( - llBar, - loopback // - ); - - // - return result; - } - - /** - * Retrieve Start Time ... - * - * @return ( datetime ) - */ - datetime From() - { - // - datetime result = NULL; - - // - if (!IsValid()) - { - return result; - } - - // - int startIndex = iBarShift( - symbol, - period, - initTime // - ); - - // - result = iTime( - symbol, - period, - loopback + startIndex // - ); - - // - return result; - } - - /** - * Retrieve Unique Identifier ... - * - * @return ( string ) - */ - string GetTag() - { - // - string result = - // - "ConsolidationZone" + "_" + - symbol + "_" + - ToString(period) + "_" + - ToString(upper) + "_" + - ToString(lower) - // - ; - - // - return result; - } - - // -}; - // struct XBoxZone { diff --git a/Libraries/x-saherelm.x-poi.state.lib.mq5 b/Libraries/x-saherelm.x-poi.state.lib.mq5 index 96078b9d..c9ea5313 100644 --- a/Libraries/x-saherelm.x-poi.state.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.state.lib.mq5 @@ -384,6 +384,11 @@ struct XPOIState XCFVG *bullishFairValueGaps[]; // Holds Founded Bullish Fair Value Gaps ... XCFVG *bearishFairValueGaps[]; // Holds Founded Bearish Fair Value Gaps ... + // + XConsolidationZone consolidationZones[]; // Holds Founded Consolidation Zones ... + XConsolidationZone bullishConsolidationZones[]; // Holds Founded Bullish Consolidation Zones ... + XConsolidationZone bearishConsolidationZones[]; // Holds Founded Bearih Consolidation Zones ... + // // Constructor ... void XPOIState() @@ -437,6 +442,11 @@ struct XPOIState Clean(bullishFairValueGaps); Clean(bearishFairValueGaps); + // + Clean(consolidationZones); + Clean(bullishConsolidationZones); + Clean(bearishConsolidationZones); + // ZeroMemory(this); } @@ -474,20 +484,22 @@ struct XPOIState // result = // - IsValidSize(CountSwingHighs()) || - IsValidSize(CountSwingLows()) || - IsValidSize(CountBullishMomentumBars()) || - IsValidSize(CountBearishMomentumBars()) || - IsValidSize(CountBullishRejectionBars()) || - IsValidSize(CountBearishRejectionBars()) || - IsValidSize(CountSupportZones()) || - IsValidSize(CountResistanceZones()) || - IsValidSize(CountSupplyZones()) || - IsValidSize(CountDemandZones()) || - IsValidSize(CountBullishOrderBlocks()) || - IsValidSize(CountBearishOrderBlocks()) || - IsValidSize(CountBullishFairValueGaps()) || - IsValidSize(CountBearishFairValueGaps()) + HasSwingLows() || + HasSwingHighs() || + HasSupplyZones() || + HasDemandZones() || + HasSupportZones() || + HasResistanceZones() || + HasBullishOrderBlocks() || + HasBearishOrderBlocks() || + HasBullishMomentumBars() || + HasBearishMomentumBars() || + HasBullishRejectionBars() || + HasBearishRejectionBars() || + HasBullishFairValueGaps() || + HasBearishFairValueGaps() || + HasBullishConsolidationZones() || + HasBearishConsolidationZones() // ; @@ -495,101 +507,6 @@ struct XPOIState return result; } - /** - * Fill Dest State by Current State's Data ... - * - * @param dest: XPOIState instance, reference to specified dest ... - * - */ - void Fill(XPOIState &dest) - { - // - if (!IsValid() || - !HasChild()) - { - return; - } - - // - dest.symbol = symbol; - dest.period = period; - dest.time = time; - - // - Copy( - swingHighs, - dest.swingHighs, - false // - ); - Copy( - swingLows, - dest.swingLows, - false // - ); - Copy( - bullishMomentumBars, - dest.bullishMomentumBars, - false // - ); - Copy( - bearishMomentumBars, - dest.bearishMomentumBars, - false // - ); - Copy( - bullishRejectionBars, - dest.bullishRejectionBars, - false // - ); - Copy( - bearishRejectionBars, - dest.bearishRejectionBars, - false // - ); - Copy( - supportZones, - dest.supportZones, - false // - ); - Copy( - resistanceZones, - dest.resistanceZones, - false // - ); - Copy( - supplyZones, - dest.supplyZones, - false // - ); - Copy( - demandZones, - dest.demandZones, - false // - ); - Copy( - bullishOrderBlocks, - dest.bullishOrderBlocks, - false // - ); - Copy( - bearishOrderBlocks, - dest.bearishOrderBlocks, - false // - ); - Copy( - bullishFairValueGaps, - dest.bullishFairValueGaps, - false // - ); - Copy( - bearishFairValueGaps, - dest.bearishFairValueGaps, - false // - ); - - // - } - // // Counters ... @@ -1068,6 +985,42 @@ struct XPOIState return IsValidSize(CountBearishFairValueGaps()); } + // + bool HasConsolidationZones() + { + return HasChild(consolidationZones); + } + + // + int CountConsolidationZones() + { + return ArraySize(consolidationZones); + } + + // + bool HasBullishConsolidationZones() + { + return HasChild(bullishConsolidationZones); + } + + // + int CountBullishConsolidationZones() + { + return ArraySize(bullishConsolidationZones); + } + + // + bool HasBearishConsolidationZones() + { + return HasChild(bearishConsolidationZones); + } + + // + int CountBearishConsolidationZones() + { + return ArraySize(bearishConsolidationZones); + } + // void UpdateTo(datetime value = NULL) { diff --git a/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 b/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 index de345e3a..1f5a5ee8 100644 --- a/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 @@ -106,183 +106,6 @@ class XC121SMCCycleHelper : public XCBase // // Getter/Setter(s) ... - // - int CountConsolidationZones() - { - return ArraySize(mConsolidationZones); - } - - // - bool HasConsolidationZones() - { - return HasChild(mConsolidationZones); - } - - // - bool GetConsolidationZone( - int idx, - XConsolidationZone &zone // - ) - { - // - bool result = false; - - // - zone.Clean(); - - // - result = HasConsolidationZones(); - if (!result) - { - return result; - } - - // - int count = CountConsolidationZones(); - result = idx >= 0 && - idx < count; - if (!result) - { - return result; - } - - // - zone = mConsolidationZones[idx]; - result = zone.IsValid(); - - // - return result; - } - - // - bool GetLastDirectionalConsolidationZone( - ENUM_X_DIRECTION forDir, - XConsolidationZone &zone // - ) - { - // - bool result = false; - - // - zone.Clean(); - - // - result = HasDirection(forDir); - if (!result) - { - return result; - } - - // - bool hasZones = HasConsolidationZones(); - int zonesCount = CountConsolidationZones(); - result = hasZones; - if (!result) - { - return result; - } - - // - for (int i = zonesCount - 1; i >= 0; i--) - { - // - XConsolidationZone iZone = mConsolidationZones[i]; - - // - if (!iZone.IsBreaked()) - { - continue; - } - - // - if (!HasDirection(iZone.breakDir)) - { - continue; - } - - // - if (iZone.breakDir != forDir) - { - continue; - } - - // - zone = iZone; - break; - } - - // - result = zone.IsValid(); - - // - return result; - } - - // - bool GetActiveConsolidationZone( - XConsolidationZone &zone // - ) - { - // - bool result = false; - - // - zone = mActiveConsolidationZone; - result = zone.IsValid(); - - // - return result; - } - - // - int FillConsolidationZones( - ENUM_X_DIRECTION forDir, - XConsolidationZone &zones[] // - ) - { - // - int result = 0; - - // - Clean(zones); - - // - bool hasZones = HasConsolidationZones(); - if (!hasZones) - { - return result; - } - - // - int count = CountConsolidationZones(); - for (int i = 0; i < count; i++) - { - // - XConsolidationZone iZone = mConsolidationZones[i]; - - // - bool isDirPassed = - (forDir == X_DIRECTION_ALL || - forDir == X_DIRECTION_NONE) - ? true - : forDir == iZone.breakDir; - if (isDirPassed) - { - // - AddRef( - iZone, - zones // - ); - } - } - - // - result = ArraySize(zones); - - // - return result; - } - // // Actions ... @@ -618,7 +441,7 @@ class XC121SMCCycleHelper : public XCBase conditions.time = TimeCurrent(); // - Update(); + // Update(); // result = conditions.IsValid(); @@ -627,87 +450,6 @@ class XC121SMCCycleHelper : public XCBase return result; } - // - // Tools ... - void Update() - { - // - int czRange = 50; // Consolidation min Range Points ... - int czLoopback = 5; - int maxAllowed = 20; - bool isActiveConsolidationZoneBreaked = false; - bool hasActiveConsolidationZone = mActiveConsolidationZone.IsValid(); - - // - if (hasActiveConsolidationZone) - { - // - isActiveConsolidationZoneBreaked = mActiveConsolidationZone.IsBreaked(); - - // - if (isActiveConsolidationZoneBreaked) - { - // - AddRef( - mActiveConsolidationZone, - mConsolidationZones // - ); - - // - CleanupArray( - mConsolidationZones, - maxAllowed // - ); - - // - mActiveConsolidationZone.Clean(); - } - else - { - mActiveConsolidationZone.Update(); - } - } - else - { - // - XOHCL mBar; - bool hasBar = GetBar( - mBar, - 0 // - ); - if (hasBar) - { - // - double upper = 0; - double lower = 0; - bool hasConsolidationZone = - mBarAnalyser.IsConsolidate( - mBar, - upper, - lower, - czLoopback, - czRange // - ); - - // - if (hasConsolidationZone) - { - // - mActiveConsolidationZone.Init( - GetSymbol(), - GetPeriod(), - upper, - lower, - czLoopback // - ); - } - } - - // - mBar.Clean(); - } - } - // // Virtuals ... @@ -729,11 +471,6 @@ class XC121SMCCycleHelper : public XCBase string mSymbol; ENUM_TIMEFRAMES mPeriod; - // - // CArrayObj mConsolidationObjects; - XConsolidationZone mActiveConsolidationZone; - XConsolidationZone mConsolidationZones[]; - // // Actions ... @@ -751,10 +488,6 @@ class XC121SMCCycleHelper : public XCBase delete mX121Helper; delete mPOIDetector; delete mBarAnalyser; - - // - Clean(mConsolidationZones); - mActiveConsolidationZone.Clean(); } /** diff --git a/X121SMCEA/Libraries/x-121.smc.guard.lib.mq5 b/X121SMCEA/Libraries/x-121.smc.guard.lib.mq5 index 6a10ca41..87bebf7f 100644 --- a/X121SMCEA/Libraries/x-121.smc.guard.lib.mq5 +++ b/X121SMCEA/Libraries/x-121.smc.guard.lib.mq5 @@ -489,172 +489,172 @@ bool DetectX121SMCGuards( // // - // - // Detect Consolidation Zone ... + // // + // // Detect Consolidation Zone ... - // - // Detect Consolidation Zones ... + // // + // // Detect Consolidation Zones ... - // - XBoxZone lastBullishBox; - XBoxZone prevLastBullishBox; - bool hasLastBullishBox = false; - bool hasPrevLastBullishBox = false; - XConsolidationZone lastBullishZone; - bool isLastBullishAbovePrev = false; - bool isLastBullishBelowPrev = false; - XConsolidationZone prevLastBullishZone; + // // + // XBoxZone lastBullishBox; + // XBoxZone prevLastBullishBox; + // bool hasLastBullishBox = false; + // bool hasPrevLastBullishBox = false; + // XConsolidationZone lastBullishZone; + // bool isLastBullishAbovePrev = false; + // bool isLastBullishBelowPrev = false; + // XConsolidationZone prevLastBullishZone; - // - XBoxZone lastBearishBox; - XBoxZone prevLastBearishBox; - bool hasLastBearishBox = false; - bool hasPrevLastBearishBox = false; - XConsolidationZone lastBearishZone; - bool isLastBearishAbovePrev = false; - bool isLastBearishBelowPrev = false; - XConsolidationZone prevLastBearishZone; + // // + // XBoxZone lastBearishBox; + // XBoxZone prevLastBearishBox; + // bool hasLastBearishBox = false; + // bool hasPrevLastBearishBox = false; + // XConsolidationZone lastBearishZone; + // bool isLastBearishAbovePrev = false; + // bool isLastBearishBelowPrev = false; + // XConsolidationZone prevLastBearishZone; - // - int bullishConsolidationZonesCount = 0; - int bearishConsolidationZonesCount = 0; - bool hasBullishConsolidationZones = false; - bool hasBearishConsolidationZones = false; - XConsolidationZone bullishConsolidationZones[]; - XConsolidationZone bearishConsolidationZones[]; - bool hasConsolidationZones = decisionCycleHelper.HasConsolidationZones(); - int consolidationZonesCount = decisionCycleHelper.CountConsolidationZones(); - if (hasConsolidationZones) - { - // - bullishConsolidationZonesCount = decisionCycleHelper - .FillConsolidationZones( - X_DIRECTION_BULLISH, - bullishConsolidationZones // - ); - hasBullishConsolidationZones = IsValidSize(bullishConsolidationZonesCount); + // // + // int bullishConsolidationZonesCount = 0; + // int bearishConsolidationZonesCount = 0; + // bool hasBullishConsolidationZones = false; + // bool hasBearishConsolidationZones = false; + // XConsolidationZone bullishConsolidationZones[]; + // XConsolidationZone bearishConsolidationZones[]; + // bool hasConsolidationZones = decisionCycleHelper.HasConsolidationZones(); + // int consolidationZonesCount = decisionCycleHelper.CountConsolidationZones(); + // if (hasConsolidationZones) + // { + // // + // bullishConsolidationZonesCount = decisionCycleHelper + // .FillConsolidationZones( + // X_DIRECTION_BULLISH, + // bullishConsolidationZones // + // ); + // hasBullishConsolidationZones = IsValidSize(bullishConsolidationZonesCount); - // - bearishConsolidationZonesCount = decisionCycleHelper - .FillConsolidationZones( - X_DIRECTION_BEARISH, - bearishConsolidationZones // - ); - hasBearishConsolidationZones = IsValidSize(bearishConsolidationZonesCount); + // // + // bearishConsolidationZonesCount = decisionCycleHelper + // .FillConsolidationZones( + // X_DIRECTION_BEARISH, + // bearishConsolidationZones // + // ); + // hasBearishConsolidationZones = IsValidSize(bearishConsolidationZonesCount); - // - // - // + // // + // // + // // - // - if (hasBullishConsolidationZones && - bullishConsolidationZonesCount >= 2) - { - // - lastBullishZone = bullishConsolidationZones[bullishConsolidationZonesCount - 1]; - prevLastBullishZone = bullishConsolidationZones[bullishConsolidationZonesCount - 2]; + // // + // if (hasBullishConsolidationZones && + // bullishConsolidationZonesCount >= 2) + // { + // // + // lastBullishZone = bullishConsolidationZones[bullishConsolidationZonesCount - 1]; + // prevLastBullishZone = bullishConsolidationZones[bullishConsolidationZonesCount - 2]; - // - hasLastBullishBox = ToBox( - lastBullishBox, - lastBullishZone // - ); - hasPrevLastBullishBox = ToBox( - prevLastBullishBox, - prevLastBullishZone // - ); + // // + // hasLastBullishBox = ToBox( + // lastBullishBox, + // lastBullishZone // + // ); + // hasPrevLastBullishBox = ToBox( + // prevLastBullishBox, + // prevLastBullishZone // + // ); - // - isLastBullishAbovePrev = hasLastBullishBox && - hasPrevLastBullishBox && - IsBoxAbove( - lastBullishBox, - prevLastBullishBox // - ); + // // + // isLastBullishAbovePrev = hasLastBullishBox && + // hasPrevLastBullishBox && + // IsBoxAbove( + // lastBullishBox, + // prevLastBullishBox // + // ); - // - isLastBullishBelowPrev = hasLastBullishBox && - hasPrevLastBullishBox && - IsBoxBelow( - lastBullishBox, - prevLastBullishBox // - ); - } + // // + // isLastBullishBelowPrev = hasLastBullishBox && + // hasPrevLastBullishBox && + // IsBoxBelow( + // lastBullishBox, + // prevLastBullishBox // + // ); + // } - // - if (hasBearishConsolidationZones && - bearishConsolidationZonesCount >= 2) - { - // - lastBearishZone = bearishConsolidationZones[bearishConsolidationZonesCount - 1]; - prevLastBearishZone = bearishConsolidationZones[bearishConsolidationZonesCount - 2]; + // // + // if (hasBearishConsolidationZones && + // bearishConsolidationZonesCount >= 2) + // { + // // + // lastBearishZone = bearishConsolidationZones[bearishConsolidationZonesCount - 1]; + // prevLastBearishZone = bearishConsolidationZones[bearishConsolidationZonesCount - 2]; - // - hasLastBearishBox = ToBox( - lastBearishBox, - lastBearishZone // - ); - hasPrevLastBearishBox = ToBox( - prevLastBearishBox, - prevLastBearishZone // - ); + // // + // hasLastBearishBox = ToBox( + // lastBearishBox, + // lastBearishZone // + // ); + // hasPrevLastBearishBox = ToBox( + // prevLastBearishBox, + // prevLastBearishZone // + // ); - // - isLastBearishAbovePrev = hasLastBearishBox && - hasPrevLastBearishBox && - IsBoxAbove( - lastBearishBox, - prevLastBearishBox // - ); + // // + // isLastBearishAbovePrev = hasLastBearishBox && + // hasPrevLastBearishBox && + // IsBoxAbove( + // lastBearishBox, + // prevLastBearishBox // + // ); - // - isLastBearishBelowPrev = hasLastBearishBox && - hasPrevLastBearishBox && - IsBoxBelow( - lastBearishBox, - prevLastBearishBox // - ); - } + // // + // isLastBearishBelowPrev = hasLastBearishBox && + // hasPrevLastBearishBox && + // IsBoxBelow( + // lastBearishBox, + // prevLastBearishBox // + // ); + // } - // - } + // // + // } // // Detect High Probability Swings ... - bool isSwingLow = - // - cBar.low > pBar.low && - ppBar.low > pBar.low && - // - zBar.low > pBar.low - // - ; - bool isSwingHigh = - // - cBar.high < pBar.high && - ppBar.high < pBar.high && - // - zBar.high < pBar.high - // - ; - bool isStrongSwingLow = - pBar.IsBullish() && - pBar.GetLowShadow() >= pBar.GetBody() * 2; - bool isStrongSwingHigh = - pBar.IsBearish() && - pBar.GetHighShadow() >= pBar.GetBody() * 2; + // bool isSwingLow = + // // + // cBar.low > pBar.low && + // ppBar.low > pBar.low && + // // + // zBar.low > pBar.low + // // + // ; + // bool isSwingHigh = + // // + // cBar.high < pBar.high && + // ppBar.high < pBar.high && + // // + // zBar.high < pBar.high + // // + // ; + // bool isStrongSwingLow = + // pBar.IsBullish() && + // pBar.GetLowShadow() >= pBar.GetBody() * 2; + // bool isStrongSwingHigh = + // pBar.IsBearish() && + // pBar.GetHighShadow() >= pBar.GetBody() * 2; - // - bool isStrongSwingLowAboveLastBullishBox = - isStrongSwingLow && - hasLastBullishBox && - pBar.low > lastBullishBox.upper; + // // + // bool isStrongSwingLowAboveLastBullishBox = + // isStrongSwingLow && + // hasLastBullishBox && + // pBar.low > lastBullishBox.upper; - // - bool isStrongSwingHighBelowLastBearishBox = - isStrongSwingHigh && - hasLastBearishBox && - pBar.high < lastBearishBox.lower; + // // + // bool isStrongSwingHighBelowLastBearishBox = + // isStrongSwingHigh && + // hasLastBearishBox && + // pBar.high < lastBearishBox.lower; // // Here We Have all Requirements for Guarding Positions ... @@ -822,82 +822,82 @@ bool DetectX121SMCGuards( // - occures two same type consolidation zones in order of positions type; // - occures a swing in order of consolidation zones ... - // - bool canTrailBasedOnTwoZone = - isLong - ? isLastBullishAbovePrev - : isLastBearishBelowPrev; - if (canTrailBasedOnTwoZone) - { - // - trailedStop = - isLong - ? prevLastBullishBox.lower - : prevLastBearishBox.upper; - } + // // + // bool canTrailBasedOnTwoZone = + // isLong + // ? isLastBullishAbovePrev + // : isLastBearishBelowPrev; + // if (canTrailBasedOnTwoZone) + // { + // // + // trailedStop = + // isLong + // ? prevLastBullishBox.lower + // : prevLastBearishBox.upper; + // } - // - bool canTrailBasedOnZoneSwing = - trailedStop <= 0 && - (isLong - ? isStrongSwingLowAboveLastBullishBox - : isStrongSwingHighBelowLastBearishBox); - if (canTrailBasedOnZoneSwing) - { - // - trailedStop = - isLong - ? pBar.low - : pBar.high; - } + // // + // bool canTrailBasedOnZoneSwing = + // trailedStop <= 0 && + // (isLong + // ? isStrongSwingLowAboveLastBullishBox + // : isStrongSwingHighBelowLastBearishBox); + // if (canTrailBasedOnZoneSwing) + // { + // // + // trailedStop = + // isLong + // ? pBar.low + // : pBar.high; + // } - // - bool canDoTrailStop = - trailedStop > 0 && - ( - // - iPosition.sl == 0 - ? (isLong - ? trailedStop > iPosition.entry && - trailedStop < iPosition.price - : trailedStop < iPosition.entry && - trailedStop > iPosition.price) - : (isLong - ? trailedStop > iPosition.sl && - trailedStop > iPosition.entry && - trailedStop < iPosition.price - : trailedStop < iPosition.sl && - trailedStop < iPosition.entry && - trailedStop > iPosition.price) - // - ) - // - ; + // // + // bool canDoTrailStop = + // trailedStop > 0 && + // ( + // // + // iPosition.sl == 0 + // ? (isLong + // ? trailedStop > iPosition.entry && + // trailedStop < iPosition.price + // : trailedStop < iPosition.entry && + // trailedStop > iPosition.price) + // : (isLong + // ? trailedStop > iPosition.sl && + // trailedStop > iPosition.entry && + // trailedStop < iPosition.price + // : trailedStop < iPosition.sl && + // trailedStop < iPosition.entry && + // trailedStop > iPosition.price) + // // + // ) + // // + // ; - // - if (canDoTrailStop) - { - // - X121SMCGuard iGuard; + // // + // if (canDoTrailStop) + // { + // // + // X121SMCGuard iGuard; - // - iGuard.time = cTime; - iGuard.symbol = symbol; - iGuard.provider = provider; - iGuard.action = X_121_SMC_GUARD_ACTION_TRAIL_STOP; + // // + // iGuard.time = cTime; + // iGuard.symbol = symbol; + // iGuard.provider = provider; + // iGuard.action = X_121_SMC_GUARD_ACTION_TRAIL_STOP; - // - iGuard.ticket = iPosition.ticket; + // // + // iGuard.ticket = iPosition.ticket; - // - iGuard.sl = trailedStop; + // // + // iGuard.sl = trailedStop; - // - AddGuard( - iGuard, - guards // - ); - } + // // + // AddGuard( + // iGuard, + // guards // + // ); + // } } } @@ -956,14 +956,14 @@ bool DetectX121SMCGuards( consolidationXConditions.Clean(); // - lastBullishBox.Clean(); - lastBearishBox.Clean(); - lastBullishZone.Clean(); - lastBearishZone.Clean(); - prevLastBullishBox.Clean(); - prevLastBearishBox.Clean(); - prevLastBullishZone.Clean(); - prevLastBearishZone.Clean(); + // lastBullishBox.Clean(); + // lastBearishBox.Clean(); + // lastBullishZone.Clean(); + // lastBearishZone.Clean(); + // prevLastBullishBox.Clean(); + // prevLastBearishBox.Clean(); + // prevLastBullishZone.Clean(); + // prevLastBearishZone.Clean(); // count = ArraySize(guards); diff --git a/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 b/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 index 60026085..3e7262d6 100644 --- a/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 @@ -1082,26 +1082,26 @@ class XCX121SMCXWZSignalDetector : public XCBase // // - // - // Detect Consolidation Zone ... + // // + // // Detect Consolidation Zone ... - // - // Bullish ... - XConsolidationZone bullishConsolidationZone; - bool hasBullishConsolidationZone = decisionCycleHelper - .GetLastDirectionalConsolidationZone( - X_DIRECTION_BULLISH, - bullishConsolidationZone // - ); + // // + // // Bullish ... + // XConsolidationZone bullishConsolidationZone; + // bool hasBullishConsolidationZone = decisionCycleHelper + // .GetLastDirectionalConsolidationZone( + // X_DIRECTION_BULLISH, + // bullishConsolidationZone // + // ); - // - // Bearish ... - XConsolidationZone bearishConsolidationZone; - bool hasBearishConsolidationZone = decisionCycleHelper - .GetLastDirectionalConsolidationZone( - X_DIRECTION_BEARISH, - bearishConsolidationZone // - ); + // // + // // Bearish ... + // XConsolidationZone bearishConsolidationZone; + // bool hasBearishConsolidationZone = decisionCycleHelper + // .GetLastDirectionalConsolidationZone( + // X_DIRECTION_BEARISH, + // bearishConsolidationZone // + // ); // // Detect High Probability Swings ... @@ -1179,114 +1179,114 @@ class XCX121SMCXWZSignalDetector : public XCBase double sl = iPosition.sl; double tp = iPosition.tp; - // - // Trail Stops Using Consolidation Zones ... - bool canTraiLonglUsingCZone = - // - (isLong && - isInProfit && - hasBullishConsolidationZone && - bullishConsolidationZone.lower > iPosition.sl && - bullishConsolidationZone.lower > iPosition.entry) - // - ; - if (canTraiLonglUsingCZone) - { - sl = bullishConsolidationZone.lower; - } + // // + // // Trail Stops Using Consolidation Zones ... + // bool canTraiLonglUsingCZone = + // // + // (isLong && + // isInProfit && + // hasBullishConsolidationZone && + // bullishConsolidationZone.lower > iPosition.sl && + // bullishConsolidationZone.lower > iPosition.entry) + // // + // ; + // if (canTraiLonglUsingCZone) + // { + // sl = bullishConsolidationZone.lower; + // } - // - bool canTraiShortlUsingCZone = - // - (!isLong && - isInProfit && - hasBearishConsolidationZone && - bearishConsolidationZone.upper < iPosition.sl && - bearishConsolidationZone.upper < iPosition.entry) - // - ; - if (canTraiShortlUsingCZone) - { - sl = bearishConsolidationZone.upper; - } + // // + // bool canTraiShortlUsingCZone = + // // + // (!isLong && + // isInProfit && + // hasBearishConsolidationZone && + // bearishConsolidationZone.upper < iPosition.sl && + // bearishConsolidationZone.upper < iPosition.entry) + // // + // ; + // if (canTraiShortlUsingCZone) + // { + // sl = bearishConsolidationZone.upper; + // } - // - bool canTrailUsingCZone = - canTraiLonglUsingCZone || - canTraiShortlUsingCZone; + // // + // bool canTrailUsingCZone = + // canTraiLonglUsingCZone || + // canTraiShortlUsingCZone; - // - // Trail Stops Using Swings ... + // // + // // Trail Stops Using Swings ... - // - bool canTrailLongUsingSwings = - // - isLong && - isInProfit && - (isSwingLow || - isStrongSwingLow) && - pBar.low > iPosition.sl && - pBar.low > iPosition.entry - // - ; - if (canTrailLongUsingSwings) - { - sl = pBar.low; - } + // // + // bool canTrailLongUsingSwings = + // // + // isLong && + // isInProfit && + // (isSwingLow || + // isStrongSwingLow) && + // pBar.low > iPosition.sl && + // pBar.low > iPosition.entry + // // + // ; + // if (canTrailLongUsingSwings) + // { + // sl = pBar.low; + // } - // - bool canTraiShortlUsingSwings = - // - !isLong && - isInProfit && - (isSwingHigh || - isStrongSwingHigh) && - pBar.high < iPosition.sl && - pBar.high < iPosition.entry - // - ; - if (canTraiShortlUsingSwings) - { - sl = pBar.high; - } + // // + // bool canTraiShortlUsingSwings = + // // + // !isLong && + // isInProfit && + // (isSwingHigh || + // isStrongSwingHigh) && + // pBar.high < iPosition.sl && + // pBar.high < iPosition.entry + // // + // ; + // if (canTraiShortlUsingSwings) + // { + // sl = pBar.high; + // } - // - bool canTrailUsingSwings = - canTrailLongUsingSwings || - canTraiShortlUsingSwings; + // // + // bool canTrailUsingSwings = + // canTrailLongUsingSwings || + // canTraiShortlUsingSwings; - // - // - // + // // + // // + // // - // - bool canTrail = - sl != iPosition.sl && - (canTrailUsingCZone || - canTrailUsingSwings); - if (canTrail) - { - // - X121SMCGuard iGuard; + // // + // bool canTrail = + // sl != iPosition.sl && + // (canTrailUsingCZone || + // canTrailUsingSwings); + // if (canTrail) + // { + // // + // X121SMCGuard iGuard; - // - iGuard.time = cTime; - iGuard.symbol = symbol; - iGuard.provider = provider; - iGuard.action = X_121_SMC_GUARD_ACTION_TRAIL_STOP; + // // + // iGuard.time = cTime; + // iGuard.symbol = symbol; + // iGuard.provider = provider; + // iGuard.action = X_121_SMC_GUARD_ACTION_TRAIL_STOP; - // - iGuard.ticket = iPosition.ticket; + // // + // iGuard.ticket = iPosition.ticket; - // - iGuard.sl = sl; + // // + // iGuard.sl = sl; - // - AddGuard( - iGuard, - guards // - ); - } + // // + // AddGuard( + // iGuard, + // guards // + // ); + // } } // diff --git a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 index 6e9b242a..22550f84 100644 --- a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 @@ -451,9 +451,6 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy */ void DoUnwaitedTicksWork() override { - // - // Decision ... - mDecisionCycleHelper.Update(); } /** @@ -814,6 +811,12 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy x121Inputs.xvwapInputs.showVWapMedium = showAll || true; x121Inputs.xvwapInputs.showVWapSlow = showAll || true; + // + // X3MA ... + x121Inputs.x3maInputs.showX3MaFast = showAll || true; + x121Inputs.x3maInputs.showX3MaMid = showAll || true; + x121Inputs.x3maInputs.showX3MaSlow = showAll || true; + // // Initialize Cycle Helpers ...