From db5144b1ef025b47a51f624f54dc69109f2e1f26 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Wed, 11 Dec 2024 04:58:55 +0330 Subject: [PATCH] Last ... --- Classes/x-saherelm.x-bar.analyser.class.mq5 | 194 ------------- Libraries/x-saherelm.x-poi.lib.mq5 | 261 ++++++++++++++++++ .../x-121.smc.market.cycle.helper.class.mq5 | 2 +- .../x-121.smc.test.strategy.class.mq5 | 105 +++++++ 4 files changed, 367 insertions(+), 195 deletions(-) diff --git a/Classes/x-saherelm.x-bar.analyser.class.mq5 b/Classes/x-saherelm.x-bar.analyser.class.mq5 index 24d1f6f8..5a138486 100644 --- a/Classes/x-saherelm.x-bar.analyser.class.mq5 +++ b/Classes/x-saherelm.x-bar.analyser.class.mq5 @@ -26,200 +26,6 @@ // // 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 diff --git a/Libraries/x-saherelm.x-poi.lib.mq5 b/Libraries/x-saherelm.x-poi.lib.mq5 index aaae41a3..ba5e2c2e 100644 --- a/Libraries/x-saherelm.x-poi.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.lib.mq5 @@ -3667,6 +3667,267 @@ struct XPOIState // }; + +// +// 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 HasSupplyZone( + XCSupplyZone *&zone // + ) + { + // + bool result = false; + + // + result = IsBreaked() && + breakDirection == 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() && + breakDirection == 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; + } + + // +}; + // // Extensions ... 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 faca769a..09caf424 100644 --- a/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 @@ -887,7 +887,7 @@ class XC121SMCCycleHelper : public XCBase * * @return ( int ) */ - int FillConsolidations( + int FillConsolidationZones( XConsolidationZone &consolidations[] // ) { diff --git a/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 index b65bfa23..9ae5bc40 100644 --- a/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 @@ -468,6 +468,111 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy double bid = GetBid(symbol); datetime cTime = TimeCurrent(); + // + int consolidationsCount = mTriggerCycleHelper.CountConsolidationZones(); + result = IsValidSize(consolidationsCount); + if (!result) + { + // + conditions.Clean(); + return result; + } + XConsolidationZone consolidations[]; + mTriggerCycleHelper.FillConsolidationZones(consolidations); + + // + // Detect Bid inside Of Zones ... + bool hasSupply = false; + bool hasDemand = false; + XCSupplyZone *supplyZone; + XCDemandZone *demandZone; + bool isBidInsideZone = false; + XConsolidationZone bidContainsConsolidationZone; + for (int i = consolidationsCount - 1; i >= 0; i--) + { + // + XConsolidationZone iZone = consolidations[i]; + + // + // Check Supply or Demand Zone ... + hasSupply = iZone.HasSupplyZone(supplyZone); + hasDemand = iZone.HasDemandZone(demandZone); + + // + result = hasSupply || + hasDemand; + if (!result) + { + continue; + } + + // + // Check Bid inside Zone ... + if (hasSupply) + { + // + result = bid < supplyZone.Upper() && + bid > supplyZone.Lower(); + } + else + { + // + result = bid < demandZone.Upper() && + bid > demandZone.Lower(); + } + + // + if (result) + { + break; + } + } + if (!result) + { + // + conditions.Clean(); + return result; + } + + // + if (hasSupply) + { + // + supplyZone.To(cTime); + XCSupplyZoneObject *iSupplyZoneObj; + result = mPOIDrawer.CreateSupplyZone( + supplyZone, + iSupplyZoneObj // + ); + if (!result) + { + // + conditions.Clean(); + return result; + } + } + + // + if (hasDemand) + { + // + demandZone.To(cTime); + XCDemandZoneObject *iDemandZoneObj; + result = mPOIDrawer.CreateDemandZone( + demandZone, + iDemandZoneObj // + ); + if (!result) + { + // + conditions.Clean(); + return result; + } + } + + // + Print("BID Inside Zone ..."); + // if (!result) {