From c92f2570c70a535265001957b1c92602dbbd40d0 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Sun, 29 Dec 2024 17:46:35 +0330 Subject: [PATCH] last ... --- Classes/x-saherelm.x-poi.drawer.class.mq5 | 61 ++ .../BKP/5}/x-121.smc.xoepv.signal.lib.mq5 | 0 .../BKP/5}/x-121.smc.xpvdp.signal.lib.mq5 | 0 .../BKP/5}/x-121.smc.xpvob.signal.lib.mq5 | 0 .../BKP/5}/x-121.smc.xpvsupdem.signal.lib.mq5 | 0 .../BKP/5}/x-121.smc.xvwpb.signal.lib.mq5 | 0 Libraries/x-saherelm.x-poi.lib.mq5 | 334 +++++++ .../Classes/x-121.smc.base.strategy.class.mq5 | 67 +- .../x-121.smc.x-tradehandler.class.mq5 | 34 + X121SMCEA/Experts/x-121.smc.expert.class.mq5 | 23 + .../Signals/x-121.smc.xtwpv.signal.lib.mq5 | 468 +++++++++- .../Strategy/x-121.smc.strategy.class.mq5 | 821 +----------------- 12 files changed, 944 insertions(+), 864 deletions(-) rename {X121SMCEA/Signals => Documents/BKP/5}/x-121.smc.xoepv.signal.lib.mq5 (100%) rename {X121SMCEA/Signals => Documents/BKP/5}/x-121.smc.xpvdp.signal.lib.mq5 (100%) rename {X121SMCEA/Signals => Documents/BKP/5}/x-121.smc.xpvob.signal.lib.mq5 (100%) rename {X121SMCEA/Signals => Documents/BKP/5}/x-121.smc.xpvsupdem.signal.lib.mq5 (100%) rename {X121SMCEA/Signals => Documents/BKP/5}/x-121.smc.xvwpb.signal.lib.mq5 (100%) diff --git a/Classes/x-saherelm.x-poi.drawer.class.mq5 b/Classes/x-saherelm.x-poi.drawer.class.mq5 index 81d4f748..e31cbb2d 100644 --- a/Classes/x-saherelm.x-poi.drawer.class.mq5 +++ b/Classes/x-saherelm.x-poi.drawer.class.mq5 @@ -2513,6 +2513,67 @@ class XCPOIDrawer : public XCBase return result; } + /** + * Draw Specified Signal ... + * + * @param signal: XSignal instance ... + */ + bool DrawSignal( + XSignal &signal, + XCSignalObject *&object // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = signal.IsValid(); + if (!result) + { + return result; + } + + // + string name = signal.GetTag(); + object = new XCSignalObject(); + result = object.Create( + ChartIdentification(), + name, + SubWindowIdentification(), + signal // + ); + if (!result) + { + return result; + } + + // + object.TPWidth(1); + object.TPColor(clrGreen); + object.TPWidth(STYLE_DOT); + + // + object.SLWidth(1); + object.SLColor(clrRed); + object.SLWidth(STYLE_DOT); + + // + object.TargetWidth(1); + object.TargetColor(clrLightBlue); + object.TargetWidth(STYLE_DOT); + + // + object.EntryWidth(1); + object.EntryColor(clrYellow); + object.EntryWidth(STYLE_DOT); + + // + return result; + } + /** * Draw Specified POI State ... * diff --git a/X121SMCEA/Signals/x-121.smc.xoepv.signal.lib.mq5 b/Documents/BKP/5/x-121.smc.xoepv.signal.lib.mq5 similarity index 100% rename from X121SMCEA/Signals/x-121.smc.xoepv.signal.lib.mq5 rename to Documents/BKP/5/x-121.smc.xoepv.signal.lib.mq5 diff --git a/X121SMCEA/Signals/x-121.smc.xpvdp.signal.lib.mq5 b/Documents/BKP/5/x-121.smc.xpvdp.signal.lib.mq5 similarity index 100% rename from X121SMCEA/Signals/x-121.smc.xpvdp.signal.lib.mq5 rename to Documents/BKP/5/x-121.smc.xpvdp.signal.lib.mq5 diff --git a/X121SMCEA/Signals/x-121.smc.xpvob.signal.lib.mq5 b/Documents/BKP/5/x-121.smc.xpvob.signal.lib.mq5 similarity index 100% rename from X121SMCEA/Signals/x-121.smc.xpvob.signal.lib.mq5 rename to Documents/BKP/5/x-121.smc.xpvob.signal.lib.mq5 diff --git a/X121SMCEA/Signals/x-121.smc.xpvsupdem.signal.lib.mq5 b/Documents/BKP/5/x-121.smc.xpvsupdem.signal.lib.mq5 similarity index 100% rename from X121SMCEA/Signals/x-121.smc.xpvsupdem.signal.lib.mq5 rename to Documents/BKP/5/x-121.smc.xpvsupdem.signal.lib.mq5 diff --git a/X121SMCEA/Signals/x-121.smc.xvwpb.signal.lib.mq5 b/Documents/BKP/5/x-121.smc.xvwpb.signal.lib.mq5 similarity index 100% rename from X121SMCEA/Signals/x-121.smc.xvwpb.signal.lib.mq5 rename to Documents/BKP/5/x-121.smc.xvwpb.signal.lib.mq5 diff --git a/Libraries/x-saherelm.x-poi.lib.mq5 b/Libraries/x-saherelm.x-poi.lib.mq5 index 02ce5323..ce3ef48c 100644 --- a/Libraries/x-saherelm.x-poi.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.lib.mq5 @@ -6101,6 +6101,340 @@ void DetectPivotPOIs( } } +/** + * Detect Price Inside Zones ... + * + * @param state: XPOIState instance Reference ... + * @param bar: XOHCL instance Reference ... + * @param hasSupport: Boolean ... + * @param hasResistanceZone: Boolean ... + * @param hasSupplyZone: Boolean ... + * @param hasDemandZone: Boolean ... + * @param hasOrderBlock: Boolean ... + * @param hasFairValueGap: Boolean ... + * @return ( bool ) + */ +bool DetectPriceInsideZones( + XPOIState &state, + XOHCL &bar, + int &zonesCount, + bool &hasSupportZone, + XCSupportZone *&supportZone, + bool &hasResistanceZone, + XCResistanceZone *&resistanceZone, + bool &hasSupplyZone, + XCSupplyZone *&supplyZone, + bool &hasDemandZone, + XCDemandZone *&demandZone, + bool &hasOrderBlock, + XCOrderBlock *&orderBlock, + bool &hasFairValueGap, + XCFVG *&fairValueGap // +) +{ + // + bool result = false; + + // + zonesCount = 0; + + // + hasSupportZone = false; + hasResistanceZone = false; + hasSupplyZone = false; + hasDemandZone = false; + hasOrderBlock = false; + hasFairValueGap = false; + + // + supportZone = NULL; + resistanceZone = NULL; + supplyZone = NULL; + demandZone = NULL; + orderBlock = NULL; + fairValueGap = NULL; + + // + datetime cTime = TimeCurrent(); + + // + result = bar.IsValid() && + state.IsValid() && + state.HasChild(); + if (!result) + { + return result; + } + + // + int count = 0; + + // + // Support Zone ... + count = state.CountSupportZones(); + if (IsValidSize(count)) + { + // + for (int i = count - 1; i >= 0; i--) + { + // + XCSupportZone *iZone = state.supportZones[i]; + + // + bool isValid = IsPriceInsideZone(bar, iZone); + if (isValid) + { + // + supportZone = iZone; + } + } + + // + hasSupportZone = supportZone != NULL && + supportZone.IsValid(); + if (hasSupportZone) + { + // + zonesCount++; + supportZone.To(cTime); + } + } + + // + // Resistance Zone ... + count = state.CountResistanceZones(); + if (IsValidSize(count)) + { + // + for (int i = count - 1; i >= 0; i--) + { + // + XCResistanceZone *iZone = state.resistanceZones[i]; + + // + bool isValid = IsPriceInsideZone(bar, iZone); + if (isValid) + { + // + resistanceZone = iZone; + } + } + + // + hasResistanceZone = resistanceZone != NULL && + resistanceZone.IsValid(); + if (hasResistanceZone) + { + // + zonesCount++; + resistanceZone.To(cTime); + } + } + + // + // Supply Zone ... + count = state.CountSupplyZones(); + if (IsValidSize(count)) + { + // + for (int i = count - 1; i >= 0; i--) + { + // + XCSupplyZone *iZone = state.supplyZones[i]; + + // + bool isValid = IsPriceInsideZone(bar, iZone); + if (isValid) + { + // + supplyZone = iZone; + } + } + + // + hasSupplyZone = supplyZone != NULL && + supplyZone.IsValid(); + if (hasSupplyZone) + { + // + zonesCount++; + supplyZone.To(cTime); + } + } + + // + // Demand Zone ... + count = state.CountDemandZones(); + if (IsValidSize(count)) + { + // + for (int i = count - 1; i >= 0; i--) + { + // + XCDemandZone *iZone = state.demandZones[i]; + + // + bool isValid = IsPriceInsideZone(bar, iZone); + if (isValid) + { + // + demandZone = iZone; + } + } + + // + hasDemandZone = demandZone != NULL && + demandZone.IsValid(); + if (hasDemandZone) + { + // + zonesCount++; + demandZone.To(cTime); + } + } + + // + // OrderBlock ... + count = state.CountBullishOrderBlocks(); + if (IsValidSize(count)) + { + // + for (int i = count - 1; i >= 0; i--) + { + // + XCOrderBlock *iZone = state.bullishOrderBlocks[i]; + + // + bool isValid = IsPriceInsideZone(bar, iZone); + if (isValid) + { + // + orderBlock = iZone; + } + } + + // + hasOrderBlock = orderBlock != NULL && + orderBlock.IsValid(); + if (hasOrderBlock) + { + // + zonesCount++; + orderBlock.To(cTime); + } + } + if (!hasOrderBlock) + { + // + count = state.CountBearishOrderBlocks(); + if (IsValidSize(count)) + { + // + for (int i = count - 1; i >= 0; i--) + { + // + XCOrderBlock *iZone = state.bearishOrderBlocks[i]; + + // + bool isValid = IsPriceInsideZone(bar, iZone); + if (isValid) + { + // + orderBlock = iZone; + } + } + + // + hasOrderBlock = orderBlock != NULL && + orderBlock.IsValid(); + if (hasOrderBlock) + { + // + zonesCount++; + orderBlock.To(cTime); + } + } + } + + // + // Fair Value Gap ... + count = state.CountBullishFairValueGaps(); + if (IsValidSize(count)) + { + // + for (int i = count - 1; i >= 0; i--) + { + // + XCFVG *iZone = state.bullishFairValueGaps[i]; + + // + bool isValid = IsPriceInsideZone(bar, iZone); + if (isValid) + { + // + fairValueGap = iZone; + } + } + + // + hasFairValueGap = fairValueGap != NULL && + fairValueGap.IsValid(); + if (hasFairValueGap) + { + // + zonesCount++; + fairValueGap.To(cTime); + } + } + if (!hasFairValueGap) + { + // + count = state.CountBearishFairValueGaps(); + if (IsValidSize(count)) + { + // + for (int i = count - 1; i >= 0; i--) + { + // + XCFVG *iZone = state.bearishFairValueGaps[i]; + + // + bool isValid = IsPriceInsideZone(bar, iZone); + if (isValid) + { + // + fairValueGap = iZone; + } + } + + // + hasFairValueGap = fairValueGap != NULL && + fairValueGap.IsValid(); + if (hasFairValueGap) + { + // + zonesCount++; + fairValueGap.To(cTime); + } + } + } + + // + result = + // + hasSupportZone || + hasResistanceZone || + hasSupplyZone || + hasDemandZone || + hasOrderBlock || + hasFairValueGap + // + ; + + // + return result; +} + /** * Add Value Change instance to Exists Collection if it's not Exists ... * diff --git a/X121SMCEA/Classes/x-121.smc.base.strategy.class.mq5 b/X121SMCEA/Classes/x-121.smc.base.strategy.class.mq5 index f93901e9..83bf2869 100644 --- a/X121SMCEA/Classes/x-121.smc.base.strategy.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.base.strategy.class.mq5 @@ -89,6 +89,13 @@ class XCX121SMCBaseStrategy : public XCBaseAlert return mPeriod; } + /** + * Retrieve POI Drawer Instance Pointer ... + **/ + XCPOIDrawer* GetDrawer() { + return mPOIDrawer; + } + /** * Check Strategy is Disabled or not ... * @@ -727,66 +734,6 @@ class XCX121SMCBaseStrategy : public XCBaseAlert // // Draw Functions ... - /** - * Draw Specified Signal ... - * - * @param signal: XSignal instance ... - */ - void DrawSignal(XSignal &signal) - { - // - if (!signal.IsValid()) - { - return; - } - - // - // DrawConditions(conditions); - - // - string name = signal.GetTag(); - RemoveObject(name); - - // - XCSignalObject *iObj; - iObj = new XCSignalObject(); - - // - bool isCreated = iObj.Create( - ChartIdentification(), - name, - SubWindowIdentification(), - signal // - ); - if (!isCreated) - { - return; - } - - // - iObj.TPWidth(1); - iObj.TPColor(clrGreen); - iObj.TPWidth(STYLE_DOT); - - // - iObj.SLWidth(1); - iObj.SLColor(clrRed); - iObj.SLWidth(STYLE_DOT); - - // - iObj.TargetWidth(1); - iObj.TargetColor(clrLightBlue); - iObj.TargetWidth(STYLE_DOT); - - // - iObj.EntryWidth(1); - iObj.EntryColor(clrYellow); - iObj.EntryWidth(STYLE_DOT); - - // - // mDrawnObjects.Add(iObj); - } - /** * Clear all Drawn Objects ... */ diff --git a/X121SMCEA/Classes/x-121.smc.x-tradehandler.class.mq5 b/X121SMCEA/Classes/x-121.smc.x-tradehandler.class.mq5 index b11efc8f..77817950 100644 --- a/X121SMCEA/Classes/x-121.smc.x-tradehandler.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.x-tradehandler.class.mq5 @@ -26,6 +26,7 @@ #include "../../Classes/x-saherelm.x-alert.class.mq5" #include "../../Classes/x-saherelm.x-bar.analyser.class.mq5" #include "../../Classes/x-saherelm.x-trade.class.mq5" +#include "../../Classes/x-saherelm.x-poi.drawer.class.mq5" // // Definitions ... @@ -2204,6 +2205,32 @@ class XC121SMCTradeHandler : public XCBaseAlert mHedgeingMinRequiredProfitPerVolumeStep = value; } + /** + * Get POI Drawer instance Pointer ... + */ + XCPOIDrawer *GetDrawer() + { + return mDrawer; + } + + /** + * Get POI Drawer instance Pointer ... + */ + void SetDrawer(XCPOIDrawer *drawer) + { + mDrawer = drawer; + } + + /** + * Check Darwer Exists Before Draw anything ... + * + * @return ( bool ) + */ + bool CanDraw() + { + return mDrawer != NULL; + } + // // Actions ... @@ -3133,6 +3160,12 @@ class XC121SMCTradeHandler : public XCBaseAlert // // Add XTradeHandler Data ... Add(signal); + if (CanDraw()) + { + // + XCSignalObject *iObj; + mDrawer.DrawSignal(signal, iObj); + } // // Handle Last Executed Signal ... @@ -3607,6 +3640,7 @@ class XC121SMCTradeHandler : public XCBaseAlert // XCBarAnalyser mBarAnalyser; + XCPOIDrawer *mDrawer; // // Common Functions ... diff --git a/X121SMCEA/Experts/x-121.smc.expert.class.mq5 b/X121SMCEA/Experts/x-121.smc.expert.class.mq5 index 7a9b6324..d0b071f3 100644 --- a/X121SMCEA/Experts/x-121.smc.expert.class.mq5 +++ b/X121SMCEA/Experts/x-121.smc.expert.class.mq5 @@ -1033,6 +1033,7 @@ class XC121SMCExpert : public XCBaseExpert // // Parsers ... XSymbolParser _symbolParser; + XCPOIDrawer *poiDrawer = NULL; // // Single Symbol ... @@ -1049,6 +1050,14 @@ class XC121SMCExpert : public XCBaseExpert _Period // ); + // + if (poiDrawer == NULL) + { + // + poiDrawer = iX121SMCStrategy + .GetDrawer(); + } + // iX121SMCStrategy.AddXSignalEventHandler(OnSignalEventListener); @@ -1114,6 +1123,14 @@ class XC121SMCExpert : public XCBaseExpert _Period // ); + // + if (poiDrawer == NULL) + { + // + poiDrawer = iX121SMCStrategy + .GetDrawer(); + } + // iX121SMCStrategy.AddXSignalEventHandler(OnSignalEventListener); @@ -1125,6 +1142,12 @@ class XC121SMCExpert : public XCBaseExpert } } + // + if (poiDrawer != NULL) + { + mTradeHandler.SetDrawer(poiDrawer); + } + // return result; } diff --git a/X121SMCEA/Signals/x-121.smc.xtwpv.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xtwpv.signal.lib.mq5 index 8f6778a2..d4cfa2e7 100644 --- a/X121SMCEA/Signals/x-121.smc.xtwpv.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xtwpv.signal.lib.mq5 @@ -52,6 +52,20 @@ struct X121SMCStrategyXTWPVSignalConditions double point; XPVPivot pivot; + // + bool hasSupportZone; + bool hasResistanceZone; + bool hasSupplyZone; + bool hasDemandZone; + bool hasOrderBlock; + bool hasFairValueGap; + XCSupportZone *supportZone; + XCResistanceZone *resistanceZone; + XCSupplyZone *supplyZone; + XCDemandZone *demandZone; + XCOrderBlock *orderBlock; + XCFVG *fairValueGap; + // // Constructor ... X121SMCStrategyXTWPVSignalConditions() @@ -169,8 +183,161 @@ struct X121SMCStrategyXTWPVSignalConditions // point = 0; pivot.Clean(); + + // + CleanPriceInsideZones(); } + /** + * Clean Price Insie Zones ... + */ + void CleanPriceInsideZones() + { + // + hasSupportZone = false; + hasResistanceZone = false; + hasSupplyZone = false; + hasDemandZone = false; + hasOrderBlock = false; + hasFairValueGap = false; + + // + supportZone = NULL; + resistanceZone = NULL; + supplyZone = NULL; + demandZone = NULL; + orderBlock = NULL; + fairValueGap = NULL; + } + + /** + * Count Price Inside Zones ... + * + * @return ( int ) + */ + int CountPriceInsideZones() + { + // + int result = 0; + + // + if (hasSupportZone) + { + result++; + } + + // + if (hasResistanceZone) + { + result++; + } + + // + if (hasSupplyZone) + { + result++; + } + + // + if (hasDemandZone) + { + result++; + } + + // + if (hasOrderBlock) + { + result++; + } + + // + if (hasFairValueGap) + { + result++; + } + + // + return result; + } + + /** + * Check Conditions Has Price Inside Zones ... + * + * @return ( bool ) + */ + bool HasPriceInsideZones() + { + // + bool result = false; + + // + result = IsValidSize(CountPriceInsideZones()); + + // + return result; + } + + /** + * Check Conditions Has Bullish Price Inside Zone ... + * + * @return ( bool ) + */ + bool HasBullishPriceInsideZone() + { + // + bool result = false; + + // + result = + // + HasPriceInsideZones() && + // + (hasDemandZone || + hasSupportZone || + (hasOrderBlock && + orderBlock.IsBullish()) || + (hasFairValueGap && + fairValueGap.IsBullish())) + // + ; + + // + return result; + } + + /** + * Check Conditions Has Bearish Price Inside Zone ... + * + * @return ( bool ) + */ + bool HasBearishPriceInsideZone() + { + // + bool result = false; + + // + result = + // + HasPriceInsideZones() && + // + (hasSupplyZone || + hasResistanceZone || + (hasOrderBlock && + orderBlock.IsBearish()) || + (hasFairValueGap && + fairValueGap.IsBearish())) + // + ; + + // + return result; + } + + /** + * Check has Vald Pivot or not ... + * + * @return ( bool ) + */ bool HasPivot() { return pivot.IsValid(); @@ -555,6 +722,36 @@ bool DetectX121SMCXTWPVSiganlSetup( conditions.point = conditions.pivot.lower; } + // + // Detect a Zone Which Price Inside it ... + conditions.CleanPriceInsideZones(); + bool hasPriceInsideZones = conditions.HasPriceInsideZones(); + int priceInsideZonesCount = conditions.CountPriceInsideZones(); + if (!hasPriceInsideZones) + { + // + hasPriceInsideZones = DetectPriceInsideZones( + verificationState, + cBar, + priceInsideZonesCount, + conditions.hasSupportZone, + conditions.supportZone, + conditions.hasResistanceZone, + conditions.resistanceZone, + conditions.hasSupplyZone, + conditions.supplyZone, + conditions.hasDemandZone, + conditions.demandZone, + conditions.hasOrderBlock, + conditions.orderBlock, + conditions.hasFairValueGap, + conditions.fairValueGap // + ); + + // + priceInsideZonesCount = conditions.CountPriceInsideZones(); + } + // double donCloseUpper = helperConditions.x121Conditions.donCloseUpperBuffer[1]; double donCloseLower = helperConditions.x121Conditions.donCloseLowerBuffer[1]; @@ -588,9 +785,8 @@ bool DetectX121SMCXTWPVSiganlSetup( // isBearish = // - bearishConditions1 - // || - // bearishConditions2 + bearishConditions1 || + bearishConditions2 // ; @@ -1003,6 +1199,72 @@ bool DetectX121SMCXTWPVSiganlTrigger( ); } + // + double peak = analyseConditions.x121Conditions.peaksBuffer[1]; + double vale = analyseConditions.x121Conditions.valesBuffer[1]; + + // + bool isBasedOnPeak = conditions.point == peak; + bool isBasedOnVale = conditions.point == vale; + + // + bool hasPriceInsideZones = conditions.HasPriceInsideZones(); + bool hasBullishPriceInsideZone = conditions.HasBullishPriceInsideZone(); + bool hasBearishPriceInsideZone = conditions.HasBearishPriceInsideZone(); + + // + if ( + isBearish && + isBasedOnPeak && + hasPriceInsideZones && + hasBearishPriceInsideZone // + ) + { + // + // Supply ... + if (conditions.hasSupplyZone) + { + // + Add( + conditions.supplyZone.Upper(), + sls // + ); + } + + // + // Resistance ... + if (conditions.hasResistanceZone) + { + // + Add( + conditions.resistanceZone.Upper(), + sls // + ); + } + + // + // Order Block ... + if (conditions.hasOrderBlock) + { + // + Add( + conditions.orderBlock.Upper(), + sls // + ); + } + + // + // Fair Value Gap ... + if (conditions.hasFairValueGap) + { + // + Add( + conditions.fairValueGap.Upper(), + sls // + ); + } + } + // double slsMin = GetMin(sls); double slsMax = GetMax(sls); @@ -1035,4 +1297,204 @@ bool DetectX121SMCXTWPVSiganlTrigger( return result; } +/** + * Drw Conditions Price Inside Zones ... + * + * @param conditions: X121SMCStrategyXTWPVSignalConditions instance Reference ... + * @param drawer: XCPOIDrawer pointer ... + * @param drawnObjects: XCBaseObject instance Reference Collection ... + * + * @return ( int ) + */ +int DrawPriceInsideZones( + X121SMCStrategyXTWPVSignalConditions &conditions, + XCPOIDrawer *drawer, + XCBaseObject *&drawnObjects[] // +) +{ + // + int result = 0; + + // + Clean(drawnObjects); + + // + if ( + drawer == NULL || + !conditions.HasPriceInsideZones()) + { + return result; + } + + // + // Support ... + if (conditions.hasSupportZone) + { + // + XCSupportZoneObject *iObj; + bool isCreated = drawer.CreateSupportZone( + conditions.supportZone, + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + drawnObjects // + ); + } + } + + // + // Resistance ... + if (conditions.hasResistanceZone) + { + // + XCResistanceZoneObject *iObj; + bool isCreated = drawer.CreateResistanceZone( + conditions.resistanceZone, + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + drawnObjects // + ); + } + } + + // + // Supply ... + if (conditions.hasSupplyZone) + { + // + XCSupplyZoneObject *iObj; + bool isCreated = drawer.CreateSupplyZone( + conditions.supplyZone, + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + drawnObjects // + ); + } + } + + // + // Demand ... + if (conditions.hasDemandZone) + { + // + XCDemandZoneObject *iObj; + bool isCreated = drawer.CreateDemandZone( + conditions.demandZone, + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + drawnObjects // + ); + } + } + + // + // Order Block ... + if (conditions.hasOrderBlock) + { + // + bool isBullish = conditions.orderBlock.IsBullish(); + if (isBullish) + { + // + XCBullishOrderBlockObject *iObj; + bool isCreated = drawer.CreateBullishOrderBlock( + conditions.orderBlock, + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + drawnObjects // + ); + } + } + else + { + // + XCBearishOrderBlockObject *iObj; + bool isCreated = drawer.CreateBearishOrderBlock( + conditions.orderBlock, + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + drawnObjects // + ); + } + } + } + + // + // FairValueGap ... + if (conditions.hasFairValueGap) + { + // + bool isBullish = conditions.fairValueGap.IsBullish(); + if (isBullish) + { + // + XCBullishFairValueGapObject *iObj; + bool isCreated = drawer.CreateBullishFairValueGap( + conditions.fairValueGap, + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + drawnObjects // + ); + } + } + else + { + // + XCBearishFairValueGapObject *iObj; + bool isCreated = drawer.CreateBearishFairValueGap( + conditions.fairValueGap, + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + drawnObjects // + ); + } + } + } + + // + result = ArraySize(drawnObjects); + + // + return result; +} + // diff --git a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 index 99000111..885eff5b 100644 --- a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 @@ -28,12 +28,7 @@ // #include "../Signals/x-121.smc.test.signal.lib.mq5" -#include "../Signals/x-121.smc.xoepv.signal.lib.mq5" -#include "../Signals/x-121.smc.xpvdp.signal.lib.mq5" -#include "../Signals/x-121.smc.xpvob.signal.lib.mq5" -#include "../Signals/x-121.smc.xpvsupdem.signal.lib.mq5" #include "../Signals/x-121.smc.xtwpv.signal.lib.mq5" -#include "../Signals/x-121.smc.xvwpb.signal.lib.mq5" // // Definitions ... @@ -161,21 +156,11 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // bool useTestSignal = false; - bool useXPVOBSignal = false; - bool useXPVDPSignal = false; - bool useXVWPBSignal = false; bool useXTWPVSignal = true; - bool useXOEPVSignal = false; - bool useXPVSUPDEMSignal = false; // bool hasTestSignal = false; - bool hasXPVOBSignal = false; - bool hasXPVDPSignal = false; - bool hasXVWPBSignal = false; bool hasXTWPVSignal = false; - bool hasXOEPVSignal = false; - bool hasXPVSUPDEMSignal = false; // // Test Signal ... @@ -186,33 +171,6 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy hasSignal = hasTestSignal; } - // - // XPVOB Signal ... - if (useXPVOBSignal && !hasSignal) - { - // - hasXPVOBSignal = DetectXPVOBSignal(conditions); - hasSignal = hasXPVOBSignal; - } - - // - // XPVDP Signal ... - if (useXPVDPSignal && !hasSignal) - { - // - hasXPVDPSignal = DetectXPVDPSignal(conditions); - hasSignal = hasXPVDPSignal; - } - - // - // XVWPB Signal ... - if (useXVWPBSignal && !hasSignal) - { - // - hasXVWPBSignal = DetectXVWPBSignal(conditions); - hasSignal = hasXVWPBSignal; - } - // // XTWPV Signal ... if (useXTWPVSignal && !hasSignal) @@ -222,24 +180,6 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy hasSignal = hasXTWPVSignal; } - // - // XOEPV Signal ... - if (useXOEPVSignal && !hasSignal) - { - // - hasXOEPVSignal = DetectXOEPVSignal(conditions); - hasSignal = hasXOEPVSignal; - } - - // - // XPVSUPDEM Signal ... - if (useXPVSUPDEMSignal && !hasSignal) - { - // - hasXPVSUPDEMSignal = DetectXPVSUPDEMSignal(conditions); - hasSignal = hasXPVSUPDEMSignal; - } - // result = hasSignal; if (!result) @@ -338,51 +278,9 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy signal.target = tp; } - // - // Configure Signal Protecting ... - // if (hasXPVOBSignal || - // hasXPVDPSignal || - // hasXPVSUPDEMSignal) - // { - // // - // signal.fullTPLevel = r2r; - // signal.partialCloseOnTPLevel = 2; - // signal.partialCloseMultiplier = 0.5; - - // // - // signal.riskFreeOnBreakEven = true; - // signal.tpLevelForBreakEven = 1; - - // // - // signal.trailSL = true; - // signal.trailSLStartOnReachTPLevel = 3; - // } - - // - // Configure Signal Protecting ... - // if (hasXVWPBSignal) - // { - // // - // signal.fullTPLevel = r2r; - // signal.partialCloseOnTPLevel = 2; - // signal.partialCloseMultiplier = 0.5; - - // // - // signal.riskFreeOnBreakEven = true; - // signal.tpLevelForBreakEven = 1; - - // // - // signal.trailSL = true; - // signal.trailSLStartOnReachTPLevel = 2; - // } - // result = PrepareSignal(signal); - if (result) - { - DrawSignal(signal); - } - + // hasLong = false; hasShort = false; @@ -759,390 +657,6 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy return result; } - // - // XPVOB Signal ... - X121SMCStrategyXPVOBSignalConditions mXPVOBConditions; - bool DetectXPVOBSignal( - X121SMCStrategyConditions &conditions // - ) - { - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - datetime cTime = TimeCurrent(); - - // - ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XPVOB; - string providerStr = ToString(provider); - - // - // Detect Setup Conditions ... - datetime setupTime = mXPVOBConditions.setupTime; - bool isSetuped = mXPVOBConditions.IsSetuped(); - ENUM_X_DIRECTION setupDir = mXPVOBConditions.dir; - if (!isSetuped) - { - // - // Detect Signal Setup ... - isSetuped = DetectX121SMCXPVOBSiganlSetup( - symbol, - period, - mXPVOBConditions, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - result = isSetuped; - if (!result) - { - return result; - } - - // - setupDir = mXPVOBConditions.dir; - setupTime = mXPVOBConditions.setupTime; - } - - // - // Draw Conditions Active FVG ... - // if (isSetuped) - // { - // // - // XCFVG *iFVG = mXPVOBConditions.activeFVG; - // if (iFVG != NULL && iFVG.IsValid()) - // { - // // - // ClearDraws(); - // iFVG.To(cTime); - // if (IsBullish(setupDir) && iFVG.IsBullish()) - // { - // // - // XCBullishFairValueGapObject *iObj; - // bool isCreated = mPOIDrawer.CreateBullishFairValueGap( - // iFVG, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - // } - // else if (IsBearish(setupDir) && iFVG.IsBearish()) - // { - // // - // XCBearishFairValueGapObject *iObj; - // bool isCreated = mPOIDrawer.CreateBearishFairValueGap( - // iFVG, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - // } - // } - // } - - // - // Detect Trigger Conditions ... - bool canTrigger = mXPVOBConditions.CanTrigger(); - datetime triggerTime = mXPVOBConditions.triggerTime; - if (!canTrigger) - { - // - // Detect Signal Trigger ... - canTrigger = DetectX121SMCXPVOBSiganlTrigger( - mXPVOBConditions, - symbol, - period, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - result = canTrigger; - if (!result) - { - return result; - } - - // - triggerTime = mXPVOBConditions.triggerTime; - } - - // - // Check Signal Direction ... - - // - isBullish = IsBullish(setupDir); - isBearish = IsBearish(setupDir); - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Issues Signal on Conditions ... - conditions.signalDir = setupDir; - conditions.provider = providerStr; - conditions.sl = mXPVOBConditions.sl; - conditions.target = mXPVOBConditions.target; - - // - mXPVOBConditions.Clean(); - - // - return result; - } - - // - // XPVDP Signal ... - X121SMCStrategyXPVDPSignalConditions mXPVDPConditions; - bool DetectXPVDPSignal( - X121SMCStrategyConditions &conditions // - ) - { - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - datetime cTime = TimeCurrent(); - - // - ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XPVDP; - string providerStr = ToString(provider); - - // - // Detect Setup Conditions ... - datetime setupTime = mXPVDPConditions.setupTime; - bool isSetuped = mXPVDPConditions.IsSetuped(); - ENUM_X_DIRECTION setupDir = mXPVDPConditions.dir; - if (!isSetuped) - { - // - // Detect Signal Setup ... - isSetuped = DetectX121SMCXPVDPSiganlSetup( - symbol, - period, - mXPVDPConditions, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - setupDir = mXPVDPConditions.dir; - setupTime = mXPVDPConditions.setupTime; - } - result = isSetuped; - if (!result) - { - return result; - } - - // - // Detect Trigger Conditions ... - bool canTrigger = mXPVDPConditions.CanTrigger(); - datetime triggerTime = mXPVDPConditions.triggerTime; - if (!canTrigger) - { - // - // Detect Signal Trigger ... - canTrigger = DetectX121SMCXPVDPSiganlTrigger( - mXPVDPConditions, - symbol, - period, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - result = canTrigger; - if (!result) - { - return result; - } - - // - triggerTime = mXPVDPConditions.triggerTime; - } - - // - // Check Signal Direction ... - - // - isBullish = IsBullish(setupDir); - isBearish = IsBearish(setupDir); - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Issues Signal on Conditions ... - conditions.signalDir = setupDir; - conditions.provider = providerStr; - conditions.sl = mXPVDPConditions.sl; - conditions.target = mXPVDPConditions.target; - - // - mXPVDPConditions.Clean(); - - // - return result; - } - - // - // XVWPB Signal ... - X121SMCStrategyXVWPBSignalConditions mXVWPBConditions; - bool DetectXVWPBSignal( - X121SMCStrategyConditions &conditions // - ) - { - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - datetime cTime = TimeCurrent(); - - // - ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XVWPB; - string providerStr = ToString(provider); - - // - // Detect Setup Conditions ... - datetime setupTime = mXVWPBConditions.setupTime; - bool isSetuped = mXVWPBConditions.IsSetuped(); - ENUM_X_DIRECTION setupDir = mXVWPBConditions.dir; - if (!isSetuped) - { - // - // Detect Signal Setup ... - isSetuped = DetectX121SMCXVWPBSiganlSetup( - symbol, - period, - mXVWPBConditions, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - setupDir = mXVWPBConditions.dir; - setupTime = mXVWPBConditions.setupTime; - } - result = isSetuped; - if (!result) - { - return result; - } - - // - // Detect Trigger Conditions ... - bool canTrigger = mXVWPBConditions.CanTrigger(); - datetime triggerTime = mXVWPBConditions.triggerTime; - if (!canTrigger) - { - // - // Detect Signal Trigger ... - canTrigger = DetectX121SMCXVWPBSiganlTrigger( - mXVWPBConditions, - symbol, - period, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - result = canTrigger; - if (!result) - { - return result; - } - - // - triggerTime = mXVWPBConditions.triggerTime; - } - - // - // Check Signal Direction ... - - // - isBullish = IsBullish(setupDir); - isBearish = IsBearish(setupDir); - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Issues Signal on Conditions ... - conditions.signalDir = setupDir; - conditions.provider = providerStr; - conditions.sl = mXVWPBConditions.sl; - conditions.target = mXVWPBConditions.target; - - // - mXVWPBConditions.Clean(); - - // - return result; - } - // // XTWPV Signal ... X121SMCStrategyXTWPVSignalConditions mXTWPVConditions; @@ -1192,39 +706,26 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // setupDir = mXTWPVConditions.dir; setupTime = mXTWPVConditions.setupTime; - - // // - // if (!isSetuped) - // { - // // - // bool hasParent = mXTWPVConditions.HasParentPivot(); - // if (hasParent) - // { - // // - // XCBaseObject *objs[]; - // mPOIDrawer.DrawPivot( - // mXTWPVConditions.parentPivot, - // objs, - // true, // Drawing State ... - // true // Drawing Ticks Zone ... - // ); - // AddObjectsIfNotExists(objs); - // } - - // // - // bool hasChild = mXTWPVConditions.HasChildPivot(); - // if (hasChild) - // { - // // - // XCBaseObject *objs[]; - // mPOIDrawer.DrawPivot( - // mXTWPVConditions.childPivot, - // objs // - // ); - // AddObjectsIfNotExists(objs); - // } - // } } + + // + // Draw Price Inside Zones ... + if (mXTWPVConditions.HasPriceInsideZones()) + { + // + ClearDraws(); + + // + XCBaseObject *drawnObjects[]; + int drawnObjectsCount = DrawPriceInsideZones( + mXTWPVConditions, + mPOIDrawer, + drawnObjects // + ); + AddObjectsIfNotExists(drawnObjects); + } + + // result = isSetuped; if (!result) { @@ -1289,288 +790,6 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy return result; } - // - // XOEPV Signal ... - X121SMCStrategyXOEPVSignalConditions mXOEPVConditions; - bool DetectXOEPVSignal( - X121SMCStrategyConditions &conditions // - ) - { - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - datetime cTime = TimeCurrent(); - - // - ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XOEPV; - string providerStr = ToString(provider); - - // - // Detect Setup Conditions ... - datetime setupTime = mXOEPVConditions.setupTime; - bool isSetuped = mXOEPVConditions.IsSetuped(); - ENUM_X_DIRECTION setupDir = mXOEPVConditions.dir; - if (!isSetuped) - { - // - // Detect Signal Setup ... - isSetuped = DetectX121SMCXOEPVSiganlSetup( - symbol, - period, - mXOEPVConditions, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - setupDir = mXOEPVConditions.dir; - setupTime = mXOEPVConditions.setupTime; - } - - // - result = isSetuped; - if (!result) - { - return result; - } - - // - // Detect Trigger Conditions ... - bool canTrigger = mXOEPVConditions.CanTrigger(); - datetime triggerTime = mXOEPVConditions.triggerTime; - if (!canTrigger) - { - // - // Detect Signal Trigger ... - canTrigger = DetectX121SMCXOEPVSiganlTrigger( - mXOEPVConditions, - symbol, - period, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - result = canTrigger; - if (!result) - { - return result; - } - - // - triggerTime = mXOEPVConditions.triggerTime; - } - - // - // Check Signal Direction ... - - // - isBullish = IsBullish(setupDir); - isBearish = IsBearish(setupDir); - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Issues Signal on Conditions ... - conditions.signalDir = setupDir; - conditions.provider = providerStr; - conditions.sl = mXOEPVConditions.sl; - conditions.target = mXOEPVConditions.target; - - // - mXOEPVConditions.Clean(); - - // - return result; - } - - // - // XPVSUPDEM Signal ... - X121SMCStrategyXPVSUPDEMSignalConditions mXPVSUPDEMConditions; - bool DetectXPVSUPDEMSignal( - X121SMCStrategyConditions &conditions // - ) - { - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - datetime cTime = TimeCurrent(); - - // - ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XPVSUPDEM; - string providerStr = ToString(provider); - - // - // Detect Setup Conditions ... - datetime setupTime = mXPVSUPDEMConditions.setupTime; - bool isSetuped = mXPVSUPDEMConditions.IsSetuped(); - ENUM_X_DIRECTION setupDir = mXPVSUPDEMConditions.dir; - if (!isSetuped) - { - // - // Detect Signal Setup ... - isSetuped = DetectX121SMCXPVSUPDEMSiganlSetup( - symbol, - period, - mXPVSUPDEMConditions, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - setupDir = mXPVSUPDEMConditions.dir; - setupTime = mXPVSUPDEMConditions.setupTime; - } - - // ClearDraws(); - // ENUM_X_DIRECTION activeZoneDir; - // bool hasTicksZone = mXPVSUPDEMConditions.HasTicksZone(); - // bool hasActiveZone = mXPVSUPDEMConditions.HasActiveZone(activeZoneDir); - // if (hasActiveZone) - // { - // // - // if (IsBullish(activeZoneDir)) - // { - // // - // mXPVSUPDEMConditions.activeDemandZone.To(cTime); - // XCDemandZoneObject *iObj; - // bool isCreated = mPOIDrawer.CreateDemandZone( - // mXPVSUPDEMConditions.activeDemandZone, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - // } - // else - // { - // // - // mXPVSUPDEMConditions.activeSupplyZone.To(cTime); - // XCSupplyZoneObject *iObj; - // bool isCreated = mPOIDrawer.CreateSupplyZone( - // mXPVSUPDEMConditions.activeSupplyZone, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - // } - // } - // if (hasTicksZone) - // { - // // - // XCTicksZoneObject *iObj; - // bool isCreated = mPOIDrawer.CreateTicksZone( - // mXPVSUPDEMConditions.ticksZone, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - // } - - // - result = isSetuped; - if (!result) - { - return result; - } - - // - // Detect Trigger Conditions ... - bool canTrigger = mXPVSUPDEMConditions.CanTrigger(); - datetime triggerTime = mXPVSUPDEMConditions.triggerTime; - if (!canTrigger) - { - // - // Detect Signal Trigger ... - canTrigger = DetectX121SMCXPVSUPDEMSiganlTrigger( - mXPVSUPDEMConditions, - symbol, - period, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - result = canTrigger; - if (!result) - { - return result; - } - - // - triggerTime = mXPVSUPDEMConditions.triggerTime; - } - - // - // Check Signal Direction ... - - // - isBullish = IsBullish(setupDir); - isBearish = IsBearish(setupDir); - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Issues Signal on Conditions ... - conditions.signalDir = setupDir; - conditions.provider = providerStr; - conditions.sl = mXPVSUPDEMConditions.sl; - conditions.target = mXPVSUPDEMConditions.target; - - // - mXPVSUPDEMConditions.Clean(); - - // - return result; - } - // // Private ... private: