From a64430a28c007979413de2ebd14b9f2164ab9800 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Wed, 11 Dec 2024 02:14:37 +0330 Subject: [PATCH] Add Supports for Consolidation Range Founder ... - [] required to Complete Supply and Demand Zone Retrieve in XConsolidation Zone Struct ... --- Classes/x-saherelm.x-bar.analyser.class.mq5 | 307 +++++-- Documents/BKP/tmp.x121.smc.mq5 | 90 ++ Libraries/x-saherelm.common.lib.mq5 | 113 +++ .../x-121.smc.market.cycle.helper.class.mq5 | 844 +++++++++++++++++- X121SMCEA/Libraries/x-121.smc.lib.mq5 | 3 + .../x-121.smc.test.strategy.class.mq5 | 50 +- 6 files changed, 1256 insertions(+), 151 deletions(-) diff --git a/Classes/x-saherelm.x-bar.analyser.class.mq5 b/Classes/x-saherelm.x-bar.analyser.class.mq5 index 5fbbefd9..24d1f6f8 100644 --- a/Classes/x-saherelm.x-bar.analyser.class.mq5 +++ b/Classes/x-saherelm.x-bar.analyser.class.mq5 @@ -26,6 +26,200 @@ // // Definitions ... +// +// Consolidation Zone ... +struct XConsolidationZone +{ + // + // Props ... + + // + string symbol; // Symbol ... + ENUM_TIMEFRAMES period; // Period ... + + // + double upper; // Upper ... + double lower; // Lower ... + + // + int loopback; // Loopback ... + + // + ENUM_X_DIRECTION breakDirection; // 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 + // + ; + + // + upper = _upper; + lower = _lower; + symbol = _symbol; + period = _period; + loopback = _loopback; + + // + result = IsValid(); + + // + return result; + } + + /** + * Cleanup ... + */ + void Clean() + { + // + symbol = NULL; + period = NULL; + upper = 0; + lower = 0; + loopback = 0; + breakerBar.Clean(); + breakDirection = X_DIRECTION_NONE; + } + + /** + * 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(breakDirection); + + // + return result; + } + + /** + * Detect Supply Zone if Exists ... + * + * @return ( bool ) + */ + bool DetectSupplyZone( + XCSupplyZone *&zone // + ) + { + // + bool result = false; + + // + result = IsBreaked(); + if (!result) + { + return result; + } + + // + // Implment Zone Finding ... + + // + return result; + } + + /** + * Detect Demand Zone if Exists ... + * + * @return ( bool ) + */ + bool DetectDemandZone( + XCDemandZone *&zone // + ) + { + // + bool result = false; + + // + result = IsBreaked(); + if (!result) + { + return result; + } + + // + // Implment Zone Finding ... + + // + return result; + } + + // +}; + // // Implementations ... class XCBarAnalyser : public XCBase @@ -359,91 +553,88 @@ class XCBarAnalyser : public XCBase } /** - * Detect Consolidation Range ... + * Detect Price Consolidation ... * - * @param index: Integer, Start Bar Index ... - * @param range: Integer, Range of Bars ... - * @param maxRange: Consolidation Price Range in Points ... - * @param symbol: String, Symbol ... - * @param period: ENUM_TIMEFRAMES member, Period ... + * @param bar: XOHCL instance Reference, Start Bar ... + * @param loopback: Integer, Consolidation Range Finder ... + * @param upper: Double Reference ... + * @param lower: Double Reference ... + * @param upperAppliedTo: ENUM_APPLIED_PRICE member, Upper Price ... + * @param lowerAppliedTo: ENUM_APPLIED_PRICE member, Lower Price ... * * @return ( bool ) */ - bool IsConsolidating( - int index, - int range, - double maxRange, - string symbol = NULL, - ENUM_TIMEFRAMES period = NULL // + bool IsConsolidate( + XOHCL &bar, + double &upper, + double &lower, + int loopback = 30, + ENUM_APPLIED_PRICE upperAppliedTo = PRICE_HIGH, + ENUM_APPLIED_PRICE lowerAppliedTo = PRICE_LOW // ) { // bool result = false; // - if (index < 0) + upper = 0; + lower = 0; + + // + if (loopback < 7) { - index = 0; + loopback = 7; } // - if (range < 1) + result = bar.IsValid(); + if (!result) { - range = 1; + return result; } // - if (maxRange < 1) - { - maxRange = 1; - } + int consolidationRange = 30; + double points = GetPoints(bar.symbol); + int index = bar.Index(); // - // Normalize ... - symbol = NormalizeSymbol(symbol); - period = NormalizePeriod(period); - - // - // Point Value ... - double point = GetPoints(symbol); - - // - double high = iHigh( - symbol, - period, - index // - ); - double low = iLow( - symbol, - period, - index // + double upperPrice[]; + int upperPriceCount = FillPrice( + upperPrice, + upperAppliedTo, + bar.symbol, + bar.period, + index, + loopback // ); // - // Detect Range High and Low ... - for (int i = 1; i < range; i++) + double lowerPrice[]; + int lowerPriceCount = FillPrice( + lowerPrice, + lowerAppliedTo, + bar.symbol, + bar.period, + index, + loopback // + ); + + // + result = upperPriceCount == lowerPriceCount && + lowerPriceCount == loopback; + if (!result) { - // - double iH = iHigh( - symbol, - period, - index + i // - ); - - // - double iL = iLow( - symbol, - period, - index + i // - ); - - // - high = MathMax(high, iH); - low = MathMin(low, iL); + return result; } // - result = (high - low) <= (maxRange * point); + upper = upperPrice[ArrayMaximum(upperPrice)]; + lower = lowerPrice[ArrayMinimum(lowerPrice)]; + + // + double range = upper - lower; + result = range <= consolidationRange * points; // return result; diff --git a/Documents/BKP/tmp.x121.smc.mq5 b/Documents/BKP/tmp.x121.smc.mq5 index 7cb011d4..97271f4b 100644 --- a/Documents/BKP/tmp.x121.smc.mq5 +++ b/Documents/BKP/tmp.x121.smc.mq5 @@ -2591,3 +2591,93 @@ // // conditions.sl = breakerBar.high; // conditions.sl = conditions.triggerConditions.xchsarConditions.cSars[0]; // } + + +////////////////////////////////////////////////////////////////// + + + // + bool isSamePeaks = + // + conditions.triggerConditions.x121Conditions.peaksBuffer[0] == conditions.decisionConditions.x121Conditions.peaksBuffer[0] && + conditions.decisionConditions.x121Conditions.peaksBuffer[0] == conditions.analyseConditions.x121Conditions.peaksBuffer[0] + // && + // conditions.analyseConditions.x121Conditions.peaksBuffer[0] == conditions.verificationConditions.x121Conditions.peaksBuffer[0] && + // conditions.verificationConditions.x121Conditions.peaksBuffer[0] == conditions.consolidationConditions.x121Conditions.peaksBuffer[0] && + // conditions.consolidationConditions.x121Conditions.peaksBuffer[0] == conditions.visionConditions.x121Conditions.peaksBuffer[0] + // + ; + if (isSamePeaks) { + Print("isSamePeaks"); + } + + // + bool isSameVales = + // + conditions.triggerConditions.x121Conditions.valesBuffer[0] == conditions.decisionConditions.x121Conditions.valesBuffer[0] && + conditions.decisionConditions.x121Conditions.valesBuffer[0] == conditions.analyseConditions.x121Conditions.valesBuffer[0] + // && + // conditions.analyseConditions.x121Conditions.valesBuffer[0] == conditions.verificationConditions.x121Conditions.valesBuffer[0] && + // conditions.verificationConditions.x121Conditions.valesBuffer[0] == conditions.consolidationConditions.x121Conditions.valesBuffer[0] && + // conditions.consolidationConditions.x121Conditions.valesBuffer[0] == conditions.visionConditions.x121Conditions.valesBuffer[0] + // + ; + if (isSameVales) { + Print("isSameVales"); + } + + +////////////////////////////////////////////////////////////////////// + + + // + // Detect Valid Supply and Demand Zones ... + XCSupplyZone *supplyZone; + XCDemandZone *demandZone; + result = mTriggerCycleHelper + .DetectValisSupplyZone( + cBar, + supplyZone, + demandZone // + ); + if (!result) + { + // + conditions.Clean(); + return result; + } + + // + supplyZone.To(cTime); + XCSupplyZoneObject *iSupplyZoneObj; + result = mPOIDrawer.CreateSupplyZone( + supplyZone, + iSupplyZoneObj // + ); + if (!result) + { + // + conditions.Clean(); + return result; + } + + // + demandZone.To(cTime); + XCDemandZoneObject *iDemandZoneObj; + result = mPOIDrawer.CreateDemandZone( + demandZone, + iDemandZoneObj // + ); + if (!result) + { + // + conditions.Clean(); + return result; + } + + // + Print("Supply and Demand Zone Created ..."); + + +////////////////////////////////////////////////////////////////////// + diff --git a/Libraries/x-saherelm.common.lib.mq5 b/Libraries/x-saherelm.common.lib.mq5 index eed1c59a..654860e6 100644 --- a/Libraries/x-saherelm.common.lib.mq5 +++ b/Libraries/x-saherelm.common.lib.mq5 @@ -8486,6 +8486,119 @@ bool DetectMomentumChange( return result; } +// +// Fill Specified Applied Prices ... +int FillPrice( + double &buffer[], + ENUM_APPLIED_PRICE _mAppliedTo = PRICE_CLOSE, + string _mSymbol = NULL, + ENUM_TIMEFRAMES _mPeriod = NULL, + int _mStart = 0, + int _mLoopback = 10 // +) +{ + // + int result = 0; + + // + if (_mStart < 0) + { + _mStart = 0; + } + + // + if (_mLoopback < 7) + { + _mLoopback = 7; + } + + // + _mSymbol = NormalizeSymbol(_mSymbol); + _mPeriod = NormalizePeriod(_mPeriod); + + // + Clean(buffer); + ArraySetAsSeries(buffer, true); + + // + double open[]; + result = CopyOpen( + _mSymbol, + _mPeriod, + _mStart, + _mLoopback, + open // + ); + if (!IsValidSize(result)) { + return result; + } + + // + double high[]; + result = CopyHigh( + _mSymbol, + _mPeriod, + _mStart, + _mLoopback, + high // + ); + if (!IsValidSize(result)) { + return result; + } + + // + double low[]; + result = CopyLow( + _mSymbol, + _mPeriod, + _mStart, + _mLoopback, + low // + ); + if (!IsValidSize(result)) { + return result; + } + + // + double close[]; + result = CopyClose( + _mSymbol, + _mPeriod, + _mStart, + _mLoopback, + close // + ); + if (!IsValidSize(result)) { + return result; + } + + // + for (int i = 0; i < result; i++) + { + // + double iPrice = GetAppliedPrice( + _mAppliedTo, + open, + high, + low, + close, + i // + ); + + // + Add( + iPrice, + buffer // + ); + } + + // + result = ArraySize(buffer); + + // + return result; +} + // // Symbols ... 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 a436787a..faca769a 100644 --- a/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 @@ -90,6 +90,33 @@ class XC121SMCCycleHelper : public XCBase mMaxAllowedSavedChanges = value; } + /** + * Get Consolidation Loopback Length ... + * + * @return ( int ) + */ + int ConsolidationLoopback() + { + return mConsolidationLoopback; + } + + /** + * Set Consolidation Loopback Length ... + * + * @param value: Integer ... + */ + void ConsolidationLoopback(int value) + { + // + if (value < 7) + { + value = 7; + } + + // + mConsolidationLoopback = value; + } + // // Actions ... @@ -655,6 +682,231 @@ class XC121SMCCycleHelper : public XCBase return result; } + // + // Change Values Actions ... + + /** + * Count Saved Parabolic Sar Changes ... + * + * @return ( int ) + */ + int CountSarChanges() + { + return ArraySize(mSarChanges); + } + + /** + * Fill Saved Sar Changes ... + * + * @param changes: XValueChange instance Array Reference ... + * + * @return ( int ) + */ + int FillSarChanges( + XValueChange &changes[] // + ) + { + // + Clean(changes); + + // + Copy( + mSarChanges, + changes // + ); + + // + int result = ArraySize(changes); + + // + return result; + } + + /** + * Count Saved Peaks Changes ... + * + * @return ( int ) + */ + int CountPeaksChanges() + { + return ArraySize(mPeaksChanges); + } + + /** + * Fill Saved Peaks Changes ... + * + * @param changes: XValueChange instance Array Reference ... + * + * @return ( int ) + */ + int FillPeaksChanges( + XValueChange &changes[] // + ) + { + // + Clean(changes); + + // + Copy( + mPeaksChanges, + changes // + ); + + // + int result = ArraySize(changes); + + // + return result; + } + + /** + * Count Saved Vales Changes ... + * + * @return ( int ) + */ + int CountValesChanges() + { + return ArraySize(mValesChanges); + } + + /** + * Fill Saved Vales Changes ... + * + * @param changes: XValueChange instance Array Reference ... + * + * @return ( int ) + */ + int FillValesChanges( + XValueChange &changes[] // + ) + { + // + Clean(changes); + + // + Copy( + mValesChanges, + changes // + ); + + // + int result = ArraySize(changes); + + // + return result; + } + + /** + * Count Saved VWap Order Changes ... + * + * @return ( int ) + */ + int CountVWapOrderChanges() + { + return ArraySize(mVWapOrderChanges); + } + + /** + * Fill Saved VWap Order Changes ... + * + * @param changes: XValueChange instance Array Reference ... + * + * @return ( int ) + */ + int FillVWapOrderChanges( + XValueChange &changes[] // + ) + { + // + Clean(changes); + + // + Copy( + mVWapOrderChanges, + changes // + ); + + // + int result = ArraySize(changes); + + // + return result; + } + + /** + * Count Saved VWap State Changes ... + * + * @return ( int ) + */ + int CountVWapStateChanges() + { + return ArraySize(mVWapStateChanges); + } + + /** + * Fill Saved VWap State Changes ... + * + * @param changes: XValueChange instance Array Reference ... + * + * @return ( int ) + */ + int FillVWapStateChanges( + XValueChange &changes[] // + ) + { + // + Clean(changes); + + // + Copy( + mVWapStateChanges, + changes // + ); + + // + int result = ArraySize(changes); + + // + return result; + } + + /** + * Count Founded Consolidation Zones ... + * + * @return ( int ) + */ + int CountConsolidationZones() + { + return ArraySize(mConsolidationZones); + } + + /** + * Fill Broken Consolidations ... + * + * @param consolidations: XConsolidationZone instance Array Reference ... + * + * @return ( int ) + */ + int FillConsolidations( + XConsolidationZone &consolidations[] // + ) + { + // + Clean(consolidations); + + // + Copy( + mConsolidationZones, + consolidations // + ); + + // + int result = ArraySize(consolidations); + + // + return result; + } + // // Virtuals ... @@ -664,6 +916,7 @@ class XC121SMCCycleHelper : public XCBase virtual void Default() { // + ConsolidationLoopback(15); MaxAllowedSavedChanges(50); } @@ -709,48 +962,358 @@ class XC121SMCCycleHelper : public XCBase isSarSwitchedToBearish; // - if (period == PERIOD_M1) + if (isSarChanged) { // - if (isSarChanged) + XValueChange sarChanged; + + // + datetime time = changeBar.time; + double after = conditions.x121Conditions.sarBuffer[1]; + double before = conditions.x121Conditions.sarBuffer[2]; + ENUM_X_DIRECTION dir = + isSarSwitchedToBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + // Initialize Model ... + isInited = sarChanged.Init( + before, + after, + dir, + time // + ); + if (isInited) { - // - XValueChange sarChanged; - - // - datetime time = changeBar.time; - double after = conditions.x121Conditions.sarBuffer[1]; - double before = conditions.x121Conditions.sarBuffer[2]; - ENUM_X_DIRECTION dir = - isSarSwitchedToBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - // Initialize Model ... - isInited = sarChanged.Init( - before, - after, - dir, - time // - ); - if (isInited) - { - // - isInited = AddSarChange(sarChanged); - if (isInited) - { - Print("Sar Switched ..."); - } - } + isInited = AddSarChange(sarChanged); } } // - // Detect Peak Changes ... + // Detect Peaks Changes ... // - // Detect Vale Changes ... + bool isNewPeak = conditions.x121Conditions.isNewPeak; + bool isNewPeakOverLast = conditions.x121Conditions.isNewPeakOverLast; + bool isNewPeakUnderLast = conditions.x121Conditions.isNewPeakUnderLast; + + // + if (isNewPeak) + { + // + XValueChange peaksChanged; + + // + datetime time = changeBar.time; + double after = conditions.x121Conditions.peaksBuffer[1]; + double before = conditions.x121Conditions.peaksBuffer[2]; + ENUM_X_DIRECTION dir = + isNewPeakOverLast + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + // Initialize Model ... + isInited = peaksChanged.Init( + before, + after, + dir, + time // + ); + if (isInited) + { + isInited = AddPeaksChange(peaksChanged); + } + } + + // + // Detect Vales Changes ... + + // + bool isNewVale = conditions.x121Conditions.isNewVale; + bool isNewValeOverLast = conditions.x121Conditions.isNewValeOverLast; + bool isNewValeUnderLast = conditions.x121Conditions.isNewValeUnderLast; + + // + if (isNewVale) + { + // + XValueChange valesChanged; + + // + datetime time = changeBar.time; + double after = conditions.x121Conditions.valesBuffer[1]; + double before = conditions.x121Conditions.valesBuffer[2]; + ENUM_X_DIRECTION dir = + isNewValeUnderLast + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + // Initialize Model ... + isInited = valesChanged.Init( + before, + after, + dir, + time // + ); + if (isInited) + { + isInited = AddValesChange(valesChanged); + } + } + + // + // VWap Direction Change ... + + // + // Ordered Change ... + bool isVWapSwitchedToBullishOrdered = + conditions.x121Conditions.isVWapSwitchedToBullishOrdered; + bool isVWapSwitchedToBearishOrdered = + conditions.x121Conditions.isVWapSwitchedToBearishOrdered; + bool isVWAPOrderedChanged = isVWapSwitchedToBullishOrdered || + isVWapSwitchedToBearishOrdered; + // + if (isVWAPOrderedChanged) + { + // + XValueChange vwapOrderChanged; + + // + datetime time = changeBar.time; + ENUM_X_DIRECTION dir = + isVWapSwitchedToBullishOrdered + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + double after = 0; + double before = 0; + if (isVWapSwitchedToBullishOrdered) + { + // + // After Max ... + after = MathMax( + conditions.x121Conditions.vwapFastBuffer[1], + conditions.x121Conditions.vwapMidBuffer[1] // + ); + after = MathMax( + after, + conditions.x121Conditions.vwapSlowBuffer[1] // + ); + + // + // Before Min ... + before = MathMin( + conditions.x121Conditions.vwapFastBuffer[1], + conditions.x121Conditions.vwapMidBuffer[1] // + ); + before = MathMin( + before, + conditions.x121Conditions.vwapSlowBuffer[1] // + ); + } + else + { + // + // After Min ... + after = MathMin( + conditions.x121Conditions.vwapFastBuffer[1], + conditions.x121Conditions.vwapMidBuffer[1] // + ); + after = MathMin( + after, + conditions.x121Conditions.vwapSlowBuffer[1] // + ); + + // + // Before Max ... + before = MathMax( + conditions.x121Conditions.vwapFastBuffer[1], + conditions.x121Conditions.vwapMidBuffer[1] // + ); + before = MathMax( + before, + conditions.x121Conditions.vwapSlowBuffer[1] // + ); + } + + // + // Initialize Model ... + isInited = vwapOrderChanged.Init( + before, + after, + dir, + time // + ); + if (isInited) + { + isInited = AddVWapOrderChange(vwapOrderChanged); + } + } + + // + // States Changed ... + bool isVWapSwitchedToBullishState = + conditions.x121Conditions.isVWapSwitchedToBullishState; + bool isVWapSwitchedToBearishState = + conditions.x121Conditions.isVWapSwitchedToBearishState; + bool isVWapStatesChanged = isVWapSwitchedToBullishState || + isVWapSwitchedToBearishState; + + // + if (isVWapStatesChanged) + { + // + XValueChange vwapStateChanged; + + // + datetime time = changeBar.time; + ENUM_X_DIRECTION dir = + isVWapSwitchedToBullishState + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + double after = 0; + double before = 0; + if (isVWapSwitchedToBullishState) + { + // + // After Max ... + after = MathMax( + conditions.x121Conditions.vwapFastBuffer[1], + conditions.x121Conditions.vwapMidBuffer[1] // + ); + after = MathMax( + after, + conditions.x121Conditions.vwapSlowBuffer[1] // + ); + + // + // Before Min ... + before = MathMin( + conditions.x121Conditions.vwapFastBuffer[1], + conditions.x121Conditions.vwapMidBuffer[1] // + ); + before = MathMin( + before, + conditions.x121Conditions.vwapSlowBuffer[1] // + ); + } + else + { + // + // After Min ... + after = MathMin( + conditions.x121Conditions.vwapFastBuffer[1], + conditions.x121Conditions.vwapMidBuffer[1] // + ); + after = MathMin( + after, + conditions.x121Conditions.vwapSlowBuffer[1] // + ); + + // + // Before Max ... + before = MathMax( + conditions.x121Conditions.vwapFastBuffer[1], + conditions.x121Conditions.vwapMidBuffer[1] // + ); + before = MathMax( + before, + conditions.x121Conditions.vwapSlowBuffer[1] // + ); + } + + // + // Initialize Model ... + isInited = vwapStateChanged.Init( + before, + after, + dir, + time // + ); + if (isInited) + { + isInited = AddVWapStateChange(vwapStateChanged); + } + } + + // + // Detect Consolidations ... + + // + int consolidationLoopback = ConsolidationLoopback(); + if (IsValidSize(consolidationLoopback)) + { + // + double upper = 0; + double lower = 0; + bool hasConsolidation = + mBarAnalyser.IsConsolidate( + changeBar, + upper, + lower, + consolidationLoopback // + ); + + // + if (hasConsolidation && + !mActioveConsolidationZone.IsValid()) + { + // + // Initialize Consolidation Zone ... + bool isInited = mActioveConsolidationZone.Init( + changeBar.symbol, + changeBar.period, + upper, + lower, + consolidationLoopback // + ); + } + + // + if (!hasConsolidation && + mActioveConsolidationZone.IsValid()) + { + // + // Check Consolidation Breaks ... + // Update Zone ... + // Add it ... + bool isBOSTop = changeBar.high > mActioveConsolidationZone.upper; + bool isBOSBottom = changeBar.low < mActioveConsolidationZone.lower; + + // + // Calculate Break Direction ... + ENUM_X_DIRECTION bosDir = isBOSTop + ? X_DIRECTION_BULLISH + : isBOSBottom + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + + // + // Update Actiove Zone ... + mActioveConsolidationZone.breakerBar = changeBar; + mActioveConsolidationZone.breakDirection = bosDir; + + // + // Add Active to List ... + AddRef( + mActioveConsolidationZone, + mConsolidationZones // + ); + + // + // Clean Active Zone ... + mActioveConsolidationZone.Clean(); + + // + Print("Breake ..."); + } + } } // @@ -761,8 +1324,17 @@ class XC121SMCCycleHelper : public XCBase // // Change Holders ... - int mMaxAllowedSavedChanges; // Max llowed Changes to Save ... - XValueChange mSarChanges[]; // Holds Parabolic Sar Direction Changes ... + int mMaxAllowedSavedChanges; // Max llowed Changes to Save ... + XValueChange mSarChanges[]; // Holds Parabolic Sar Direction Changes ... + XValueChange mPeaksChanges[]; // Holds Peaks Changes ... + XValueChange mValesChanges[]; // Holds Vales Changes ... + XValueChange mVWapOrderChanges[]; // Holds Vales Changes ... + XValueChange mVWapStateChanges[]; // Holds Vales Changes ... + + // + int mConsolidationLoopback; // Consolidation Loopback Length ... + XConsolidationZone mConsolidationZones[]; // Holds Consolidation Zones ... + XConsolidationZone mActioveConsolidationZone; // Holds Actiove Consolidation Zone ... // // Actions ... @@ -870,16 +1442,6 @@ class XC121SMCCycleHelper : public XCBase // // Change Values Actions ... - /** - * Count Saved Parabolic Sar Changes ... - * - * @return ( int ) - */ - int CountSarChanges() - { - return ArraySize(mSarChanges); - } - /** * Add Specified Parabolic Sar Changed Item ... * @@ -928,5 +1490,197 @@ class XC121SMCCycleHelper : public XCBase return result; } + /** + * Add Specified Peaks Changed Item ... + * + * @param value: XValueChange instance Reference ... + * + * @return ( bool ) + */ + bool AddPeaksChange(XValueChange &value) + { + // + bool result = false; + + // + result = value.IsValid(); + if (!result) + { + return result; + } + + // + int beforeCount = CountSarChanges(); + + // + AddIfNotExists( + value, + mPeaksChanges // + ); + + // + int afterCount = CountSarChanges(); + + // + result = afterCount == beforeCount + 1; + if (result) + { + // + // Cleaning Up Unused Items ... + int maxAllowed = MaxAllowedSavedChanges(); + CleanupArray( + mPeaksChanges, + maxAllowed // + ); + } + + // + return result; + } + + /** + * Add Specified Vales Changed Item ... + * + * @param value: XValueChange instance Reference ... + * + * @return ( bool ) + */ + bool AddValesChange(XValueChange &value) + { + // + bool result = false; + + // + result = value.IsValid(); + if (!result) + { + return result; + } + + // + int beforeCount = CountSarChanges(); + + // + AddIfNotExists( + value, + mValesChanges // + ); + + // + int afterCount = CountSarChanges(); + + // + result = afterCount == beforeCount + 1; + if (result) + { + // + // Cleaning Up Unused Items ... + int maxAllowed = MaxAllowedSavedChanges(); + CleanupArray( + mValesChanges, + maxAllowed // + ); + } + + // + return result; + } + + /** + * Add Specified VWap Order Changed Item ... + * + * @param value: XValueChange instance Reference ... + * + * @return ( bool ) + */ + bool AddVWapOrderChange(XValueChange &value) + { + // + bool result = false; + + // + result = value.IsValid(); + if (!result) + { + return result; + } + + // + int beforeCount = CountSarChanges(); + + // + AddIfNotExists( + value, + mVWapOrderChanges // + ); + + // + int afterCount = CountSarChanges(); + + // + result = afterCount == beforeCount + 1; + if (result) + { + // + // Cleaning Up Unused Items ... + int maxAllowed = MaxAllowedSavedChanges(); + CleanupArray( + mVWapOrderChanges, + maxAllowed // + ); + } + + // + return result; + } + + /** + * Add Specified VWap State Changed Item ... + * + * @param value: XValueChange instance Reference ... + * + * @return ( bool ) + */ + bool AddVWapStateChange(XValueChange &value) + { + // + bool result = false; + + // + result = value.IsValid(); + if (!result) + { + return result; + } + + // + int beforeCount = CountSarChanges(); + + // + AddIfNotExists( + value, + mVWapStateChanges // + ); + + // + int afterCount = CountSarChanges(); + + // + result = afterCount == beforeCount + 1; + if (result) + { + // + // Cleaning Up Unused Items ... + int maxAllowed = MaxAllowedSavedChanges(); + CleanupArray( + mVWapStateChanges, + maxAllowed // + ); + } + + // + return result; + } + // }; diff --git a/X121SMCEA/Libraries/x-121.smc.lib.mq5 b/X121SMCEA/Libraries/x-121.smc.lib.mq5 index 4ff53480..79346722 100644 --- a/X121SMCEA/Libraries/x-121.smc.lib.mq5 +++ b/X121SMCEA/Libraries/x-121.smc.lib.mq5 @@ -637,6 +637,9 @@ struct X121SMCStrategyConditions string provider; ENUM_X_DIRECTION marketStructureDir; + // + + // void X121SMCStrategyConditions() { diff --git a/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 index 4de82a5b..b65bfa23 100644 --- a/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 @@ -115,10 +115,12 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy // Start Calculations ... // + // Retrieve Common Data ... string symbol = GetSymbol(); ENUM_TIMEFRAMES period = GetPeriod(); // + // Required Value For SL/TP Calculations ... double points = GetPoints(symbol); double pip = GetPipPrice(symbol); double pip2 = 2 * pip; @@ -466,54 +468,6 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy double bid = GetBid(symbol); datetime cTime = TimeCurrent(); - // // - // // Detect Valid Supply and Demand Zones ... - // XCSupplyZone *supplyZone; - // XCDemandZone *demandZone; - // result = mTriggerCycleHelper - // .DetectValisSupplyZone( - // cBar, - // supplyZone, - // demandZone // - // ); - // if (!result) - // { - // // - // conditions.Clean(); - // return result; - // } - - // // - // supplyZone.To(cTime); - // XCSupplyZoneObject *iSupplyZoneObj; - // result = mPOIDrawer.CreateSupplyZone( - // supplyZone, - // iSupplyZoneObj // - // ); - // if (!result) - // { - // // - // conditions.Clean(); - // return result; - // } - - // // - // demandZone.To(cTime); - // XCDemandZoneObject *iDemandZoneObj; - // result = mPOIDrawer.CreateDemandZone( - // demandZone, - // iDemandZoneObj // - // ); - // if (!result) - // { - // // - // conditions.Clean(); - // return result; - // } - - // // - // Print("Supply and Demand Zone Created ..."); - // if (!result) {