From 317e8b8ba34fe3f0a8084efaeffb4c5e777c9a5a Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Sun, 8 Dec 2024 14:13:30 +0330 Subject: [PATCH] last works ... --- Libraries/x-saherelm.common.lib.mq5 | 26 ++ .../x-121.smc.market.cycle.helper.class.mq5 | 279 ++++++++++++++++++ .../x-121.smc.test.strategy.class.mq5 | 48 +++ 3 files changed, 353 insertions(+) diff --git a/Libraries/x-saherelm.common.lib.mq5 b/Libraries/x-saherelm.common.lib.mq5 index d02ed8f9..7104eba7 100644 --- a/Libraries/x-saherelm.common.lib.mq5 +++ b/Libraries/x-saherelm.common.lib.mq5 @@ -307,6 +307,32 @@ struct XTick return result; } + /** + * Init XTick for Specified Time ... + * + * @param _symbol: String, Symbol Representation ... + * @param _time: Datetime, Specified Time ... + * + * @return ( bool ) + */ + bool Init( + string _symbol, + datetime _time // + ) + { + // + bool result = false; + + // + // TODO: Complete this ... + + // + result = IsValid(); + + // + return result; + } + /** * Cleanup ... */ 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 60bce4dd..ca1379a9 100644 --- a/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 @@ -330,6 +330,285 @@ class XC121SMCCycleHelper : public XCBase return result; } + // + // Tools ... + + /** + * Detect Nearest Supply/Demand Zones ... + * + * @param bar: XOHCL instance, Start Bar ... + * + * @return ( bool ) + */ + bool DetectValisSupplyZone( + XOHCL &bar, + XCSupplyZone *&supplyZone, + XCDemandZone *&demandZone // + ) + { + // + bool result = false; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + int index = bar.Index(); + + // + double bid = GetBid(bar.symbol); + + // + // Retrieve X121 Cnditions ... + int conditionsLoopback = 10; + X121Conditions x121Conditions; + result = mX121Helper.GetConditions( + x121Conditions, + index, + conditionsLoopback // + ); + if (!result) + { + return result; + } + int validPeaksCount = ArraySize(x121Conditions.validPeaksBuffer); + int validValesCount = ArraySize(x121Conditions.validValesBuffer); + + // + XPOIState state; + ENUM_XPOI_EVENTS events[]; + mPOIDetector.Update(events); + mPOIDetector.GetState(state); + result = state.IsValid() && + state.HasChild(); + if (!result) + { + return result; + } + + // + // Supply Zones ... + XCSupplyZone *supplies[]; + int suppliesCount = state.CountSupplyZones(); + + // + // Select Bar Validated Supply Zones ... + if (IsValidSize(suppliesCount)) + { + // + for (int i = 0; i < suppliesCount; i++) + { + // + XCSupplyZone *iZone = state.supplyZones[i]; + + // + // Check Zone is Valid For Bar ... + bool isValid = bar.high < iZone.Lower(); + if (isValid) + { + // + Add( + iZone, + supplies // + ); + } + } + } + suppliesCount = ArraySize(supplies); + + // + // Select Valid Peaks Filtered Supplies ... + if (IsValidSize(suppliesCount)) + { + // + // Check Valid Peaks ... + XCSupplyZone *tmp[]; + if (IsValidSize(validPeaksCount)) + { + // + for (int i = 0; i < suppliesCount; i++) + { + // + XCSupplyZone *iZone = supplies[i]; + + // + for (int j = 0; j < validPeaksCount; j++) + { + // + double value = x121Conditions.validPeaksBuffer[j]; + + // + // Check Valid Peaks in Zone ... + bool isZoneContainsValidValue = + value >= iZone.Lower() && + value <= iZone.Upper(); + if (isZoneContainsValidValue) + { + // + Add( + iZone, + tmp // + ); + } + } + } + } + + // + Clean(supplies); + Copy( + tmp, + supplies // + ); + } + suppliesCount = ArraySize(supplies); + + // + // Select Nearest Supply Zone ... + if (IsValidSize(suppliesCount)) + { + // + // Check Nearest Supplies ... + for (int i = 0; i < suppliesCount; i++) + { + // + XCSupplyZone *iZone = supplies[i]; + if (supplyZone == NULL) + { + supplyZone = iZone; + } + else + { + // + bool canChange = + iZone.Lower() < supplyZone.Lower(); + if (canChange) + { + supplyZone = iZone; + } + } + } + } + + // + // Demand Zones ... + XCDemandZone *demands[]; + int demandsCount = state.CountDemandZones(); + + // + // Select Bar Validated Demand Zones ... + if (IsValidSize(demandsCount)) + { + // + for (int i = 0; i < demandsCount; i++) + { + // + XCDemandZone *iZone = state.demandZones[i]; + + // + // Check Zone is Valid For Bar ... + bool isValid = bar.low > iZone.Upper(); + if (isValid) + { + // + Add( + iZone, + demands // + ); + } + } + } + demandsCount = ArraySize(demands); + + // + // Select Valid Vales Filtered Demands ... + if (IsValidSize(demandsCount)) + { + // + // Check Valid Vales ... + XCDemandZone *tmp[]; + if (IsValidSize(validValesCount)) + { + // + for (int i = 0; i < demandsCount; i++) + { + // + XCDemandZone *iZone = demands[i]; + + // + for (int j = 0; j < validValesCount; j++) + { + // + double value = x121Conditions.validValesBuffer[j]; + + // + // Check Valid Peaks in Zone ... + bool isZoneContainsValidValue = + value >= iZone.Lower() && + value <= iZone.Upper(); + if (isZoneContainsValidValue) + { + // + Add( + iZone, + tmp // + ); + } + } + } + } + + // + Clean(demands); + Copy( + tmp, + demands // + ); + } + demandsCount = ArraySize(demands); + + // + // Select Nearest Demand Zone ... + if (IsValidSize(demandsCount)) + { + // + // Check Nearest Demands ... + for (int i = 0; i < demandsCount; i++) + { + // + XCDemandZone *iZone = demands[i]; + if (demandZone == NULL) + { + demandZone = iZone; + } + else + { + // + bool canChange = + iZone.Upper() > demandZone.Upper(); + if (canChange) + { + demandZone = iZone; + } + } + } + } + + // + // Validate Founded Zones ... + result = (supplyZone != NULL && + supplyZone.IsValid()) && + (demandZone != NULL && + demandZone.IsValid()); + + // + return result; + } + // // Virtuals ... diff --git a/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 index 38726d5e..184ffd69 100644 --- a/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 @@ -425,6 +425,54 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy } conditions.visionConditions.state = mVisionState; + // + // 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) {