From 3c2de65f40d000030efd5be350fc6d35f29270f5 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Fri, 17 Jan 2025 02:19:22 +0330 Subject: [PATCH] Try to Cleanup Memory for Fix Memory Leaks ... --- Classes/x-saherelm.base.class.mq5 | 8 +- Classes/x-saherelm.x-expert.class.mq5 | 3 + Classes/x-saherelm.x-poi.class.mq5 | 194 +----- Classes/x-saherelm.x-poi.drawer.class.mq5 | 2 + Classes/x-saherelm.x-trade.class.mq5 | 11 + Experts/x-saherelm.x-121.smc.ea.mq5 | 6 +- Helpers/x-saherelm.x121.xatr.helper.mq5 | 16 +- Helpers/x-saherelm.x121.xche.helper.mq5 | 12 + Helpers/x-saherelm.x121.xdon.helper.mq5 | 18 +- Helpers/x-saherelm.x121.xpv.helper.mq5 | 17 + Helpers/x-saherelm.x121.xstr.helper.mq5 | 10 + Helpers/x-saherelm.x121.xvwap.helper.mq5 | 20 +- Helpers/x-saherelm.xcc.helper.mq5 | 14 +- Helpers/x-saherelm.xct.helper.mq5 | 1 + Libraries/x-saherelm.common.lib.mq5 | 2 +- .../Classes/x-121.smc.base.strategy.class.mq5 | 14 +- .../x-121.smc.market.cycle.helper.class.mq5 | 3 +- .../x-121.smc.x-tradehandler.class.mq5 | 9 +- X121SMCEA/Experts/x-121.smc.expert.class.mq5 | 16 + X121SMCEA/Libraries/x-121.smc.guard.lib.mq5 | 586 ++++++++++++++++-- .../Signals/x-121.smc.xpz.signal.lib.mq5 | 62 ++ .../Signals/x-121.smc.xstrpv.signal.lib.mq5 | 61 ++ .../Strategy/x-121.smc.strategy.class.mq5 | 139 +---- 23 files changed, 842 insertions(+), 382 deletions(-) diff --git a/Classes/x-saherelm.base.class.mq5 b/Classes/x-saherelm.base.class.mq5 index b367dbec..0e7557f0 100644 --- a/Classes/x-saherelm.base.class.mq5 +++ b/Classes/x-saherelm.base.class.mq5 @@ -34,11 +34,15 @@ class XCBase // // Represent Basic Unique Tag ... - virtual string GetTag(); + virtual string GetTag() { + return NULL; + } // // Retrieve Class Token ... - virtual string GetToken(); + virtual string GetToken() { + return NULL; + } // // Protected diff --git a/Classes/x-saherelm.x-expert.class.mq5 b/Classes/x-saherelm.x-expert.class.mq5 index 5e90b3fb..7c05c612 100644 --- a/Classes/x-saherelm.x-expert.class.mq5 +++ b/Classes/x-saherelm.x-expert.class.mq5 @@ -54,6 +54,8 @@ class XCBaseExpert : public XCBaseAlert // Deconstructor ... void ~XCBaseExpert() { + // + delete mTrader; } // @@ -649,6 +651,7 @@ class XCBaseExpert : public XCBaseAlert virtual void DestroyEA() { // + delete mTrader; delete mCTHelper; delete mCCHelper; } diff --git a/Classes/x-saherelm.x-poi.class.mq5 b/Classes/x-saherelm.x-poi.class.mq5 index c7d77acb..4e89e823 100644 --- a/Classes/x-saherelm.x-poi.class.mq5 +++ b/Classes/x-saherelm.x-poi.class.mq5 @@ -42,7 +42,7 @@ class XCPOIDetector : public XCBaseAlert // public: // - XCPOIDrawer mDrawer; + XCPOIDrawer *mDrawer; // // Constructors ... @@ -69,6 +69,10 @@ class XCPOIDetector : public XCBaseAlert mPeriod // ); + // + // Create Default Drawer Instance ... + mDrawer = new XCPOIDrawer(); + // // Apply Default Configurations ... Default(); @@ -1048,6 +1052,10 @@ class XCPOIDetector : public XCBaseAlert DestroyPOIs(); DestroySessions(); DestroyEventListeners(); + + // + delete mDrawer; + delete mTicksZone; } // @@ -1212,6 +1220,22 @@ class XCPOIDetector : public XCBaseAlert // Clean(mBullishFairValueGaps); Clean(mBearishFairValueGaps); + + // + ArrayFree(mSwingHighs); + ArrayFree(mSwingLows); + ArrayFree(mBullishMomentumBars); + ArrayFree(mBearishMomentumBars); + ArrayFree(mBullishRejectionBars); + ArrayFree(mBearishRejectionBars); + ArrayFree(mSupportZones); + ArrayFree(mResistanceZones); + ArrayFree(mSupplyZones); + ArrayFree(mDemandZones); + ArrayFree(mBullishOrderBlocks); + ArrayFree(mBearishOrderBlocks); + ArrayFree(mBullishFairValueGaps); + ArrayFree(mBearishFairValueGaps); } /** @@ -1226,7 +1250,11 @@ class XCPOIDetector : public XCBaseAlert */ void DestroyEventListeners() { + // Clean(mEventListeners); + + // + ArrayFree(mEventListeners); } // @@ -1327,17 +1355,6 @@ class XCPOIDetector : public XCBaseAlert swing, mSwingHighs // ); - - // - // XCSwingHighObject *iObj; - // bool isCreated = mDrawer.CreateSwingHigh( - // swing, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } } } @@ -1397,17 +1414,6 @@ class XCPOIDetector : public XCBaseAlert swing, mSwingLows // ); - - // // - // XCSwingLowObject *iObj; - // bool isCreated = mDrawer.CreateSwingLow( - // swing, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } } } @@ -1463,17 +1469,6 @@ class XCPOIDetector : public XCBaseAlert momentumBar, mBullishMomentumBars // ); - - // - // XCBullishMomentumObject *iObj; - // bool isCreated = mDrawer.CreateBullishMomentumBar( - // momentumBar, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } } } @@ -1529,17 +1524,6 @@ class XCPOIDetector : public XCBaseAlert momentumBar, mBearishMomentumBars // ); - - // - // XCBearishMomentumObject *iObj; - // bool isCreated = mDrawer.CreateBearishMomentumBar( - // momentumBar, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } } } @@ -1595,17 +1579,6 @@ class XCPOIDetector : public XCBaseAlert rejectionBar, mBullishRejectionBars // ); - - // // - // XCBullishRejectionObject *iObj; - // bool isCreated = mDrawer.CreateBullishRejectionBar( - // rejectionBar, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } } } @@ -1661,17 +1634,6 @@ class XCPOIDetector : public XCBaseAlert rejectionBar, mBearishRejectionBars // ); - - // - // XCBearishRejectionObject *iObj; - // bool isCreated = mDrawer.CreateBearishRejectionBar( - // rejectionBar, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } } } @@ -1735,17 +1697,6 @@ class XCPOIDetector : public XCBaseAlert support, mSupportZones // ); - - // // - // XCSupportZoneObject *iObj; - // bool isCreated = mDrawer.CreateSupportZone( - // support, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } } } @@ -1805,17 +1756,6 @@ class XCPOIDetector : public XCBaseAlert resistance, mResistanceZones // ); - - // // - // XCResistanceZoneObject *iObj; - // bool isCreated = mDrawer.CreateResistanceZone( - // resistance, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } } } @@ -1902,17 +1842,6 @@ class XCPOIDetector : public XCBaseAlert supply, mSupplyZones // ); - - // // - // XCSupplyZoneObject *iObj; - // bool isCreated = mDrawer.CreateSupplyZone( - // supply, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } } } @@ -1999,17 +1928,6 @@ class XCPOIDetector : public XCBaseAlert demand, mDemandZones // ); - - // // - // XCDemandZoneObject *iObj; - // bool isCreated = mDrawer.CreateDemandZone( - // demand, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } } } @@ -2085,17 +2003,6 @@ class XCPOIDetector : public XCBaseAlert ob, mBullishOrderBlocks // ); - - // // - // XCBullishOrderBlockObject *iObj; - // bool isCreated = mDrawer.CreateBullishOrderBlock( - // ob, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } } } @@ -2242,17 +2149,6 @@ class XCPOIDetector : public XCBaseAlert ob, mBearishOrderBlocks // ); - - // // - // XCBearishOrderBlockObject *iObj; - // bool isCreated = mDrawer.CreateBearishOrderBlock( - // ob, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } } } @@ -2402,17 +2298,6 @@ class XCPOIDetector : public XCBaseAlert fvg, mBullishFairValueGaps // ); - - // // - // XCBullishFairValueGapObject *iObj; - // bool isCreated = mDrawer.CreateBullishFairValueGap( - // fvg, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } } } @@ -2491,17 +2376,6 @@ class XCPOIDetector : public XCBaseAlert fvg, mBearishFairValueGaps // ); - - // // - // XCBearishFairValueGapObject *iObj; - // bool isCreated = mDrawer.CreateBearishFairValueGap( - // fvg, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } } } @@ -4341,16 +4215,6 @@ class XCPOIDetector : public XCBaseAlert return result; } - // // - // if (mTicksZoneObject != NULL) - // { - // mTicksZoneObject.Destroy(); - // } - // mDrawer.CreateTicksZone( - // mTicksZone, - // mTicksZoneObject // - // ); - // return result; } diff --git a/Classes/x-saherelm.x-poi.drawer.class.mq5 b/Classes/x-saherelm.x-poi.drawer.class.mq5 index 55671829..b2983039 100644 --- a/Classes/x-saherelm.x-poi.drawer.class.mq5 +++ b/Classes/x-saherelm.x-poi.drawer.class.mq5 @@ -44,6 +44,8 @@ class XCPOIDrawer : public XCBase // Deconstructor ... void ~XCPOIDrawer() { + // + ArrayFree(mTicksZoneSpecs); } // diff --git a/Classes/x-saherelm.x-trade.class.mq5 b/Classes/x-saherelm.x-trade.class.mq5 index 1cdf0caf..64599b8e 100644 --- a/Classes/x-saherelm.x-trade.class.mq5 +++ b/Classes/x-saherelm.x-trade.class.mq5 @@ -598,6 +598,17 @@ class XCTrade : public XCBase Clean(mOnPartialCloseEventHandlers); Clean(mPositionsChangedEventHandlers); Clean(mTradeStateChangedEventHandlers); + + // + ArrayFree(mOnModifyEventHandlers); + ArrayFree(mStopLossEventHandlers); + ArrayFree(mTakeProfitEventHandlers); + ArrayFree(mDealsChangedEventHandlers); + ArrayFree(mOnForceCloseEventHandlers); + ArrayFree(mOrdersChangedEventHandlers); + ArrayFree(mOnPartialCloseEventHandlers); + ArrayFree(mPositionsChangedEventHandlers); + ArrayFree(mTradeStateChangedEventHandlers); } // diff --git a/Experts/x-saherelm.x-121.smc.ea.mq5 b/Experts/x-saherelm.x-121.smc.ea.mq5 index 212750d7..64042fe1 100644 --- a/Experts/x-saherelm.x-121.smc.ea.mq5 +++ b/Experts/x-saherelm.x-121.smc.ea.mq5 @@ -106,7 +106,7 @@ input bool eaReportNewHours = false; // Report New Hours // // Define Local Variables ... -XC121SMCExpert eaExpert; +XC121SMCExpert *eaExpert; // // Event Handlers ... @@ -132,6 +132,7 @@ int OnInit() // // Configure EA Expert Class ... + eaExpert = new XC121SMCExpert(); // // Event Handlers ... @@ -241,6 +242,9 @@ void OnDeinit(const int reason) // // Destroy Timer ... eaExpert.HandleOnDeInit(); + + // + delete eaExpert; } // diff --git a/Helpers/x-saherelm.x121.xatr.helper.mq5 b/Helpers/x-saherelm.x121.xatr.helper.mq5 index beed74b1..06b3bfbf 100644 --- a/Helpers/x-saherelm.x121.xatr.helper.mq5 +++ b/Helpers/x-saherelm.x121.xatr.helper.mq5 @@ -475,6 +475,16 @@ class XCX121XATRHelper : public XCBaseHelper // Deconstructor ... ~XCX121XATRHelper() { + // + ArrayFree(rsiBuffer); + ArrayFree(atrUpperBuffer); + ArrayFree(atrLowerBuffer); + ArrayFree(atrBuffer); + ArrayFree(atrUpperRawBuffer); + ArrayFree(atrLowerRawBuffer); + + // + mInputs.Clean(); } // @@ -482,7 +492,7 @@ class XCX121XATRHelper : public XCBaseHelper bool Init( string symbol, // Trading Symbol ENUM_TIMEFRAMES period, // Trading Period - X121XATRInputs &inputs // Inputs + X121XATRInputs &inputs // Inputs ) { // @@ -880,8 +890,8 @@ class XCX121XATRHelper : public XCBaseHelper // bool GetConditions( X121XATRConditions &conditions, // - int barIndex = 0, // - int loopback = 5 // + int barIndex = 0, // + int loopback = 5 // ) { // diff --git a/Helpers/x-saherelm.x121.xche.helper.mq5 b/Helpers/x-saherelm.x121.xche.helper.mq5 index 711cce0c..3fdf6e95 100644 --- a/Helpers/x-saherelm.x121.xche.helper.mq5 +++ b/Helpers/x-saherelm.x121.xche.helper.mq5 @@ -420,6 +420,18 @@ class XCX121XCHEHelper : public XCBaseHelper // Deconstructor ... ~XCX121XCHEHelper() { + // + mInputs.Clean(); + + // + ArrayFree(le1Buffer); + ArrayFree(se1Buffer); + ArrayFree(le2Buffer); + ArrayFree(se2Buffer); + ArrayFree(le1StartBuffer); + ArrayFree(se1StartBuffer); + ArrayFree(le2StartBuffer); + ArrayFree(se2StartBuffer); } // diff --git a/Helpers/x-saherelm.x121.xdon.helper.mq5 b/Helpers/x-saherelm.x121.xdon.helper.mq5 index 32ba9d78..c4bd5f69 100644 --- a/Helpers/x-saherelm.x121.xdon.helper.mq5 +++ b/Helpers/x-saherelm.x121.xdon.helper.mq5 @@ -421,6 +421,18 @@ class XCX121XDONHelper : public XCBaseHelper // Deconstructor ... ~XCX121XDONHelper() { + // + mInputs.Clean(); + + // + ArrayFree(donOpenUpperBuffer); + ArrayFree(donOpenLowerBuffer); + ArrayFree(donHighUpperBuffer); + ArrayFree(donHighLowerBuffer); + ArrayFree(donLowUpperBuffer); + ArrayFree(donLowLowerBuffer); + ArrayFree(donCloseUpperBuffer); + ArrayFree(donCloseLowerBuffer); } // @@ -428,7 +440,7 @@ class XCX121XDONHelper : public XCBaseHelper bool Init( string symbol, // Trading Symbol ENUM_TIMEFRAMES period, // Trading Period - X121XDONInputs &inputs // Inputs + X121XDONInputs &inputs // Inputs ) { // @@ -950,8 +962,8 @@ class XCX121XDONHelper : public XCBaseHelper // bool GetConditions( X121XDONConditions &conditions, // - int barIndex = 0, // - int loopback = 5 // + int barIndex = 0, // + int loopback = 5 // ) { // diff --git a/Helpers/x-saherelm.x121.xpv.helper.mq5 b/Helpers/x-saherelm.x121.xpv.helper.mq5 index 135e7f67..afa11807 100644 --- a/Helpers/x-saherelm.x121.xpv.helper.mq5 +++ b/Helpers/x-saherelm.x121.xpv.helper.mq5 @@ -514,6 +514,23 @@ class XCX121XPVHelper : public XCBaseHelper // Deconstructor ... ~XCX121XPVHelper() { + // + mInputs.Clean(); + + // + ArrayFree(peaksBuffer); + ArrayFree(valesBuffer); + ArrayFree(sarBuffer); + ArrayFree(cHHBuffer); + ArrayFree(cLLBuffer); + ArrayFree(sHHBuffer); + ArrayFree(sLLBuffer); + ArrayFree(mHHBuffer); + ArrayFree(mLLBuffer); + ArrayFree(lHHBuffer); + ArrayFree(lLLBuffer); + ArrayFree(hHHBuffer); + ArrayFree(hLLBuffer); } // diff --git a/Helpers/x-saherelm.x121.xstr.helper.mq5 b/Helpers/x-saherelm.x121.xstr.helper.mq5 index f559415b..1ac9dcbb 100644 --- a/Helpers/x-saherelm.x121.xstr.helper.mq5 +++ b/Helpers/x-saherelm.x121.xstr.helper.mq5 @@ -354,6 +354,16 @@ class XCX121XSTRHelper : public XCBaseHelper // Deconstructor ... ~XCX121XSTRHelper() { + // + mInputs.Clean(); + + // + ArrayFree(strBuffer); + ArrayFree(atrBuffer); + ArrayFree(strPriceBuffer); + ArrayFree(strUpBuffer); + ArrayFree(strDownBuffer); + ArrayFree(strStateBuffer); } // diff --git a/Helpers/x-saherelm.x121.xvwap.helper.mq5 b/Helpers/x-saherelm.x121.xvwap.helper.mq5 index ef1c17bb..0bd0806e 100644 --- a/Helpers/x-saherelm.x121.xvwap.helper.mq5 +++ b/Helpers/x-saherelm.x121.xvwap.helper.mq5 @@ -463,13 +463,25 @@ class XCX121XVWAPHelper : public XCBaseHelper // Deconstructor ... ~XCX121XVWAPHelper() { + // + mInputs.Clean(); + + // + ArrayFree(vwapFastBuffer); + ArrayFree(vwapMidBuffer); + ArrayFree(vwapSlowBuffer); + ArrayFree(vwapVolumeBuffer); + ArrayFree(vwapPriceBuffer); + ArrayFree(vwapFastStateBuffer); + ArrayFree(vwapMidStateBuffer); + ArrayFree(vwapSlowStateBuffer); } // // Tools ... bool Init( - string symbol, // Trading Symbol - ENUM_TIMEFRAMES period, // Trading Period + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period, // Trading Period X121XVWAPInputs &inputs // Inputs ) { @@ -1032,8 +1044,8 @@ class XCX121XVWAPHelper : public XCBaseHelper // bool GetConditions( X121XVWAPConditions &conditions, // - int barIndex = 0, // - int loopback = 5 // + int barIndex = 0, // + int loopback = 5 // ) { // diff --git a/Helpers/x-saherelm.xcc.helper.mq5 b/Helpers/x-saherelm.xcc.helper.mq5 index 485ce71b..7f7032e0 100644 --- a/Helpers/x-saherelm.xcc.helper.mq5 +++ b/Helpers/x-saherelm.xcc.helper.mq5 @@ -135,19 +135,23 @@ class XCXCCHelper : public XCBaseHelper { // // Public ... -public: + public: // // Props ... // // Constructors ... - XCXCCHelper() : XCBaseHelper(_Symbol, _Period) + XCXCCHelper() + : XCBaseHelper(_Symbol, _Period) { } // // Deconstructor ... - ~XCXCCHelper() {} + ~XCXCCHelper() + { + mInputs.Clean(); + } // // Tools ... @@ -232,10 +236,10 @@ public: // // Protected ... -protected: + protected: // // Private ... -private: + private: // // Props ... XCCInputs mInputs; // Inputs ... diff --git a/Helpers/x-saherelm.xct.helper.mq5 b/Helpers/x-saherelm.xct.helper.mq5 index 2bd7cede..cf4d7f41 100644 --- a/Helpers/x-saherelm.xct.helper.mq5 +++ b/Helpers/x-saherelm.xct.helper.mq5 @@ -138,6 +138,7 @@ class XCXCTHelper : public XCBaseHelper // Deconstructor ... ~XCXCTHelper() { + mInputs.Clean(); } // diff --git a/Libraries/x-saherelm.common.lib.mq5 b/Libraries/x-saherelm.common.lib.mq5 index e8290c68..d76b2224 100644 --- a/Libraries/x-saherelm.common.lib.mq5 +++ b/Libraries/x-saherelm.common.lib.mq5 @@ -7043,8 +7043,8 @@ template void Clean(T &buffer[]) { // - ArrayFree(buffer); ArrayResize(buffer, 0); + ArrayFree(buffer); } template void SpecificClean(T &buffer[]) diff --git a/X121SMCEA/Classes/x-121.smc.base.strategy.class.mq5 b/X121SMCEA/Classes/x-121.smc.base.strategy.class.mq5 index 180f15fe..1b841476 100644 --- a/X121SMCEA/Classes/x-121.smc.base.strategy.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.base.strategy.class.mq5 @@ -44,7 +44,7 @@ class XCX121SMCBaseStrategy : public XCBaseAlert // // Constructor(s) ... - void XCX121SMCBaseStrategy( + XCX121SMCBaseStrategy( // // Base ... string _symbol, // Trading Symbol @@ -61,7 +61,7 @@ class XCX121SMCBaseStrategy : public XCBaseAlert // // Deconstructor ... - void ~XCX121SMCBaseStrategy() + ~XCX121SMCBaseStrategy() { DeInit(); } @@ -500,6 +500,9 @@ class XCX121SMCBaseStrategy : public XCBaseAlert // Waits Until Next Candle if Current Tick has Guard ... mGuardBarTracker.Waits(); + // + ArrayFree(positions); + // return result; } @@ -863,6 +866,9 @@ class XCX121SMCBaseStrategy : public XCBaseAlert { AddObjectIfNotExists(objects[i]); } + + // + ArrayFree(objects); } // @@ -959,6 +965,10 @@ class XCX121SMCBaseStrategy : public XCBaseAlert // delete mPOIDrawer; + // + ArrayFree(mTicks); + ArrayFree(mSignalEventHandlers); + // Destroy(); } 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 d55e6fd3..276f5e8b 100644 --- a/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 @@ -1108,8 +1108,7 @@ class XC121SMCCycleHelper : public XCBase { // delete mX121Helper; - - // + delete mPOIDetector; delete mBarAnalyser; } diff --git a/X121SMCEA/Classes/x-121.smc.x-tradehandler.class.mq5 b/X121SMCEA/Classes/x-121.smc.x-tradehandler.class.mq5 index 1c778b3e..7dfb754f 100644 --- a/X121SMCEA/Classes/x-121.smc.x-tradehandler.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.x-tradehandler.class.mq5 @@ -1628,6 +1628,14 @@ class XC121SMCTradeHandler : public XCBaseAlert // Deconstructor ... ~XC121SMCTradeHandler() { + // + ArrayFree(mData); + ArrayFree(mSymbolInfos); + ArrayFree(mLastExecutedSignals); + + // + delete mDrawer; + // delete mTrader; delete mCollector; @@ -3882,7 +3890,6 @@ class XC121SMCTradeHandler : public XCBaseAlert double mHedgeingMinRequiredProfitPerVolumeStep; // Minimum Required Profit Per Volume Step for Hedging ... // - XCBarAnalyser mBarAnalyser; XCPOIDrawer *mDrawer; // diff --git a/X121SMCEA/Experts/x-121.smc.expert.class.mq5 b/X121SMCEA/Experts/x-121.smc.expert.class.mq5 index 6652c94c..547c215d 100644 --- a/X121SMCEA/Experts/x-121.smc.expert.class.mq5 +++ b/X121SMCEA/Experts/x-121.smc.expert.class.mq5 @@ -55,6 +55,19 @@ class XC121SMCExpert : public XCBaseExpert // TOnX121SMCSignal OnSignalEventListener; + // + // Constructor(s) ... + XC121SMCExpert() + { + } + + // + // Deconstructor(s) ... + ~XC121SMCExpert() + { + ArrayFree(mStrategies); + } + // // Getter(s) / Setter(s) ... @@ -2306,6 +2319,9 @@ class XC121SMCExpert : public XCBaseExpert } } } + + // + Clean(guards); } // diff --git a/X121SMCEA/Libraries/x-121.smc.guard.lib.mq5 b/X121SMCEA/Libraries/x-121.smc.guard.lib.mq5 index 10afd58e..5b6988ad 100644 --- a/X121SMCEA/Libraries/x-121.smc.guard.lib.mq5 +++ b/X121SMCEA/Libraries/x-121.smc.guard.lib.mq5 @@ -348,6 +348,8 @@ bool DetectX121SMCGuards( bool isConsolidationZoneBreakedUp = false; bool isConsolidationZoneBreakedDown = false; bool hasConsolidationZone = x121SMCConsolidationZone.IsValid(); + + // if (!hasConsolidationZone) { // @@ -414,14 +416,16 @@ bool DetectX121SMCGuards( // Decision ... double decisionPriceZoneUpper = 0; double decisionPriceZoneLower = 0; - bool isValidDecisionPriceZoneForPeak = false; - bool isValidDecisionPriceZoneForVale = false; + bool isDecisionPriceZoneBearish = false; + bool isDecisionPriceZoneBullish = false; + bool isDecisionPriceZoneValidForPeak = false; + bool isDecisionPriceZoneValidForVale = false; bool isDecisionPriceZoneLowerRejected = false; bool isDecisionPriceZoneUpperRejected = false; bool isDecisionPriceZoneUpperBreakedUp = false; bool isDecisionPriceZoneLowerBreakedDown = false; bool hasDecisionPriceZone = x121SMCDecisionPriceZone.IsValid(); - + // if (!hasDecisionPriceZone) { @@ -443,24 +447,28 @@ bool DetectX121SMCGuards( decisionPriceZoneLower // ); + // + isDecisionPriceZoneBearish = x121SMCDecisionPriceZone.IsBearish(); + isDecisionPriceZoneBullish = x121SMCDecisionPriceZone.IsBullish(); + + // + XOHCL iBar; + bool isInited = iBar.Init( + symbol, + decisionXConditions.period, + cIndex // + ); + // if (hasBoundary) { // - XOHCL iBar; - bool isInited = iBar.Init( - symbol, - decisionXConditions.period, - cIndex // - ); - - // - isValidDecisionPriceZoneForPeak = + isDecisionPriceZoneValidForPeak = decisionXConditions.peaksBuffer[1] <= decisionPriceZoneUpper && decisionXConditions.peaksBuffer[1] >= decisionPriceZoneLower; // - isValidDecisionPriceZoneForVale = + isDecisionPriceZoneValidForVale = decisionXConditions.valesBuffer[1] <= decisionPriceZoneUpper && decisionXConditions.valesBuffer[1] >= decisionPriceZoneLower; @@ -500,20 +508,55 @@ bool DetectX121SMCGuards( iBar // ); } + + // + // Clear Price Zone ... + bool canReset = + // + (!isInited || + !hasBoundary) + // + || + // + (isInited && + hasBoundary && + (iBar.high < decisionPriceZoneLower || + iBar.low > decisionPriceZoneUpper)) + // + ; + if (canReset) + { + // + x121SMCDecisionPriceZone.Clean(); + + // + decisionPriceZoneUpper = 0; + decisionPriceZoneLower = 0; + isDecisionPriceZoneBearish = false; + isDecisionPriceZoneBullish = false; + isDecisionPriceZoneValidForPeak = false; + isDecisionPriceZoneValidForVale = false; + isDecisionPriceZoneLowerRejected = false; + isDecisionPriceZoneUpperRejected = false; + isDecisionPriceZoneUpperBreakedUp = false; + isDecisionPriceZoneLowerBreakedDown = false; + } } // // Analyse ... double analysePriceZoneUpper = 0; double analysePriceZoneLower = 0; - bool isValidAnalysePriceZoneForPeak = false; - bool isValidAnalysePriceZoneForVale = false; + bool isAnalysePriceZoneBearish = false; + bool isAnalysePriceZoneBullish = false; + bool isAnalysePriceZoneValidForPeak = false; + bool isAnalysePriceZoneValidForVale = false; bool isAnalysePriceZoneLowerRejected = false; bool isAnalysePriceZoneUpperRejected = false; bool isAnalysePriceZoneUpperBreakedUp = false; bool isAnalysePriceZoneLowerBreakedDown = false; bool hasAnalysePriceZone = x121SMCAnalysePriceZone.IsValid(); - + // if (!hasAnalysePriceZone) { @@ -535,24 +578,28 @@ bool DetectX121SMCGuards( analysePriceZoneLower // ); + // + isAnalysePriceZoneBearish = x121SMCAnalysePriceZone.IsBearish(); + isAnalysePriceZoneBullish = x121SMCAnalysePriceZone.IsBullish(); + + // + XOHCL iBar; + bool isInited = iBar.Init( + symbol, + analyseXConditions.period, + cIndex // + ); + // if (hasBoundary) { // - XOHCL iBar; - bool isInited = iBar.Init( - symbol, - analyseXConditions.period, - cIndex // - ); - - // - isValidAnalysePriceZoneForPeak = + isAnalysePriceZoneValidForPeak = analyseXConditions.peaksBuffer[1] <= analysePriceZoneUpper && analyseXConditions.peaksBuffer[1] >= analysePriceZoneLower; // - isValidAnalysePriceZoneForVale = + isAnalysePriceZoneValidForVale = analyseXConditions.valesBuffer[1] <= analysePriceZoneUpper && analyseXConditions.valesBuffer[1] >= analysePriceZoneLower; @@ -592,20 +639,55 @@ bool DetectX121SMCGuards( iBar // ); } + + // + // Clear Price Zone ... + bool canReset = + // + (!isInited || + !hasBoundary) + // + || + // + (isInited && + hasBoundary && + (iBar.high < analysePriceZoneLower || + iBar.low > analysePriceZoneUpper)) + // + ; + if (canReset) + { + // + x121SMCAnalysePriceZone.Clean(); + + // + analysePriceZoneUpper = 0; + analysePriceZoneLower = 0; + isAnalysePriceZoneBearish = false; + isAnalysePriceZoneBullish = false; + isAnalysePriceZoneValidForPeak = false; + isAnalysePriceZoneValidForVale = false; + isAnalysePriceZoneLowerRejected = false; + isAnalysePriceZoneUpperRejected = false; + isAnalysePriceZoneUpperBreakedUp = false; + isAnalysePriceZoneLowerBreakedDown = false; + } } // // Verification ... double verificationPriceZoneUpper = 0; double verificationPriceZoneLower = 0; - bool isValidVerificationPriceZoneForPeak = false; - bool isValidVerificationPriceZoneForVale = false; + bool isVerificationPriceZoneBearish = false; + bool isVerificationPriceZoneBullish = false; + bool isVerificationPriceZoneValidForPeak = false; + bool isVerificationPriceZoneValidForVale = false; bool isVerificationPriceZoneLowerRejected = false; bool isVerificationPriceZoneUpperRejected = false; bool isVerificationPriceZoneUpperBreakedUp = false; bool isVerificationPriceZoneLowerBreakedDown = false; bool hasVerificationPriceZone = x121SMCVerificationPriceZone.IsValid(); - + // if (!hasVerificationPriceZone) { @@ -627,24 +709,28 @@ bool DetectX121SMCGuards( verificationPriceZoneLower // ); + // + isVerificationPriceZoneBearish = x121SMCVerificationPriceZone.IsBearish(); + isVerificationPriceZoneBullish = x121SMCVerificationPriceZone.IsBullish(); + + // + XOHCL iBar; + bool isInited = iBar.Init( + symbol, + verificationXConditions.period, + cIndex // + ); + // if (hasBoundary) { // - XOHCL iBar; - bool isInited = iBar.Init( - symbol, - verificationXConditions.period, - cIndex // - ); - - // - isValidVerificationPriceZoneForPeak = + isVerificationPriceZoneValidForPeak = verificationXConditions.peaksBuffer[1] <= verificationPriceZoneUpper && verificationXConditions.peaksBuffer[1] >= verificationPriceZoneLower; // - isValidVerificationPriceZoneForVale = + isVerificationPriceZoneValidForVale = verificationXConditions.valesBuffer[1] <= verificationPriceZoneUpper && verificationXConditions.valesBuffer[1] >= verificationPriceZoneLower; @@ -684,6 +770,39 @@ bool DetectX121SMCGuards( iBar // ); } + + // + // Clear Price Zone ... + bool canReset = + // + (!isInited || + !hasBoundary) + // + || + // + (isInited && + hasBoundary && + (iBar.high < verificationPriceZoneLower || + iBar.low > verificationPriceZoneUpper)) + // + ; + if (canReset) + { + // + x121SMCVerificationPriceZone.Clean(); + + // + verificationPriceZoneUpper = 0; + verificationPriceZoneLower = 0; + isVerificationPriceZoneBearish = false; + isVerificationPriceZoneBullish = false; + isVerificationPriceZoneValidForPeak = false; + isVerificationPriceZoneValidForVale = false; + isVerificationPriceZoneLowerRejected = false; + isVerificationPriceZoneUpperRejected = false; + isVerificationPriceZoneUpperBreakedUp = false; + isVerificationPriceZoneLowerBreakedDown = false; + } } // @@ -691,7 +810,87 @@ bool DetectX121SMCGuards( // // Close ... - // TODO: Implement Force Close Position ... + + // + double tpCloseDiff = (15 * points); + for (int i = 0; i < count; i++) + { + // + XPosition iPosition = ownPositions[i]; + + // + // Position Must be In Profit ... + if (iPosition.profit <= 0) + { + continue; + } + + // + bool isPricePassed = MathAbs(iPosition.tp - iPosition.price) <= tpCloseDiff; + if (!isPricePassed) + { + continue; + } + + // + bool isLong = IsLong(iPosition.type); + + // + bool iHasGuard = + // + isLong + ? // + (hasDecisionPriceZone && + isDecisionPriceZoneBearish && + isDecisionPriceZoneValidForPeak) + // + || + // + (hasAnalysePriceZone && + isAnalysePriceZoneBearish && + isAnalysePriceZoneValidForPeak) + // + || + // + (hasVerificationPriceZone && + isVerificationPriceZoneBearish && + isVerificationPriceZoneValidForPeak) + : // + (hasDecisionPriceZone && + isDecisionPriceZoneBullish && + isDecisionPriceZoneValidForVale) + // + || + // + (hasAnalysePriceZone && + isAnalysePriceZoneBullish && + isAnalysePriceZoneValidForVale) + // + || + // + (hasVerificationPriceZone && + isVerificationPriceZoneBullish && + isVerificationPriceZoneValidForVale) + // + ; + if (iHasGuard) + { + // + X121SMCGuard iGuard; + + // + iGuard.time = cTime; + iGuard.symbol = symbol; + iGuard.provider = provider; + iGuard.action = X_121_SMC_GUARD_ACTION_CLOSE; + + // + AddGuard( + iGuard, + guards // + ); + } + } // // Close All ... @@ -699,13 +898,15 @@ bool DetectX121SMCGuards( // MqlDateTime mDate; bool hasDate = TimeCurrent(mDate); - if (hasDate) { + if (hasDate) + { // ENUM_X_WEEK_DAYS dayOfWeek = GetDayOfWeek(); // bool isWeekend = dayOfWeek == X_WEEK_DAY_FRIDAY; - if (isWeekend && mDate.hour == 23 && mDate.min == 30) { + if (isWeekend && mDate.hour == 23 && mDate.min == 30) + { // X121SMCGuard guard; @@ -720,7 +921,7 @@ bool DetectX121SMCGuards( guard, guards // ); - } + } } // @@ -797,6 +998,20 @@ bool DetectX121SMCGuards( hasTriggerBearishTrend || !hasDecisionBullishTrend // + // (hasAnalysePriceZone && + // isAnalysePriceZoneBearish && + // isAnalysePriceZoneValidForPeak && + // (isAnalysePriceZoneUpperRejected || + // isAnalysePriceZoneLowerBreakedDown)) + // // + // || + // // + // (hasVerificationPriceZone && + // isVerificationPriceZoneBearish && + // isVerificationPriceZoneValidForPeak && + // (isVerificationPriceZoneUpperRejected || + // isVerificationPriceZoneLowerBreakedDown)) + // ; // @@ -839,6 +1054,20 @@ bool DetectX121SMCGuards( hasTriggerBullishTrend || !hasDecisionBearishTrend // + // (hasAnalysePriceZone && + // isAnalysePriceZoneBullish && + // isAnalysePriceZoneValidForVale && + // (isAnalysePriceZoneLowerRejected || + // isAnalysePriceZoneUpperBreakedUp)) + // // + // || + // // + // (hasVerificationPriceZone && + // isVerificationPriceZoneBullish && + // isVerificationPriceZoneValidForVale && + // (isVerificationPriceZoneLowerRejected || + // isVerificationPriceZoneUpperBreakedUp)) + // ; // @@ -879,14 +1108,54 @@ bool DetectX121SMCGuards( if (hasLongs) { // - bool hasGuard = - // + bool hasConsolidationGuard = (hasConsolidationZone && isConsolidationZoneBreaked && - isConsolidationZoneBreakedUp) + isConsolidationZoneBreakedUp); + + // + bool hasDecisionPriceZoneGuard = + (hasDecisionPriceZone && + isDecisionPriceZoneBullish && + isDecisionPriceZoneValidForVale && + isDecisionPriceZoneUpperBreakedUp); + + // + bool hasAnalysePriceZoneGuard = + (hasAnalysePriceZone && + isAnalysePriceZoneBullish && + isAnalysePriceZoneValidForVale && + isAnalysePriceZoneUpperBreakedUp); + + // + bool hasVerificationPriceZoneGuard = + (hasVerificationPriceZone && + isVerificationPriceZoneBullish && + isVerificationPriceZoneValidForVale && + isVerificationPriceZoneUpperBreakedUp); + + // + bool hasGuard = + // + hasConsolidationGuard || + hasDecisionPriceZoneGuard || + hasAnalysePriceZoneGuard || + hasVerificationPriceZoneGuard // ; + // + double guardStop = + hasConsolidationGuard + ? consolidationZoneLower + : hasDecisionPriceZoneGuard + ? decisionPriceZoneLower + : hasAnalysePriceZoneGuard + ? analysePriceZoneLower + : hasVerificationPriceZoneGuard + ? verificationPriceZoneLower + : 0; + // if (hasGuard) { @@ -905,14 +1174,14 @@ bool DetectX121SMCGuards( // // Price Must Greater than Zone Lower ... - if (iPosition.price < consolidationZoneLower) + if (iPosition.price < guardStop) { continue; } // // Position Entry Must Lesser than Zone Lower ... - if (iPosition.entry > consolidationZoneLower) + if (iPosition.entry > guardStop) { continue; } @@ -920,7 +1189,7 @@ bool DetectX121SMCGuards( // // Position SL must be Zero or Lesser than Zone Lower ... if (iPosition.sl != 0 && - iPosition.sl > consolidationZoneLower) + iPosition.sl > guardStop) { continue; } @@ -938,7 +1207,7 @@ bool DetectX121SMCGuards( iGuard.ticket = iPosition.ticket; // - iGuard.sl = consolidationZoneLower; + iGuard.sl = guardStop; // AddGuard( @@ -953,14 +1222,54 @@ bool DetectX121SMCGuards( if (hasShorts) { // - bool hasGuard = - // + bool hasConsolidationGuard = (hasConsolidationZone && isConsolidationZoneBreaked && - isConsolidationZoneBreakedDown) + isConsolidationZoneBreakedDown); + + // + bool hasDecisionPriceZoneGuard = + (hasDecisionPriceZone && + isDecisionPriceZoneBearish && + isDecisionPriceZoneValidForPeak && + isDecisionPriceZoneLowerBreakedDown); + + // + bool hasAnalysePriceZoneGuard = + (hasAnalysePriceZone && + isAnalysePriceZoneBearish && + isAnalysePriceZoneValidForPeak && + isAnalysePriceZoneLowerBreakedDown); + + // + bool hasVerificationPriceZoneGuard = + (hasVerificationPriceZone && + isVerificationPriceZoneBearish && + isVerificationPriceZoneValidForPeak && + isVerificationPriceZoneLowerBreakedDown); + + // + bool hasGuard = + // + hasConsolidationGuard || + hasDecisionPriceZoneGuard || + hasAnalysePriceZoneGuard || + hasVerificationPriceZoneGuard // ; + // + double guardStop = + hasConsolidationGuard + ? consolidationZoneUpper + : hasDecisionPriceZoneGuard + ? decisionPriceZoneUpper + : hasAnalysePriceZoneGuard + ? analysePriceZoneUpper + : hasVerificationPriceZoneGuard + ? verificationPriceZoneUpper + : 0; + // if (hasGuard) { @@ -979,14 +1288,14 @@ bool DetectX121SMCGuards( // // Price Must Lesser than Zone Upper ... - if (iPosition.price > consolidationZoneUpper) + if (iPosition.price > guardStop) { continue; } // // Position Entry Must Greater than Zone Upper ... - if (iPosition.entry < consolidationZoneUpper) + if (iPosition.entry < guardStop) { continue; } @@ -994,7 +1303,7 @@ bool DetectX121SMCGuards( // // Position SL must be Zero or Greater than Zone Upper ... if (iPosition.sl != 0 && - iPosition.sl < consolidationZoneUpper) + iPosition.sl < guardStop) { continue; } @@ -1012,7 +1321,7 @@ bool DetectX121SMCGuards( iGuard.ticket = iPosition.ticket; // - iGuard.sl = consolidationZoneUpper; + iGuard.sl = guardStop; // AddGuard( @@ -1025,22 +1334,183 @@ bool DetectX121SMCGuards( // // Trail Target ... - // TODO: Implement Target Trail ... // if (hasLongs) { + // + bool hasAnalyseGuard = + // + (hasAnalysePriceZone && + isAnalysePriceZoneValidForPeak && + isAnalysePriceZoneUpperRejected) + // + ; + + // + bool hasVerificationGuard = + // + (hasVerificationPriceZone && + isVerificationPriceZoneValidForPeak && + isVerificationPriceZoneUpperRejected) + // + ; + + // + bool hasGuard = + // + hasAnalyseGuard || + hasVerificationGuard + // + ; + + // + double guardTP = + hasAnalyseGuard + ? analysePriceZoneUpper + : hasVerificationGuard + ? verificationPriceZoneUpper + : 0; + + // + if (hasGuard) + { + // + for (int i = 0; i < longsCount; i++) + { + // + XPosition iPosition = ownLongPositions[i]; + + // + // Position Must Be In Profit ... + if (iPosition.profit <= 0) + { + continue; + } + + // + X121SMCGuard iGuard; + + // + iGuard.time = cTime; + iGuard.symbol = symbol; + iGuard.provider = provider; + iGuard.action = X_121_SMC_GUARD_ACTION_TRAIL_TARGET; + + // + iGuard.ticket = iPosition.ticket; + + // + iGuard.tp = guardTP; + + // + AddGuard( + iGuard, + guards // + ); + } + } } // if (hasShorts) { + // + bool hasAnalyseGuard = + // + (hasAnalysePriceZone && + isAnalysePriceZoneValidForVale && + isAnalysePriceZoneLowerRejected) + // + ; + + // + bool hasVerificationGuard = + // + (hasVerificationPriceZone && + isVerificationPriceZoneValidForVale && + isVerificationPriceZoneLowerRejected) + // + ; + + // + bool hasGuard = + // + hasAnalyseGuard || + hasVerificationGuard + // + ; + + // + double guardTP = + hasAnalyseGuard + ? analysePriceZoneLower + : hasVerificationGuard + ? verificationPriceZoneLower + : 0; + + // + if (hasGuard) + { + // + for (int i = 0; i < shortsCount; i++) + { + // + XPosition iPosition = ownShortPositions[i]; + + // + // Position Must Be In Profit ... + if (iPosition.profit <= 0) + { + continue; + } + + // + X121SMCGuard iGuard; + + // + iGuard.time = cTime; + iGuard.symbol = symbol; + iGuard.provider = provider; + iGuard.action = X_121_SMC_GUARD_ACTION_TRAIL_TARGET; + + // + iGuard.ticket = iPosition.ticket; + + // + iGuard.tp = guardTP; + + // + AddGuard( + iGuard, + guards // + ); + } + } } // // Hedge ... // TODO: Implement Hedge ... + // + // Release Arrays ... + ArrayFree(ownPositions); + ArrayFree(ownLongPositions); + ArrayFree(ownShortPositions); + ArrayFree(triggerPoiEvents); + ArrayFree(triggerCycleEvents); + ArrayFree(decisionPoiEvents); + ArrayFree(decisionCycleEvents); + ArrayFree(analysePoiEvents); + ArrayFree(analyseCycleEvents); + ArrayFree(verificationPoiEvents); + ArrayFree(verificationCycleEvents); + ArrayFree(consolidationPoiEvents); + ArrayFree(consolidationCycleEvents); + ArrayFree(visionPoiEvents); + ArrayFree(visionCycleEvents); + // count = ArraySize(guards); result = IsValidSize(count); diff --git a/X121SMCEA/Signals/x-121.smc.xpz.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xpz.signal.lib.mq5 index 1277f73c..2db1a801 100644 --- a/X121SMCEA/Signals/x-121.smc.xpz.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xpz.signal.lib.mq5 @@ -823,6 +823,23 @@ bool DetectX121SMCXPZSiganlSetup( isBearish; if (!result) { + + // + // Cleanup Arrays ... + ArrayFree(triggerPoiEvents); + ArrayFree(triggerCycleEvents); + ArrayFree(decisionPoiEvents); + ArrayFree(decisionCycleEvents); + ArrayFree(analysePoiEvents); + ArrayFree(analyseCycleEvents); + ArrayFree(verificationPoiEvents); + ArrayFree(verificationCycleEvents); + ArrayFree(consolidationPoiEvents); + ArrayFree(consolidationCycleEvents); + ArrayFree(visionPoiEvents); + ArrayFree(visionCycleEvents); + + // return result; } @@ -833,6 +850,21 @@ bool DetectX121SMCXPZSiganlSetup( ? X_DIRECTION_BULLISH : X_DIRECTION_BEARISH; + // + // Cleanup Arrays ... + ArrayFree(triggerPoiEvents); + ArrayFree(triggerCycleEvents); + ArrayFree(decisionPoiEvents); + ArrayFree(decisionCycleEvents); + ArrayFree(analysePoiEvents); + ArrayFree(analyseCycleEvents); + ArrayFree(verificationPoiEvents); + ArrayFree(verificationCycleEvents); + ArrayFree(consolidationPoiEvents); + ArrayFree(consolidationCycleEvents); + ArrayFree(visionPoiEvents); + ArrayFree(visionCycleEvents); + // return result; } @@ -1193,6 +1225,21 @@ bool DetectX121SMCXPZSiganlTrigger( conditions.Clean(); } + // + // Cleanup Arrays ... + ArrayFree(triggerPoiEvents); + ArrayFree(triggerCycleEvents); + ArrayFree(decisionPoiEvents); + ArrayFree(decisionCycleEvents); + ArrayFree(analysePoiEvents); + ArrayFree(analyseCycleEvents); + ArrayFree(verificationPoiEvents); + ArrayFree(verificationCycleEvents); + ArrayFree(consolidationPoiEvents); + ArrayFree(consolidationCycleEvents); + ArrayFree(visionPoiEvents); + ArrayFree(visionCycleEvents); + // return result; } @@ -1488,6 +1535,21 @@ bool DetectX121SMCXPZSiganlTrigger( ? X_POSITION_TYPE_LONG : X_POSITION_TYPE_SHORT; + // + // Cleanup Arrays ... + ArrayFree(triggerPoiEvents); + ArrayFree(triggerCycleEvents); + ArrayFree(decisionPoiEvents); + ArrayFree(decisionCycleEvents); + ArrayFree(analysePoiEvents); + ArrayFree(analyseCycleEvents); + ArrayFree(verificationPoiEvents); + ArrayFree(verificationCycleEvents); + ArrayFree(consolidationPoiEvents); + ArrayFree(consolidationCycleEvents); + ArrayFree(visionPoiEvents); + ArrayFree(visionCycleEvents); + // return result; } diff --git a/X121SMCEA/Signals/x-121.smc.xstrpv.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xstrpv.signal.lib.mq5 index fbf6b715..ee89de27 100644 --- a/X121SMCEA/Signals/x-121.smc.xstrpv.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xstrpv.signal.lib.mq5 @@ -883,6 +883,22 @@ bool DetectX121SMCXSTRPVSiganlSetup( isBearish; if (!result) { + // + // Cleanup Arrays ... + ArrayFree(triggerPoiEvents); + ArrayFree(triggerCycleEvents); + ArrayFree(decisionPoiEvents); + ArrayFree(decisionCycleEvents); + ArrayFree(analysePoiEvents); + ArrayFree(analyseCycleEvents); + ArrayFree(verificationPoiEvents); + ArrayFree(verificationCycleEvents); + ArrayFree(consolidationPoiEvents); + ArrayFree(consolidationCycleEvents); + ArrayFree(visionPoiEvents); + ArrayFree(visionCycleEvents); + + // return result; } @@ -893,6 +909,21 @@ bool DetectX121SMCXSTRPVSiganlSetup( ? X_DIRECTION_BULLISH : X_DIRECTION_BEARISH; + // + // Cleanup Arrays ... + ArrayFree(triggerPoiEvents); + ArrayFree(triggerCycleEvents); + ArrayFree(decisionPoiEvents); + ArrayFree(decisionCycleEvents); + ArrayFree(analysePoiEvents); + ArrayFree(analyseCycleEvents); + ArrayFree(verificationPoiEvents); + ArrayFree(verificationCycleEvents); + ArrayFree(consolidationPoiEvents); + ArrayFree(consolidationCycleEvents); + ArrayFree(visionPoiEvents); + ArrayFree(visionCycleEvents); + // return result; } @@ -1253,6 +1284,21 @@ bool DetectX121SMCXSTRPVSiganlTrigger( conditions.Clean(); } + // + // Cleanup Arrays ... + ArrayFree(triggerPoiEvents); + ArrayFree(triggerCycleEvents); + ArrayFree(decisionPoiEvents); + ArrayFree(decisionCycleEvents); + ArrayFree(analysePoiEvents); + ArrayFree(analyseCycleEvents); + ArrayFree(verificationPoiEvents); + ArrayFree(verificationCycleEvents); + ArrayFree(consolidationPoiEvents); + ArrayFree(consolidationCycleEvents); + ArrayFree(visionPoiEvents); + ArrayFree(visionCycleEvents); + // return result; } @@ -1548,6 +1594,21 @@ bool DetectX121SMCXSTRPVSiganlTrigger( ? X_POSITION_TYPE_LONG : X_POSITION_TYPE_SHORT; + // + // Cleanup Arrays ... + ArrayFree(triggerPoiEvents); + ArrayFree(triggerCycleEvents); + ArrayFree(decisionPoiEvents); + ArrayFree(decisionCycleEvents); + ArrayFree(analysePoiEvents); + ArrayFree(analyseCycleEvents); + ArrayFree(verificationPoiEvents); + ArrayFree(verificationCycleEvents); + ArrayFree(consolidationPoiEvents); + ArrayFree(consolidationCycleEvents); + ArrayFree(visionPoiEvents); + ArrayFree(visionCycleEvents); + // return result; } diff --git a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 index b9f19669..427aa87b 100644 --- a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 @@ -27,7 +27,6 @@ #include "../Classes/x-121.smc.market.cycle.helper.class.mq5" // -#include "../Signals/x-121.smc.test.signal.lib.mq5" #include "../Signals/x-121.smc.xpz.signal.lib.mq5" #include "../Signals/x-121.smc.xstrpv.signal.lib.mq5" @@ -43,7 +42,6 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy public: // // Props ... - bool useTestSignal; bool useXPZSignal; bool useXSTRPVSignal; @@ -64,6 +62,10 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // Deconstructur ... void ~XCX121SMCStrategy() { + // + Destroy(); + ArrayFree(mXPZConditionsCollection); + ArrayFree(mXSTRPVConditionsCollection); } // @@ -188,19 +190,9 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy bool hasSignal = false; // - bool hasTestSignal = false; bool hasXPZSignal = false; bool hasXSTRPVSignal = false; - // - // Test Signal ... - if (useTestSignal && !hasSignal) - { - // - hasTestSignal = DetectTestSignal(conditions); - hasSignal = hasTestSignal; - } - // // XOBGPV Signal ... if (useXPZSignal && !hasSignal) @@ -374,12 +366,6 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy return result; } - // - // XTEST Guard Detection ... - if (useTestSignal) - { - } - // // XSTRPV Guard Detection ... if (useXSTRPVSignal) @@ -452,122 +438,6 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // // Signalling Functions ... - // - // Test Signal ... - X121SMCStrategyTestSignalConditions mTestConditions; - bool DetectTestSignal( - 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_XTEST; - string providerStr = ToString(provider); - - // - // Detect Setup Conditions ... - datetime setupTime = mTestConditions.setupTime; - bool isSetuped = mTestConditions.IsSetuped(); - ENUM_X_DIRECTION setupDir = mTestConditions.dir; - if (!isSetuped) - { - // - // Detect Signal Setup ... - isSetuped = DetectX121SMCTestSiganlSetup( - symbol, - period, - mTestConditions, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - setupDir = mTestConditions.dir; - setupTime = mTestConditions.setupTime; - } - - // - result = isSetuped; - if (!result) - { - return result; - } - - // - // Detect Trigger Conditions ... - bool canTrigger = mTestConditions.CanTrigger(); - datetime triggerTime = mTestConditions.triggerTime; - if (!canTrigger) - { - // - // Detect Signal Trigger ... - canTrigger = DetectX121SMCTestSiganlTrigger( - mTestConditions, - symbol, - period, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - result = canTrigger; - if (!result) - { - return result; - } - - // - triggerTime = mTestConditions.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 = mTestConditions.sl; - conditions.target = mTestConditions.target; - - // - mTestConditions.Clean(); - - // - return result; - } - // // XSTRPV Signal ... bool DetectXSTRPVSignal( @@ -1035,7 +905,6 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy void InitialHelpers() { // - useTestSignal = false; useXPZSignal = true; useXSTRPVSignal = true;