diff --git a/Classes/x-saherelm.x-poi.class.mq5 b/Classes/x-saherelm.x-poi.class.mq5 index 4e89e823..df3fe2c1 100644 --- a/Classes/x-saherelm.x-poi.class.mq5 +++ b/Classes/x-saherelm.x-poi.class.mq5 @@ -1220,22 +1220,6 @@ 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); } /** @@ -1250,11 +1234,7 @@ class XCPOIDetector : public XCBaseAlert */ void DestroyEventListeners() { - // Clean(mEventListeners); - - // - ArrayFree(mEventListeners); } // diff --git a/Classes/x-saherelm.x-poi.drawer.class.mq5 b/Classes/x-saherelm.x-poi.drawer.class.mq5 index 3b881215..f0b0cb65 100644 --- a/Classes/x-saherelm.x-poi.drawer.class.mq5 +++ b/Classes/x-saherelm.x-poi.drawer.class.mq5 @@ -45,7 +45,7 @@ class XCPOIDrawer : public XCBase void ~XCPOIDrawer() { // - ArrayFree(mTicksZoneSpecs); + Clean(mTicksZoneSpecs); } // @@ -4603,7 +4603,7 @@ class XCPOIDrawer : public XCBase ); // - ArrayFree(stateObjects); + Clean(stateObjects); } // diff --git a/Classes/x-saherelm.x-trade.class.mq5 b/Classes/x-saherelm.x-trade.class.mq5 index 64599b8e..1cdf0caf 100644 --- a/Classes/x-saherelm.x-trade.class.mq5 +++ b/Classes/x-saherelm.x-trade.class.mq5 @@ -598,17 +598,6 @@ 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/Documents/BKP/1/x-121.smc.xobpv.signal.orig.old.lib.mq5 b/Documents/BKP/1/x-121.smc.xobpv.signal.orig.old.lib.mq5 index 0da02f7a..f8bd6a24 100644 --- a/Documents/BKP/1/x-121.smc.xobpv.signal.orig.old.lib.mq5 +++ b/Documents/BKP/1/x-121.smc.xobpv.signal.orig.old.lib.mq5 @@ -1247,18 +1247,18 @@ bool DetectX121SMCXOBPVSignalSetup( { // // 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); + Clean(triggerPoiEvents); + Clean(triggerCycleEvents); + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + Clean(analysePoiEvents); + Clean(analyseCycleEvents); + Clean(verificationPoiEvents); + Clean(verificationCycleEvents); + Clean(consolidationPoiEvents); + Clean(consolidationCycleEvents); + Clean(visionPoiEvents); + Clean(visionCycleEvents); // return result; @@ -1273,18 +1273,18 @@ bool DetectX121SMCXOBPVSignalSetup( // // 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); + Clean(triggerPoiEvents); + Clean(triggerCycleEvents); + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + Clean(analysePoiEvents); + Clean(analyseCycleEvents); + Clean(verificationPoiEvents); + Clean(verificationCycleEvents); + Clean(consolidationPoiEvents); + Clean(consolidationCycleEvents); + Clean(visionPoiEvents); + Clean(visionCycleEvents); // return result; @@ -1505,8 +1505,8 @@ bool DetectX121SMCXOBPVSignalTrigger( // // Cleanup Arrays ... - ArrayFree(decisionPoiEvents); - ArrayFree(decisionCycleEvents); + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); // return result; @@ -1553,8 +1553,8 @@ bool DetectX121SMCXOBPVSignalTrigger( // // Cleanup Arrays ... - ArrayFree(decisionPoiEvents); - ArrayFree(decisionCycleEvents); + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); // return result; diff --git a/Helpers/x-saherelm.x121.xatr.helper.mq5 b/Helpers/x-saherelm.x121.xatr.helper.mq5 index 8ee75d0c..a76d071e 100644 --- a/Helpers/x-saherelm.x121.xatr.helper.mq5 +++ b/Helpers/x-saherelm.x121.xatr.helper.mq5 @@ -476,12 +476,12 @@ class XCX121XATRHelper : public XCBaseHelper ~XCX121XATRHelper() { // - ArrayFree(rsiBuffer); - ArrayFree(atrUpperBuffer); - ArrayFree(atrLowerBuffer); - ArrayFree(atrBuffer); - ArrayFree(atrUpperRawBuffer); - ArrayFree(atrLowerRawBuffer); + Clean(rsiBuffer); + Clean(atrUpperBuffer); + Clean(atrLowerBuffer); + Clean(atrBuffer); + Clean(atrUpperRawBuffer); + Clean(atrLowerRawBuffer); // mInputs.Clean(); diff --git a/Helpers/x-saherelm.x121.xche.helper.mq5 b/Helpers/x-saherelm.x121.xche.helper.mq5 index cdb73c2a..e2f25ae8 100644 --- a/Helpers/x-saherelm.x121.xche.helper.mq5 +++ b/Helpers/x-saherelm.x121.xche.helper.mq5 @@ -438,14 +438,14 @@ class XCX121XCHEHelper : public XCBaseHelper mInputs.Clean(); // - ArrayFree(le1Buffer); - ArrayFree(se1Buffer); - ArrayFree(le2Buffer); - ArrayFree(se2Buffer); - ArrayFree(le1StartBuffer); - ArrayFree(se1StartBuffer); - ArrayFree(le2StartBuffer); - ArrayFree(se2StartBuffer); + Clean(le1Buffer); + Clean(se1Buffer); + Clean(le2Buffer); + Clean(se2Buffer); + Clean(le1StartBuffer); + Clean(se1StartBuffer); + Clean(le2StartBuffer); + Clean(se2StartBuffer); } // diff --git a/Helpers/x-saherelm.x121.xdon.helper.mq5 b/Helpers/x-saherelm.x121.xdon.helper.mq5 index d56bc3db..e14f0916 100644 --- a/Helpers/x-saherelm.x121.xdon.helper.mq5 +++ b/Helpers/x-saherelm.x121.xdon.helper.mq5 @@ -425,14 +425,14 @@ class XCX121XDONHelper : public XCBaseHelper mInputs.Clean(); // - ArrayFree(donOpenUpperBuffer); - ArrayFree(donOpenLowerBuffer); - ArrayFree(donHighUpperBuffer); - ArrayFree(donHighLowerBuffer); - ArrayFree(donLowUpperBuffer); - ArrayFree(donLowLowerBuffer); - ArrayFree(donCloseUpperBuffer); - ArrayFree(donCloseLowerBuffer); + Clean(donOpenUpperBuffer); + Clean(donOpenLowerBuffer); + Clean(donHighUpperBuffer); + Clean(donHighLowerBuffer); + Clean(donLowUpperBuffer); + Clean(donLowLowerBuffer); + Clean(donCloseUpperBuffer); + Clean(donCloseLowerBuffer); } // diff --git a/Helpers/x-saherelm.x121.xhk.helper.mq5 b/Helpers/x-saherelm.x121.xhk.helper.mq5 index 03160cf0..6ba2114d 100644 --- a/Helpers/x-saherelm.x121.xhk.helper.mq5 +++ b/Helpers/x-saherelm.x121.xhk.helper.mq5 @@ -430,14 +430,14 @@ class XCX121XHKHelper : public XCBaseHelper ~XCX121XHKHelper() { // - ArrayFree(xhkRawOpenBuffer); - ArrayFree(xhkRawHighBuffer); - ArrayFree(xhkRawLowBuffer); - ArrayFree(xhkRawCloseBuffer); - ArrayFree(xhkSMOpenBuffer); - ArrayFree(xhkSMHighBuffer); - ArrayFree(xhkSMLowBuffer); - ArrayFree(xhkSMCloseBuffer); + Clean(xhkRawOpenBuffer); + Clean(xhkRawHighBuffer); + Clean(xhkRawLowBuffer); + Clean(xhkRawCloseBuffer); + Clean(xhkSMOpenBuffer); + Clean(xhkSMHighBuffer); + Clean(xhkSMLowBuffer); + Clean(xhkSMCloseBuffer); // mInputs.Clean(); diff --git a/Helpers/x-saherelm.x121.xpv.helper.mq5 b/Helpers/x-saherelm.x121.xpv.helper.mq5 index 6840ca5c..a89b3718 100644 --- a/Helpers/x-saherelm.x121.xpv.helper.mq5 +++ b/Helpers/x-saherelm.x121.xpv.helper.mq5 @@ -533,19 +533,19 @@ class XCX121XPVHelper : public XCBaseHelper 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); + Clean(peaksBuffer); + Clean(valesBuffer); + Clean(sarBuffer); + Clean(cHHBuffer); + Clean(cLLBuffer); + Clean(sHHBuffer); + Clean(sLLBuffer); + Clean(mHHBuffer); + Clean(mLLBuffer); + Clean(lHHBuffer); + Clean(lLLBuffer); + Clean(hHHBuffer); + Clean(hLLBuffer); } // diff --git a/Helpers/x-saherelm.x121.xstr.helper.mq5 b/Helpers/x-saherelm.x121.xstr.helper.mq5 index 1ac9dcbb..37abaa8b 100644 --- a/Helpers/x-saherelm.x121.xstr.helper.mq5 +++ b/Helpers/x-saherelm.x121.xstr.helper.mq5 @@ -358,12 +358,12 @@ class XCX121XSTRHelper : public XCBaseHelper mInputs.Clean(); // - ArrayFree(strBuffer); - ArrayFree(atrBuffer); - ArrayFree(strPriceBuffer); - ArrayFree(strUpBuffer); - ArrayFree(strDownBuffer); - ArrayFree(strStateBuffer); + Clean(strBuffer); + Clean(atrBuffer); + Clean(strPriceBuffer); + Clean(strUpBuffer); + Clean(strDownBuffer); + Clean(strStateBuffer); } // diff --git a/Helpers/x-saherelm.x121.xvwap.helper.mq5 b/Helpers/x-saherelm.x121.xvwap.helper.mq5 index 0bd0806e..77d7e3aa 100644 --- a/Helpers/x-saherelm.x121.xvwap.helper.mq5 +++ b/Helpers/x-saherelm.x121.xvwap.helper.mq5 @@ -467,14 +467,14 @@ class XCX121XVWAPHelper : public XCBaseHelper mInputs.Clean(); // - ArrayFree(vwapFastBuffer); - ArrayFree(vwapMidBuffer); - ArrayFree(vwapSlowBuffer); - ArrayFree(vwapVolumeBuffer); - ArrayFree(vwapPriceBuffer); - ArrayFree(vwapFastStateBuffer); - ArrayFree(vwapMidStateBuffer); - ArrayFree(vwapSlowStateBuffer); + Clean(vwapFastBuffer); + Clean(vwapMidBuffer); + Clean(vwapSlowBuffer); + Clean(vwapVolumeBuffer); + Clean(vwapPriceBuffer); + Clean(vwapFastStateBuffer); + Clean(vwapMidStateBuffer); + Clean(vwapSlowStateBuffer); } // diff --git a/Libraries/x-saherelm.common.lib.mq5 b/Libraries/x-saherelm.common.lib.mq5 index 2480adf4..4eacd81e 100644 --- a/Libraries/x-saherelm.common.lib.mq5 +++ b/Libraries/x-saherelm.common.lib.mq5 @@ -7054,6 +7054,7 @@ void Clean(T &buffer[]) // ArrayResize(buffer, 0); ArrayFree(buffer); + ZeroMemory(buffer); } template void SpecificClean(T &buffer[]) diff --git a/Libraries/x-saherelm.x-poi.lib.mq5 b/Libraries/x-saherelm.x-poi.lib.mq5 index 340b49ef..a9f457d2 100644 --- a/Libraries/x-saherelm.x-poi.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.lib.mq5 @@ -7901,7 +7901,7 @@ void FilterPivotState( } // - ArrayFree(tmp); + Clean(tmp); } // @@ -7939,7 +7939,7 @@ void FilterPivotState( } // - ArrayFree(tmp); + Clean(tmp); } // @@ -7977,7 +7977,7 @@ void FilterPivotState( } // - ArrayFree(tmp); + Clean(tmp); } // @@ -8015,7 +8015,7 @@ void FilterPivotState( } // - ArrayFree(tmp); + Clean(tmp); } // @@ -8057,7 +8057,7 @@ void FilterPivotState( } // - ArrayFree(tmp); + Clean(tmp); } // @@ -8095,7 +8095,7 @@ void FilterPivotState( } // - ArrayFree(tmp); + Clean(tmp); } // @@ -8133,7 +8133,7 @@ void FilterPivotState( } // - ArrayFree(tmp); + Clean(tmp); } // @@ -8171,7 +8171,7 @@ void FilterPivotState( } // - ArrayFree(tmp); + Clean(tmp); } } @@ -8267,7 +8267,7 @@ bool DetectPivotStateBoxData( } // - ArrayFree(tmp); + Clean(tmp); } // @@ -8318,7 +8318,7 @@ bool DetectPivotStateBoxData( } // - ArrayFree(tmp); + Clean(tmp); } // @@ -8369,7 +8369,7 @@ bool DetectPivotStateBoxData( } // - ArrayFree(tmp); + Clean(tmp); } // @@ -8420,7 +8420,7 @@ bool DetectPivotStateBoxData( } // - ArrayFree(tmp); + Clean(tmp); } // @@ -8475,7 +8475,7 @@ bool DetectPivotStateBoxData( } // - ArrayFree(tmp); + Clean(tmp); } // @@ -8526,7 +8526,7 @@ bool DetectPivotStateBoxData( } // - ArrayFree(tmp); + Clean(tmp); } // @@ -8577,7 +8577,7 @@ bool DetectPivotStateBoxData( } // - ArrayFree(tmp); + Clean(tmp); } // @@ -8628,7 +8628,7 @@ bool DetectPivotStateBoxData( } // - ArrayFree(tmp); + Clean(tmp); } // diff --git a/X121SMCEA/Classes/x-121.smc.base.strategy.class.mq5 b/X121SMCEA/Classes/x-121.smc.base.strategy.class.mq5 index 528cc7f1..78a1bfcf 100644 --- a/X121SMCEA/Classes/x-121.smc.base.strategy.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.base.strategy.class.mq5 @@ -501,7 +501,7 @@ class XCX121SMCBaseStrategy : public XCBaseAlert mGuardBarTracker.Waits(); // - ArrayFree(positions); + Clean(positions); // return result; @@ -868,7 +868,7 @@ class XCX121SMCBaseStrategy : public XCBaseAlert } // - ArrayFree(objects); + Clean(objects); } // @@ -970,8 +970,8 @@ class XCX121SMCBaseStrategy : public XCBaseAlert delete mBarAnalyser; // - ArrayFree(mTicks); - ArrayFree(mSignalEventHandlers); + Clean(mTicks); + Clean(mSignalEventHandlers); // Destroy(); diff --git a/X121SMCEA/Classes/x-121.smc.x-tradehandler.class.mq5 b/X121SMCEA/Classes/x-121.smc.x-tradehandler.class.mq5 index 7dfb754f..9810c433 100644 --- a/X121SMCEA/Classes/x-121.smc.x-tradehandler.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.x-tradehandler.class.mq5 @@ -1629,9 +1629,9 @@ class XC121SMCTradeHandler : public XCBaseAlert ~XC121SMCTradeHandler() { // - ArrayFree(mData); - ArrayFree(mSymbolInfos); - ArrayFree(mLastExecutedSignals); + Clean(mData); + Clean(mSymbolInfos); + Clean(mLastExecutedSignals); // delete mDrawer; diff --git a/X121SMCEA/Experts/x-121.smc.expert.class.mq5 b/X121SMCEA/Experts/x-121.smc.expert.class.mq5 index e719bea6..fa8954c6 100644 --- a/X121SMCEA/Experts/x-121.smc.expert.class.mq5 +++ b/X121SMCEA/Experts/x-121.smc.expert.class.mq5 @@ -65,7 +65,7 @@ class XC121SMCExpert : public XCBaseExpert // Deconstructor(s) ... ~XC121SMCExpert() { - ArrayFree(mStrategies); + Clean(mStrategies); } // @@ -2486,7 +2486,7 @@ class XC121SMCExpert : public XCBaseExpert // Clean(guards); - ArrayFree(guards); + Clean(guards); } // diff --git a/X121SMCEA/Libraries/x-121.smc.guard.lib.mq5 b/X121SMCEA/Libraries/x-121.smc.guard.lib.mq5 index 61495260..994ee91d 100644 --- a/X121SMCEA/Libraries/x-121.smc.guard.lib.mq5 +++ b/X121SMCEA/Libraries/x-121.smc.guard.lib.mq5 @@ -1674,21 +1674,21 @@ bool DetectX121SMCGuards( // // 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); + Clean(ownPositions); + Clean(ownLongPositions); + Clean(ownShortPositions); + Clean(triggerPoiEvents); + Clean(triggerCycleEvents); + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + Clean(analysePoiEvents); + Clean(analyseCycleEvents); + Clean(verificationPoiEvents); + Clean(verificationCycleEvents); + Clean(consolidationPoiEvents); + Clean(consolidationCycleEvents); + Clean(visionPoiEvents); + Clean(visionCycleEvents); // count = ArraySize(guards); diff --git a/X121SMCEA/Libraries/x-121.smc.lib.mq5 b/X121SMCEA/Libraries/x-121.smc.lib.mq5 index 0fbbfb9c..b27fe0a4 100644 --- a/X121SMCEA/Libraries/x-121.smc.lib.mq5 +++ b/X121SMCEA/Libraries/x-121.smc.lib.mq5 @@ -36,8 +36,10 @@ const string X121SMCStrategyToken = "X121SMC"; // const string X121SMCXToken = "X121X"; +const string X121SMCXOBSToken = "X121XOBS"; const string X121SMCXHKPVToken = "X121XHKPV"; const string X121SMCXOBPVToken = "X121XOBPV"; +const string X121SMCXIOBPVToken = "X121XIOBPV"; // // X121 SMC Providers ... @@ -46,8 +48,10 @@ enum ENUM_X_121_SMC_PROVIDERS // X_121_SMC_PROVIDER_NONE, X_121_SMC_PROVIDER_X, + X_121_SMC_PROVIDER_XOBS, X_121_SMC_PROVIDER_XHKPV, X_121_SMC_PROVIDER_XOBPV, + X_121_SMC_PROVIDER_XIOBPV, }; // @@ -1655,6 +1659,11 @@ string ToString(ENUM_X_121_SMC_PROVIDERS value) result = X121SMCXToken; break; + // + case X_121_SMC_PROVIDER_XOBS: + result = X121SMCXOBSToken; + break; + // case X_121_SMC_PROVIDER_XHKPV: result = X121SMCXHKPVToken; @@ -1664,6 +1673,11 @@ string ToString(ENUM_X_121_SMC_PROVIDERS value) case X_121_SMC_PROVIDER_XOBPV: result = X121SMCXOBPVToken; break; + + // + case X_121_SMC_PROVIDER_XIOBPV: + result = X121SMCXIOBPVToken; + break; } // @@ -1693,6 +1707,10 @@ ENUM_X_121_SMC_PROVIDERS ParseProvider(string value) { result = X_121_SMC_PROVIDER_X; } + else if (Contains(X121SMCXOBSToken, value)) + { + result = X_121_SMC_PROVIDER_XOBS; + } else if (Contains(X121SMCXHKPVToken, value)) { result = X_121_SMC_PROVIDER_XHKPV; @@ -1701,6 +1719,10 @@ ENUM_X_121_SMC_PROVIDERS ParseProvider(string value) { result = X_121_SMC_PROVIDER_XOBPV; } + else if (Contains(X121SMCXIOBPVToken, value)) + { + result = X_121_SMC_PROVIDER_XIOBPV; + } // return result; diff --git a/X121SMCEA/Signals/x-121.smc.x.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.x.signal.lib.mq5 index ea6d22ad..ee4db31a 100644 --- a/X121SMCEA/Signals/x-121.smc.x.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.x.signal.lib.mq5 @@ -1269,18 +1269,18 @@ bool DetectX121SMCXSignalSetup( { // // 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); + Clean(triggerPoiEvents); + Clean(triggerCycleEvents); + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + Clean(analysePoiEvents); + Clean(analyseCycleEvents); + Clean(verificationPoiEvents); + Clean(verificationCycleEvents); + Clean(consolidationPoiEvents); + Clean(consolidationCycleEvents); + Clean(visionPoiEvents); + Clean(visionCycleEvents); // return result; @@ -1295,18 +1295,18 @@ bool DetectX121SMCXSignalSetup( // // 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); + Clean(triggerPoiEvents); + Clean(triggerCycleEvents); + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + Clean(analysePoiEvents); + Clean(analyseCycleEvents); + Clean(verificationPoiEvents); + Clean(verificationCycleEvents); + Clean(consolidationPoiEvents); + Clean(consolidationCycleEvents); + Clean(visionPoiEvents); + Clean(visionCycleEvents); // return result; @@ -1527,8 +1527,8 @@ bool DetectX121SMCXSignalTrigger( // // Cleanup Arrays ... - ArrayFree(decisionPoiEvents); - ArrayFree(decisionCycleEvents); + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); // return result; @@ -1575,8 +1575,8 @@ bool DetectX121SMCXSignalTrigger( // // Cleanup Arrays ... - ArrayFree(decisionPoiEvents); - ArrayFree(decisionCycleEvents); + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); // return result; diff --git a/X121SMCEA/Signals/x-121.smc.xhkpv.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xhkpv.signal.lib.mq5 index 025cf08e..9c7a3114 100644 --- a/X121SMCEA/Signals/x-121.smc.xhkpv.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xhkpv.signal.lib.mq5 @@ -1412,18 +1412,18 @@ bool DetectX121SMCXHKPVSignalSetup( // // 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); + Clean(triggerPoiEvents); + Clean(triggerCycleEvents); + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + Clean(analysePoiEvents); + Clean(analyseCycleEvents); + Clean(verificationPoiEvents); + Clean(verificationCycleEvents); + Clean(consolidationPoiEvents); + Clean(consolidationCycleEvents); + Clean(visionPoiEvents); + Clean(visionCycleEvents); // return result; @@ -1438,18 +1438,18 @@ bool DetectX121SMCXHKPVSignalSetup( // // 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); + Clean(triggerPoiEvents); + Clean(triggerCycleEvents); + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + Clean(analysePoiEvents); + Clean(analyseCycleEvents); + Clean(verificationPoiEvents); + Clean(verificationCycleEvents); + Clean(consolidationPoiEvents); + Clean(consolidationCycleEvents); + Clean(visionPoiEvents); + Clean(visionCycleEvents); // return result; @@ -1670,8 +1670,8 @@ bool DetectX121SMCXHKPVSignalTrigger( // // Cleanup Arrays ... - ArrayFree(decisionPoiEvents); - ArrayFree(decisionCycleEvents); + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); // return result; @@ -1718,8 +1718,8 @@ bool DetectX121SMCXHKPVSignalTrigger( // // Cleanup Arrays ... - ArrayFree(decisionPoiEvents); - ArrayFree(decisionCycleEvents); + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); // return result; diff --git a/X121SMCEA/Signals/x-121.smc.xiobpv.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xiobpv.signal.lib.mq5 new file mode 100644 index 00000000..f8fad7a2 --- /dev/null +++ b/X121SMCEA/Signals/x-121.smc.xiobpv.signal.lib.mq5 @@ -0,0 +1,1853 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 X121 SMC Signal Class +// ------------------------------------------------- +// Name: XIOBPV +// Description: provide all Signalling functions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Imports ... +// #include "../../Libraries/x-trade.lib" +#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" +#include "../Libraries/x-121.smc.guard.lib.mq5" +#include "../Libraries/x-121.smc.lib.mq5" + +// +// Definitions ... +struct X121SMCStrategyXIOBPVSignalConditions +{ + // + // Props ... + + // + string symbol; + ENUM_TIMEFRAMES period; + + // + double sl; + double target; + ENUM_X_DIRECTION dir; + ENUM_X_POSITION_TYPES type; + + // + // Setup Props ... + + // + datetime setupTime; + datetime triggerTime; + + // + double pivot; + double point; + + // + XBoxZone priceBox; + datetime priceOBAt; + bool isPriceOBActed; + bool isPriceOBBreaked; + XCOrderBlock *priceOB; + X121SMCCycleState state; + + // + // Constructor ... + X121SMCStrategyXIOBPVSignalConditions() + { + Clean(); + } + + // + // Tools ... + + /** + * Cleaning Up ... + */ + void Clean() + { + // + sl = 0; + target = 0; + + // + dir = X_DIRECTION_NONE; + type = X_POSITION_TYPE_NONE; + + // + symbol = NULL; + period = NULL; + setupTime = NULL; + triggerTime = NULL; + + // + ExtensionClean(); + } + + /** + * Check Condition is Setting Up ... + * + * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... + * + * @return ( bool ) + */ + bool IsSetuped() + { + // + bool result = false; + + // + result = IsValid(setupTime) && + HasDirection(dir); + if (!result) + { + return result; + } + + // + return result; + } + + /** + * Calculate Setup Age ... + * + * @return ( int ) + */ + int GetSetupAge() + { + // + int result = 0; + + // + if (!IsSetuped()) + { + return result; + } + + // + result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); + + // + return result; + } + + /** + * Detect How we Can Trigger Signal ... + * + * @return ( bool ) + */ + bool CanTrigger() + { + // + bool result = false; + + // + result = + // + sl > 0 && + IsValid(symbol) && + IsValid(period) && + IsValid(triggerTime) && + type != X_POSITION_TYPE_ALL && + type != X_POSITION_TYPE_NONE + // + ; + + // + return result; + } + + // + // Extensions ... + + /** + * Clean Additional Properties ... + */ + void ExtensionClean() + { + // + pivot = 0; + point = 0; + + // + state.Clean(); + priceOB = NULL; + priceBox.Clean(); + priceOBAt = NULL; + isPriceOBActed = false; + isPriceOBBreaked = false; + } + + // +}; + +// +// Signaller Data Sources ... +X121SMCStrategyXIOBPVSignalConditions mXIOBPVConditions; +X121SMCStrategyXIOBPVSignalConditions mXIOBPVConditionsCollection[]; + +// +// Extension Functions ... + +// +// Detect Setup Conditions ... +bool DetectX121SMCXIOBPVSignalSetup( + string _symbol, + ENUM_TIMEFRAMES _period, + // + X121SMCStrategyXIOBPVSignalConditions &conditions, + // + XC121SMCCycleHelper *triggerCycleHelper, + XC121SMCCycleHelper *decisionCycleHelper, + XC121SMCCycleHelper *analyseCycleHelper, + XC121SMCCycleHelper *verificationCycleHelper, + XC121SMCCycleHelper *consolidationCycleHelper, + XC121SMCCycleHelper *visionCycleHelper, + // + int resetAfterUnActedZoneInMinutes = 120 + // +) +{ + // + bool result = false; + + // + bool isBullish = false; + bool isBearish = false; + + // + int zIndex = 0; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + int loopback = 10; + + // + string symbol = _symbol; + ENUM_TIMEFRAMES period = _period; + + // + conditions.symbol = symbol; + conditions.period = period; + + // + XC121SMCCycleHelper *barCycle = triggerCycleHelper; + + // + XOHCL zBar; + result = barCycle.GetBar( + zBar, + zIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL cBar; + result = barCycle.GetBar( + cBar, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = barCycle.GetBar( + pBar, + pIndex // + ); + if (!result) + { + return result; + } + + // + double ask = GetAsk(symbol); + double bid = GetBid(symbol); + datetime cTime = TimeCurrent(); + double points = GetPoints(symbol); + + // + int swingLoopback = 7; + double ll = cBar.FindLowest(swingLoopback, MODE_LOW); + double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); + double ll50 = cBar.FindLowest(50, MODE_LOW); + double hh50 = cBar.FindHighest(50, MODE_HIGH); + double llDown = cBar.FindLowesttDown(swingLoopback); + double hhUp = cBar.FindHighestUp(swingLoopback); + + // + // Cycles Conditions ... + + // + // Trigger ... + ENUM_XPOI_EVENTS triggerPoiEvents[]; + ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; + X121SMCCycleConditions triggerConditions; + result = triggerCycleHelper.GetConditions( + triggerCycleEvents, + triggerPoiEvents, + triggerConditions, + zIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + // Decision ... + ENUM_XPOI_EVENTS decisionPoiEvents[]; + ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; + X121SMCCycleConditions decisionConditions; + result = decisionCycleHelper.GetConditions( + decisionCycleEvents, + decisionPoiEvents, + decisionConditions, + zIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + // Analyse ... + ENUM_XPOI_EVENTS analysePoiEvents[]; + ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; + X121SMCCycleConditions analyseConditions; + result = analyseCycleHelper.GetConditions( + analyseCycleEvents, + analysePoiEvents, + analyseConditions, + zIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + // Verification ... + ENUM_XPOI_EVENTS verificationPoiEvents[]; + ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; + X121SMCCycleConditions verificationConditions; + result = verificationCycleHelper.GetConditions( + verificationCycleEvents, + verificationPoiEvents, + verificationConditions, + zIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + // Consolidation ... + ENUM_XPOI_EVENTS consolidationPoiEvents[]; + ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; + X121SMCCycleConditions consolidationConditions; + result = consolidationCycleHelper.GetConditions( + consolidationCycleEvents, + consolidationPoiEvents, + consolidationConditions, + zIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + // Vision ... + ENUM_XPOI_EVENTS visionPoiEvents[]; + ENUM_X_CYCLE_EVENTS visionCycleEvents[]; + X121SMCCycleConditions visionConditions; + result = visionCycleHelper.GetConditions( + visionCycleEvents, + visionPoiEvents, + visionConditions, + zIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + // Cycles POI States ... + XPOIState triggerState = triggerConditions.state; + XPOIState decisionState = decisionConditions.state; + XPOIState analyseState = analyseConditions.state; + XPOIState verificationState = verificationConditions.state; + XPOIState consolidationState = consolidationConditions.state; + XPOIState visionState = visionConditions.state; + + // + // Cycle X121Conditions ... + X121Conditions triggerXConditions = triggerConditions.x121Conditions; + X121Conditions decisionXConditions = decisionConditions.x121Conditions; + X121Conditions analyseXConditions = analyseConditions.x121Conditions; + X121Conditions verificationXConditions = verificationConditions.x121Conditions; + X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; + X121Conditions visionXConditions = visionConditions.x121Conditions; + + // + // Setup Conditions ... + + // + // Detect Trend ... + + // + // Consolidation ... + ENUM_X_DIRECTION consolidationTrendDir; + bool hasConsolidationTrend = + consolidationCycleHelper + .DetectMarketStructure( + consolidationTrendDir // + ); + bool hasConsolidationBullishTrend = + hasConsolidationTrend && + IsBullish(consolidationTrendDir); + bool hasConsolidationBearishTrend = + hasConsolidationTrend && + IsBearish(consolidationTrendDir); + + // + // Verification ... + ENUM_X_DIRECTION verificationTrendDir; + bool hasVerificationTrend = + verificationCycleHelper + .DetectMarketStructure( + verificationTrendDir // + ); + bool hasVerificationBullishTrend = + hasVerificationTrend && + IsBullish(verificationTrendDir); + bool hasVerificationBearishTrend = + hasVerificationTrend && + IsBearish(verificationTrendDir); + + // + // Analyse ... + ENUM_X_DIRECTION analyseTrendDir; + bool hasAnalyseTrend = + analyseCycleHelper + .DetectMarketStructure( + analyseTrendDir // + ); + bool hasAnalyseBullishTrend = + hasAnalyseTrend && + IsBullish(analyseTrendDir); + bool hasAnalyseBearishTrend = + hasAnalyseTrend && + IsBearish(analyseTrendDir); + + // + // Decision ... + ENUM_X_DIRECTION decisionTrendDir; + bool hasDecisionTrend = + decisionCycleHelper + .DetectMarketStructure( + decisionTrendDir // + ); + bool hasDecisionBullishTrend = + hasDecisionTrend && + IsBullish(decisionTrendDir); + bool hasDecisionBearishTrend = + hasDecisionTrend && + IsBearish(decisionTrendDir); + + // + // Detect Bar State ... + + // + // PinBar ... + ENUM_X_DIRECTION cBarPinDir; + bool isCBarPin = decisionCycleHelper + .mBarAnalyser + .IsPinBar( + cBar, + cBarPinDir, + 1 // + ); + bool isCBarBullishPin = + isCBarPin && + IsBullish(cBarPinDir); + bool isCBarBearishPin = + isCBarPin && + IsBearish(cBarPinDir); + + // + // Engulf ... + ENUM_X_DIRECTION cBarEngulfDir; + bool isCBarEngulfed = decisionCycleHelper + .mBarAnalyser + .IsEngulfBar( + cBar, + cBarEngulfDir, + 0 // Extended ... + ); + bool isCBarBullishEngulfed = + isCBarEngulfed && + IsBullish(cBarEngulfDir); + bool isCBarBearishEngulfed = + isCBarEngulfed && + IsBearish(cBarEngulfDir); + + // + // Momentum ... + ENUM_X_DIRECTION cBarMomentumDir; + bool isCBarMomentum = decisionCycleHelper + .mBarAnalyser + .IsMomentumBar( + cBar, + cBarMomentumDir, + 0 // Extended ... + ); + bool isCBarBullishMomentum = + isCBarMomentum && + IsBullish(cBarMomentumDir); + bool isCBarBearishMomentum = + isCBarMomentum && + IsBearish(cBarMomentumDir); + + // + // Reject ... + ENUM_X_DIRECTION cBarRejectDir; + bool isCBarRejected = decisionCycleHelper + .mBarAnalyser + .IsRejectionBar( + cBar, + cBarRejectDir, + 0 // Extended ... + ); + bool isCBarBullishRejected = + isCBarRejected && + IsBullish(cBarRejectDir); + bool isCBarBearishRejected = + isCBarRejected && + IsBearish(cBarRejectDir); + + // + // Pull Back ... + ENUM_X_DIRECTION cBarPullbackDir; + bool isCBarPullbacked = + decisionCycleHelper + .mBarAnalyser + .HasPullBack( + cBarPullbackDir, + cBar // + ); + bool isCBarBullishPullbacked = + isCBarPullbacked && + IsBullish(cBarPullbackDir); + bool isCBarBearishPullbacked = + isCBarPullbacked && + IsBearish(cBarPullbackDir); + + // + // HH/LL Break ... + + // + bool isCBarBreaksUpHH = IsBarBreak( + hh, + X_DIRECTION_BULLISH, + cBar // + ); + + // + bool isCBarBreaksDownLL = IsBarBreak( + hh, + X_DIRECTION_BEARISH, + cBar // + ); + + // + // Bars Pattern and Power and Pressures ... + + // + bool hasCBarBullishPattern = + decisionCycleHelper + .mBarAnalyser + .HasBullishPattern( + cBar, + 2 // + ); + + // + bool hasCBarBearishPattern = + decisionCycleHelper + .mBarAnalyser + .HasBearishPattern( + cBar, + 2 // + ); + + // + bool isCBarHasBullishPower = + decisionCycleHelper + .mBarAnalyser + .HasBullishPower( + cBar, + 2 // + ); + + // + bool isCBarHasBearishPower = + decisionCycleHelper + .mBarAnalyser + .HasBearishPower( + cBar, + 2 // + ); + + // + bool isCBarHasBullishPressure = + decisionCycleHelper + .mBarAnalyser + .HasBullishPressure( + cBar, + 2 // + ); + + // + bool isCBarHasBearishPressure = + decisionCycleHelper + .mBarAnalyser + .HasBearishPressure( + cBar, + 2 // + ); + + // + // Bar Checking Summary ... + + // + // Bullish ... + bool isCBarBullishFormed = + // + ( + // + hasCBarBullishPattern && + isCBarHasBullishPower && + isCBarHasBullishPressure + // + ) + // + || + // + ( + // + isCBarBullishPin || + isCBarBreaksUpHH || + isCBarBullishEngulfed || + isCBarBullishMomentum || + isCBarBullishRejected + // + ) + // + ; + + // + // Bearish ... + bool isCBarBearishFormed = + // + ( + // + hasCBarBearishPattern && + isCBarHasBearishPower && + isCBarHasBearishPressure + // + ) + // + || + // + ( + // + isCBarBearishPin || + isCBarBreaksDownLL || + isCBarBearishEngulfed || + isCBarBearishMomentum || + isCBarBearishRejected + // + ) + // + ; + + // + // Detect Cycle State ... + + // + double upper = 0; + double lower = 0; + bool hasYoungestOB = false; + bool isPriceOBValid = false; + bool isBullishHappens = false; + bool isBearishHappens = false; + XCOrderBlock *youngestOB = NULL; + bool hasPriceBox = conditions.priceBox.IsValid(); + bool hasState = visionCycleHelper.GetCycleState(conditions.state); + + // + // Detect Price Box if not Provided ... + if (hasState && + !hasPriceBox) + { + // + hasPriceBox = DetectPriceInsideBox( + conditions.priceBox, + conditions.priceOB, + decisionXConditions, + conditions.state // + ); + if (hasPriceBox) + { + conditions.priceOBAt = cTime; + } + } + + // + if (hasPriceBox) + { + // + // Update Price Box Date ... + conditions.priceOB.To(cTime); + conditions.priceBox.to = cTime; + upper = conditions.priceOB.Upper(); + lower = conditions.priceOB.Lower(); + + // + hasYoungestOB = conditions.state.GetYoungestOB(youngestOB); + + // + // Here We Can Validate Box by Same Cycles Peaks and Vales ... + bool isBullish = IsBullish(conditions.priceBox.dir); + + // + bool isPriceBoxSameAsOB = + // + conditions.priceBox.upper <= conditions.priceOB.Upper() && + conditions.priceBox.lower >= conditions.priceOB.Lower() + // + ; + + // + int cIDX = 1; + + // + bool isSameCyclePeaks = + // + triggerXConditions.peaksBuffer[cIDX] == decisionXConditions.peaksBuffer[cIDX] && + decisionXConditions.peaksBuffer[cIDX] == analyseXConditions.peaksBuffer[cIDX] && + analyseXConditions.peaksBuffer[cIDX] == verificationXConditions.peaksBuffer[cIDX] + // + ; + + // + bool isSameCycleVales = + // + triggerXConditions.valesBuffer[cIDX] == decisionXConditions.valesBuffer[cIDX] && + decisionXConditions.valesBuffer[cIDX] == analyseXConditions.valesBuffer[cIDX] && + analyseXConditions.valesBuffer[cIDX] == verificationXConditions.valesBuffer[cIDX] + // + ; + + // + // Check Validation Conditions ... + isPriceOBValid = + // + hasPriceBox && + isPriceBoxSameAsOB && + (isBullish + ? isSameCycleVales + : isSameCyclePeaks) + // + ; + + // + // Check Conditions ... + + // + X121Conditions xConditions = triggerXConditions; + + // + isBullishHappens = + // + isPriceOBValid && + isCBarBullishFormed && + conditions.priceOB.IsBullish() && + IsBullish(conditions.priceBox.dir) && + // + (xConditions.isBreakedUpPrevSar || + xConditions.isBreakedUpPrevStr || + xConditions.isVWapMaxBreakedUp || + xConditions.isBreakedUpPrevCheMax || + xConditions.isBreakedUpPrevAtrLower) && + // + (xConditions.isSarSwitchedToBullish || + xConditions.isStrSwitchedToBullish || + xConditions.isCheSwitchedToBullish || + xConditions.isVWapSwitchedToBullishState || + xConditions.isVWapSwitchedToBullishOrdered) + // + ; + + // + isBearishHappens = + // + isPriceOBValid && + isCBarBearishFormed && + conditions.priceOB.IsBearish() && + IsBearish(conditions.priceBox.dir) && + // + (xConditions.isBreakedDownPrevSar || + xConditions.isBreakedDownPrevStr || + xConditions.isVWapMinBreakedDown || + xConditions.isBreakedDownPrevCheMin || + xConditions.isBreakedDownPrevAtrUpper) && + // + (xConditions.isSarSwitchedToBearish || + xConditions.isStrSwitchedToBearish || + xConditions.isCheSwitchedToBearish || + xConditions.isVWapSwitchedToBearishState || + xConditions.isVWapSwitchedToBearishOrdered) + // + ; + + // + if (!conditions.isPriceOBActed) + { + conditions.isPriceOBActed = isBullishHappens || + isBearishHappens; + } + } + + // + // Detect Accumulation ... + if (conditions.isPriceOBActed) + { + // + // Checking OB Breake on Side ... + if (!conditions.isPriceOBBreaked) + { + // + conditions.isPriceOBBreaked = + (conditions.priceOB.IsBullish() && + IsBullish(conditions.priceBox.dir)) + ? (cBar.low < upper && + cBar.high > upper && + cBar.close > upper) + // + || + // + (pBar.high < upper && + cBar.low > upper && + cBar.open > upper) + : (cBar.high > lower && + cBar.low < lower && + cBar.close < lower) + // + || + // + (pBar.low > lower && + cBar.high < lower && + cBar.open < lower); + } + } + + // + // Detect Distribution ... + bool isPriceOBUpperBrekedUp = false; + bool isPriceOBLowerBrekedDown = false; + if (conditions.isPriceOBBreaked) + { + // + isPriceOBUpperBrekedUp = IsBarBreak( + upper, + X_DIRECTION_BULLISH, + cBar // + ); + + // + isPriceOBLowerBrekedDown = IsBarBreak( + lower, + X_DIRECTION_BEARISH, + cBar // + ); + } + + // // + // // Draw ... + // XCBaseObject *drawnObjects[]; + // int drawnObjectsCount = visionCycleHelper.DrawCycleState( + // conditions.state, + // drawnObjects // + // ); + + // // + // if (hasPriceBox) + // { + // // + // bool isBullish = IsBullish(conditions.priceBox.dir); + // color boxColor = isBullish ? clrYellow : clrOrange; + + // // + // XCBoxObject *iObj; + // bool isCreated = visionCycleHelper.mPOIDrawer.CreateBox( + // conditions.priceBox, + // iObj, + // boxColor, + // 1, + // false, + // STYLE_DASHDOTDOT // + // ); + + // // + // if (isCreated) + // { + // // + // Add( + // (XCBaseObject *)iObj, + // drawnObjects // + // ); + // } + + // // + // XCBaseObject *priceOBObj = NULL; + // if (isBullish) + // { + // // + // XCBullishOrderBlockObject *iObj; + // isCreated = visionCycleHelper + // .mPOIDrawer + // .CreateBullishOrderBlock( + // conditions.priceOB, + // iObj // + // ); + + // // + // if (isCreated) + // { + // // + // iObj.ZoneWidth(2); + // iObj.ZoneColor(boxColor); + // iObj.ZoneStyle(STYLE_SOLID); + + // // + // priceOBObj = (XCBaseObject *)iObj; + // } + // } + // else + // { + // // + // XCBearishOrderBlockObject *iObj; + // isCreated = visionCycleHelper + // .mPOIDrawer + // .CreateBearishOrderBlock( + // conditions.priceOB, + // iObj // + // ); + + // // + // if (isCreated) + // { + // // + // iObj.ZoneWidth(2); + // iObj.ZoneColor(boxColor); + // iObj.ZoneStyle(STYLE_SOLID); + + // // + // priceOBObj = (XCBaseObject *)iObj; + // } + // } + + // // + // if (isCreated) + // { + // // + // Add( + // priceOBObj, + // drawnObjects // + // ); + // } + // } + + // + // + // + + // + // Check Verifications Conditions ... + + // + // XHK ... + bool isXHKBullish = false; + bool isXHKBearish = false; + + // + // XSAR ... + bool isXSarBullish = false; + bool isXSarBearish = false; + + // + // XATR ... + bool isXAtrBullish = false; + bool isXAtrBearish = false; + + // + // XSTR ... + bool isXStrBullish = false; + bool isXStrBearish = false; + + // + // XVWAP ... + bool isXVWapBullish = false; + bool isXVWapBearish = false; + + // + // XCHE ... + bool isXCheBullish = false; + bool isXCheBearish = false; + + // + if (hasPriceBox) + { + // + // XHK ... + + // + isXHKBullish = + // + // Trigger ... + triggerXConditions.isSMHKBullish && + triggerXConditions.isRawHKBullish && + triggerXConditions.isClosedOverSMHK && + triggerXConditions.isClosedOverRawHK && + (triggerXConditions.isBreakedUpSMHK || + triggerXConditions.isBreakedUpRawHK) && + triggerXConditions.isRawHKClosedOverSMHK && + // + // Decision ... + decisionXConditions.isSMHKBullish && + decisionXConditions.isRawHKBullish && + decisionXConditions.isClosedOverSMHK && + decisionXConditions.isClosedOverRawHK && + (decisionXConditions.isBreakedUpSMHK || + decisionXConditions.isBreakedUpRawHK) && + decisionXConditions.isRawHKClosedOverSMHK && + // + // Analyse ... + analyseXConditions.isSMHKBullish && + analyseXConditions.isRawHKBullish && + analyseXConditions.isClosedOverSMHK && + analyseXConditions.isClosedOverRawHK && + (analyseXConditions.isBreakedUpSMHK || + analyseXConditions.isBreakedUpRawHK) && + decisionXConditions.isRawHKClosedOverSMHK + // + ; + + // + isXHKBearish = + // + // Trigger ... + triggerXConditions.isSMHKBearish && + triggerXConditions.isRawHKBearish && + triggerXConditions.isClosedUnderSMHK && + triggerXConditions.isClosedUnderRawHK && + (triggerXConditions.isBreakedDownSMHK || + triggerXConditions.isBreakedDownRawHK) && + triggerXConditions.isRawHKClosedUnderSMHK && + // + // Decision ... + decisionXConditions.isSMHKBearish && + decisionXConditions.isRawHKBearish && + decisionXConditions.isClosedUnderSMHK && + decisionXConditions.isClosedUnderRawHK && + (decisionXConditions.isBreakedDownSMHK || + decisionXConditions.isBreakedDownRawHK) && + decisionXConditions.isRawHKClosedUnderSMHK && + // + // Analyse ... + analyseXConditions.isSMHKBearish && + analyseXConditions.isRawHKBearish && + analyseXConditions.isClosedUnderSMHK && + analyseXConditions.isClosedUnderRawHK && + (analyseXConditions.isBreakedDownSMHK || + analyseXConditions.isBreakedDownRawHK) && + analyseXConditions.isRawHKClosedUnderSMHK + // + ; + + // + // XSAR ... + + // + isXSarBullish = + // + // Trigger ... + triggerXConditions.isSarBullish && + triggerXConditions.isSarIncreased && + // + // Decision ... + decisionXConditions.isSarBullish && + decisionXConditions.isSarIncreased && + // + // Analyse ... + analyseXConditions.isSarBullish && + analyseXConditions.isSarIncreased + // + ; + + // + isXSarBearish = + // + // Trigger ... + triggerXConditions.isSarBearish && + triggerXConditions.isSarDecreased && + // + // Decision ... + decisionXConditions.isSarBearish && + decisionXConditions.isSarDecreased && + // + // Analyse ... + analyseXConditions.isSarBearish // && + // + ; + + // + // XATR ... + + // + isXAtrBullish = + // + // Trigger ... + triggerXConditions.isClosedOverAtrUpper && + // + // Decision ... + decisionXConditions.isClosedOverAtrUpper + // + // Analyse ... + // + ; + + // + isXAtrBearish = + // + // Trigger ... + triggerXConditions.isClosedUnderAtrLower && + // + // Decision ... + decisionXConditions.isClosedUnderAtrLower + // + // Analyse ... + // + ; + + // + // XSTR ... + + // + isXStrBullish = + // + // Trigger ... + triggerXConditions.isStrBullish && + // + // Decision ... + decisionXConditions.isStrBullish + // + // Analyse ... + // + ; + + // + isXStrBearish = + // + // Trigger ... + triggerXConditions.isStrBearish && + // + // Decision ... + decisionXConditions.isStrBearish + // + // Analyse ... + // + ; + + // + // XVWAP ... + + // + isXVWapBullish = + // + // Trigger ... + triggerXConditions.isVWapBullishState && + triggerXConditions.isVWapBullishOrdered && + // + // Decision ... + decisionXConditions.isVWapBullishState && + decisionXConditions.isVWapBullishOrdered && + // + // Analyse ... + analyseXConditions.isVWapBullishState && + analyseXConditions.isVWapBullishOrdered + // + ; + + // + isXVWapBearish = + // + // Trigger ... + triggerXConditions.isVWapBearishState && + triggerXConditions.isVWapBearishOrdered && + // + // Decision ... + decisionXConditions.isVWapBearishState && + decisionXConditions.isVWapBearishOrdered && + // + // Analyse ... + analyseXConditions.isVWapBearishState && + analyseXConditions.isVWapBearishOrdered + // + ; + + // + // XCHE ... + + // + isXCheBullish = + // + // Trigger ... + triggerXConditions.isCheBullish && + // + // Decision ... + decisionXConditions.isCheBullish && + // + // Analyse ... + analyseXConditions.isCheBullish + // + ; + + // + isXCheBearish = + // + // Trigger ... + triggerXConditions.isCheBearish && + // + // Decision ... + decisionXConditions.isCheBearish && + // + // Analyse ... + analyseXConditions.isCheBearish + // + ; + } + + // + // Summarize Conditions ... + + // + bool isCondition1Bullish = + // + isPriceOBUpperBrekedUp && + conditions.isPriceOBBreaked && + conditions.priceOB.IsBearish() && + // + // XHK ... + isXHKBullish && + // + // XSAR ... + isXSarBullish && + // + // XATR ... + isXAtrBullish && + // + // XSTR ... + isXStrBullish && + // + // XVWAP ... + isXVWapBullish && + // + // XCHE ... + isXCheBullish && + // + true + // + ; + + // + bool isCondition1Bearish = + // + isPriceOBLowerBrekedDown && + conditions.isPriceOBBreaked && + conditions.priceOB.IsBullish() && + // + // XHK ... + isXHKBearish && + // + // XSAR ... + isXSarBearish && + // + // XATR ... + isXAtrBearish && + // + // XSTR ... + isXStrBearish && + // + // XVWAP ... + isXVWapBearish && + // + // XCHE ... + isXCheBearish && + // + true + // + ; + + // + bool hasCondition1 = isCondition1Bullish || + isCondition1Bearish; + if (hasCondition1) + { + // + ENUM_X_DIRECTION pzDir = + isCondition1Bullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + double point = GetEntry( + conditions.symbol, + pzDir // + ); + + // + double longPivot = lower; // triggerXConditions.valesBuffer[1]; + double shortPivot = upper; // triggerXConditions.peaksBuffer[1]; + + // + // Manipulate Conditions Point ... + + // + conditions.point = + isCondition1Bullish + ? shortPivot + : longPivot; + + // + // Manipulate Conditions Pivot ... + + // + conditions.pivot = + isCondition1Bullish + ? longPivot + : shortPivot; + } + + // + // + // + + // + isBullish = + // + isCondition1Bullish + // + ; + + // + isBearish = + // + isCondition1Bearish + // + ; + + // + result = isBullish || + isBearish; + if (!result) + { + // + // Detect PriceOB Lifetime Bars ... + if (hasPriceBox) + { + // + int obLifetimeBars = (int)(cTime - conditions.priceOBAt) / PeriodSeconds(PERIOD_M1); + bool canReset = + // + !conditions.isPriceOBActed && + obLifetimeBars >= resetAfterUnActedZoneInMinutes + // + ; + if (canReset) + { + conditions.Clean(); + } + } + + // + // Cleanup Arrays ... + Clean(triggerPoiEvents); + Clean(triggerCycleEvents); + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + Clean(analysePoiEvents); + Clean(analyseCycleEvents); + Clean(verificationPoiEvents); + Clean(verificationCycleEvents); + Clean(consolidationPoiEvents); + Clean(consolidationCycleEvents); + Clean(visionPoiEvents); + Clean(visionCycleEvents); + + // + return result; + } + + // + conditions.setupTime = cTime; + conditions.dir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + // Cleanup Arrays ... + Clean(triggerPoiEvents); + Clean(triggerCycleEvents); + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + Clean(analysePoiEvents); + Clean(analyseCycleEvents); + Clean(verificationPoiEvents); + Clean(verificationCycleEvents); + Clean(consolidationPoiEvents); + Clean(consolidationCycleEvents); + Clean(visionPoiEvents); + Clean(visionCycleEvents); + + // + return result; +} + +// +// Detect Trigger Conditions ... +bool DetectX121SMCXIOBPVSignalTrigger( + // + X121SMCStrategyXIOBPVSignalConditions &conditions, + // + string _symbol, + ENUM_TIMEFRAMES _period, + // + XC121SMCCycleHelper *triggerCycleHelper, + XC121SMCCycleHelper *decisionCycleHelper, + XC121SMCCycleHelper *analyseCycleHelper, + XC121SMCCycleHelper *verificationCycleHelper, + XC121SMCCycleHelper *consolidationCycleHelper, + XC121SMCCycleHelper *visionCycleHelper, + // + int maxAllowedSetupAge = 60 // + // +) +{ + // + bool result = false; + + // + result = conditions.IsSetuped(); + if (!result) + { + return result; + } + + // + datetime setupTime = conditions.setupTime; + ENUM_X_DIRECTION setupDir = conditions.dir; + + // + bool isBullish = IsBullish(setupDir); + bool isBearish = IsBearish(setupDir); + + // + int zIndex = 0; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + int loopback = 10; + + // + string symbol = _symbol; + ENUM_TIMEFRAMES period = _period; + + // + XOHCL zBar; + result = decisionCycleHelper.GetBar( + zBar, + zIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL cBar; + result = decisionCycleHelper.GetBar( + cBar, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = decisionCycleHelper.GetBar( + pBar, + pIndex // + ); + if (!result) + { + return result; + } + + // + double ask = GetAsk(symbol); + double bid = GetBid(symbol); + datetime cTime = TimeCurrent(); + double points = GetPoints(symbol); + + // + int swingLoopback = 9; + double ll = cBar.FindLowest(swingLoopback, MODE_LOW); + double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); + double llDown = cBar.FindLowesttDown(swingLoopback); + double hhUp = cBar.FindHighestUp(swingLoopback); + + // + // Cycles Conditions ... + + // + // Decision ... + ENUM_XPOI_EVENTS decisionPoiEvents[]; + ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; + X121SMCCycleConditions decisionConditions; + result = decisionCycleHelper.GetConditions( + decisionCycleEvents, + decisionPoiEvents, + decisionConditions, + zIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + // Cycles POI States ... + XPOIState decisionState = decisionConditions.state; + + // + // Cycle X121Conditions ... + X121Conditions decisionXConditions = decisionConditions.x121Conditions; + + // + // Trigger Conditions ... + + // + // Slopes ... + + // + bool isRsiSlopeBullish = decisionXConditions.isRsiSlopeBullish; + bool isStrSlopeBullish = decisionXConditions.isStrSlopeBullish; + bool isAtrUpperSlopeBullish = decisionXConditions.isAtrUpperSlopeBullish; + bool isAtrLowerSlopeBullish = decisionXConditions.isAtrLowerSlopeBullish; + bool isVwapFastSlopeBullish = decisionXConditions.isVwapFastSlopeBullish; + bool isVwapMidSlopeBullish = decisionXConditions.isVwapMidSlopeBullish; + bool isVwapSlowSlopeBullish = decisionXConditions.isVwapSlowSlopeBullish; + + // + bool isRsiSlopeBearish = decisionXConditions.isRsiSlopeBearish; + bool isStrSlopeBearish = decisionXConditions.isStrSlopeBearish; + bool isAtrUpperSlopeBearish = decisionXConditions.isAtrUpperSlopeBearish; + bool isAtrLowerSlopeBearish = decisionXConditions.isAtrLowerSlopeBearish; + bool isVwapFastSlopeBearish = decisionXConditions.isVwapFastSlopeBearish; + bool isVwapMidSlopeBearish = decisionXConditions.isVwapMidSlopeBearish; + bool isVwapSlowSlopeBearish = decisionXConditions.isVwapSlowSlopeBearish; + + // + bool isSlopesBullish = + isRsiSlopeBullish && + isStrSlopeBullish && + isAtrUpperSlopeBullish && + isAtrLowerSlopeBullish && + isVwapFastSlopeBullish && + isVwapMidSlopeBullish && + isVwapSlowSlopeBullish; + + // + bool isSlopesBearish = + isRsiSlopeBearish && + isStrSlopeBearish && + isAtrUpperSlopeBearish && + isAtrLowerSlopeBearish && + isVwapFastSlopeBearish && + isVwapMidSlopeBearish && + isVwapSlowSlopeBearish; + + // + double point = conditions.point; + bool isPointBreaked = IsBarBreak( + point, + setupDir, + cBar // + ); + + // + // Summary ... + + // + isBullish = + // + isBullish && + isPointBreaked && + isSlopesBullish + // + ; + + // + isBearish = + // + isBearish && + isPointBreaked && + isSlopesBearish + // + ; + + // + result = isBullish || + isBearish; + if (!result) + { + // + // Cleanup Setup Conditions ... + int setupAge = conditions.GetSetupAge(); + if (IsValidSize(setupAge) && + IsValidSize(maxAllowedSetupAge) && + setupAge >= maxAllowedSetupAge) + { + conditions.Clean(); + } + + // + // Cleanup Arrays ... + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + + // + return result; + } + + // + // Detect Nearest Pivot Point ... + + // + double entry = GetEntry( + conditions.symbol, + setupDir // + ); + + // + double sls[]; + Add( + conditions.pivot, + sls // + ); + + // + double iAtr = decisionConditions.x121Conditions.atrBuffer[1]; + iAtr *= 1.5; + + // + double slsMin = GetMin(sls); + double slsMax = GetMax(sls); + + // + double sl = isBullish + ? slsMin - iAtr + : slsMax + iAtr; + double risk = MathAbs(entry - sl); + + // + // Filling Conditions Props ... + conditions.sl = sl; + // conditions.target = target; + conditions.triggerTime = cTime; + conditions.type = isBullish + ? X_POSITION_TYPE_LONG + : X_POSITION_TYPE_SHORT; + + // + // Cleanup Arrays ... + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + + // + return result; +} + +// +// Detect Guards ... +bool DetectX121SMCXIOBPVGuards( + X121SMCGuard &guards[], + const XPosition &positions[], + XC121SMCCycleHelper *triggerCycleHelper, + XC121SMCCycleHelper *decisionCycleHelper, + XC121SMCCycleHelper *analyseCycleHelper, + XC121SMCCycleHelper *verificationCycleHelper, + XC121SMCCycleHelper *consolidationCycleHelper, + XC121SMCCycleHelper *visionCycleHelper // +) +{ + // + bool result = false; + + // + string provider = ToString(X_121_SMC_PROVIDER_X); + + // + result = DetectX121SMCGuards( + provider, + guards, + positions, + triggerCycleHelper, + decisionCycleHelper, + analyseCycleHelper, + verificationCycleHelper, + consolidationCycleHelper, + visionCycleHelper, + // + true, // CloseOnTPNear Guard ... + true, // CloseLongsOnBearishTrend Guard ... + true, // CloseShortsOnBullishTrend Guard ... + true, // CloseAllWeekend Guard ... + true, // PartialCloseOnTrendChange Guard ... + true, // TrailStop Guard ... + true, // TrailTarget Guard ... + true // Hedge Guard ... + // + ); + + // + return result; +} + +// +// Add Conditions to Conditions Collection ... +int AddX121SMCXIOBPVConditionsIfNotExists( + X121SMCStrategyXIOBPVSignalConditions &item, + X121SMCStrategyXIOBPVSignalConditions &items[], + int maxAllowed = 10 // +) +{ + // + int result = 0; + + // + bool isSetuped = IsValid(item.setupTime) && + HasDirection(item.dir); + if (!isSetuped) + { + return result; + } + + // + int count = ArraySize(items); + if (IsValidSize(count)) + { + // + // Copy Original Items ... + X121SMCStrategyXIOBPVSignalConditions tmpItems[]; + Copy( + items, + tmpItems // + ); + + // + // Prese Item Data ... + bool isBullish = IsBullish(item.dir); + + // + for (int i = 0; i < count; i++) + { + // + X121SMCStrategyXIOBPVSignalConditions iItem = tmpItems[i]; + + // + bool canRemove = item.dir == iItem.dir && + item.pivot == iItem.pivot; + if (canRemove) + { + // + ArrayRemove( + items, + i, + 1 // + ); + } + } + + // + Clean(tmpItems); + } + + // + AddRef( + item, + items // + ); + + // + // Remove Olds ... + CleanupArray( + items, + maxAllowed // + ); + + // + result = ArraySize(items); + + // + return result; +} + +// diff --git a/X121SMCEA/Signals/x-121.smc.xobpv.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xobpv.signal.lib.mq5 index 7ae31ff7..e34126e3 100644 --- a/X121SMCEA/Signals/x-121.smc.xobpv.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xobpv.signal.lib.mq5 @@ -972,18 +972,18 @@ bool DetectX121SMCXOBPVSignalSetup( { // // 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); + Clean(triggerPoiEvents); + Clean(triggerCycleEvents); + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + Clean(analysePoiEvents); + Clean(analyseCycleEvents); + Clean(verificationPoiEvents); + Clean(verificationCycleEvents); + Clean(consolidationPoiEvents); + Clean(consolidationCycleEvents); + Clean(visionPoiEvents); + Clean(visionCycleEvents); // return result; @@ -998,18 +998,18 @@ bool DetectX121SMCXOBPVSignalSetup( // // 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); + Clean(triggerPoiEvents); + Clean(triggerCycleEvents); + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + Clean(analysePoiEvents); + Clean(analyseCycleEvents); + Clean(verificationPoiEvents); + Clean(verificationCycleEvents); + Clean(consolidationPoiEvents); + Clean(consolidationCycleEvents); + Clean(visionPoiEvents); + Clean(visionCycleEvents); // return result; @@ -1230,8 +1230,8 @@ bool DetectX121SMCXOBPVSignalTrigger( // // Cleanup Arrays ... - ArrayFree(decisionPoiEvents); - ArrayFree(decisionCycleEvents); + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); // return result; @@ -1278,8 +1278,8 @@ bool DetectX121SMCXOBPVSignalTrigger( // // Cleanup Arrays ... - ArrayFree(decisionPoiEvents); - ArrayFree(decisionCycleEvents); + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); // return result; diff --git a/X121SMCEA/Signals/x-121.smc.xobs.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xobs.signal.lib.mq5 new file mode 100644 index 00000000..c554378d --- /dev/null +++ b/X121SMCEA/Signals/x-121.smc.xobs.signal.lib.mq5 @@ -0,0 +1,1225 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 X121 SMC Signal Class +// ------------------------------------------------- +// Name: XOBS +// Description: provide all Signalling functions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Imports ... +// #include "../../Libraries/x-trade.lib" +#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" +#include "../Libraries/x-121.smc.guard.lib.mq5" +#include "../Libraries/x-121.smc.lib.mq5" + +// +// Definitions ... +struct X121SMCStrategyXOBSSignalConditions +{ + // + // Props ... + + // + string symbol; + ENUM_TIMEFRAMES period; + + // + double sl; + double target; + ENUM_X_DIRECTION dir; + ENUM_X_POSITION_TYPES type; + + // + // Setup Props ... + + // + datetime setupTime; + datetime triggerTime; + + // + double pivot; + double point; + + // + + // + // Constructor ... + X121SMCStrategyXOBSSignalConditions() + { + Clean(); + } + + // + // Tools ... + + /** + * Cleaning Up ... + */ + void Clean() + { + // + sl = 0; + target = 0; + + // + dir = X_DIRECTION_NONE; + type = X_POSITION_TYPE_NONE; + + // + symbol = NULL; + period = NULL; + setupTime = NULL; + triggerTime = NULL; + + // + ExtensionClean(); + } + + /** + * Check Condition is Setting Up ... + * + * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... + * + * @return ( bool ) + */ + bool IsSetuped() + { + // + bool result = false; + + // + result = IsValid(setupTime) && + HasDirection(dir); + if (!result) + { + return result; + } + + // + return result; + } + + /** + * Calculate Setup Age ... + * + * @return ( int ) + */ + int GetSetupAge() + { + // + int result = 0; + + // + if (!IsSetuped()) + { + return result; + } + + // + result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); + + // + return result; + } + + /** + * Detect How we Can Trigger Signal ... + * + * @return ( bool ) + */ + bool CanTrigger() + { + // + bool result = false; + + // + result = + // + sl > 0 && + IsValid(symbol) && + IsValid(period) && + IsValid(triggerTime) && + type != X_POSITION_TYPE_ALL && + type != X_POSITION_TYPE_NONE + // + ; + + // + return result; + } + + // + // Extensions ... + + /** + * Clean Additional Properties ... + */ + void ExtensionClean() + { + // + pivot = 0; + point = 0; + + // + } + + // +}; + +// +// Signaller Data Sources ... +X121SMCStrategyXOBSSignalConditions mXOBSConditions; +X121SMCStrategyXOBSSignalConditions mXOBSConditionsCollection[]; + +// +// Extension Functions ... + +// +// Detect Setup Conditions ... +bool DetectX121SMCXOBSSignalSetup( + string _symbol, + ENUM_TIMEFRAMES _period, + // + X121SMCStrategyXOBSSignalConditions &conditions, + // + XC121SMCCycleHelper *triggerCycleHelper, + XC121SMCCycleHelper *decisionCycleHelper, + XC121SMCCycleHelper *analyseCycleHelper, + XC121SMCCycleHelper *verificationCycleHelper, + XC121SMCCycleHelper *consolidationCycleHelper, + XC121SMCCycleHelper *visionCycleHelper, + // + int resetAfterUnActedZoneInMinutes = 120 + // +) +{ + // + bool result = false; + + // + bool isBullish = false; + bool isBearish = false; + + // + int zIndex = 0; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + int loopback = 10; + + // + string symbol = _symbol; + ENUM_TIMEFRAMES period = _period; + + // + conditions.symbol = symbol; + conditions.period = period; + + // + XC121SMCCycleHelper *barCycle = triggerCycleHelper; + + // + XOHCL zBar; + result = barCycle.GetBar( + zBar, + zIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL cBar; + result = barCycle.GetBar( + cBar, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = barCycle.GetBar( + pBar, + pIndex // + ); + if (!result) + { + return result; + } + + // + double ask = GetAsk(symbol); + double bid = GetBid(symbol); + datetime cTime = TimeCurrent(); + double points = GetPoints(symbol); + + // + int swingLoopback = 7; + double ll = cBar.FindLowest(swingLoopback, MODE_LOW); + double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); + double ll50 = cBar.FindLowest(50, MODE_LOW); + double hh50 = cBar.FindHighest(50, MODE_HIGH); + double llDown = cBar.FindLowesttDown(swingLoopback); + double hhUp = cBar.FindHighestUp(swingLoopback); + + // + // Cycles Conditions ... + + // + // Trigger ... + ENUM_XPOI_EVENTS triggerPoiEvents[]; + ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; + X121SMCCycleConditions triggerConditions; + result = triggerCycleHelper.GetConditions( + triggerCycleEvents, + triggerPoiEvents, + triggerConditions, + zIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + // Decision ... + ENUM_XPOI_EVENTS decisionPoiEvents[]; + ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; + X121SMCCycleConditions decisionConditions; + result = decisionCycleHelper.GetConditions( + decisionCycleEvents, + decisionPoiEvents, + decisionConditions, + zIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + // Analyse ... + ENUM_XPOI_EVENTS analysePoiEvents[]; + ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; + X121SMCCycleConditions analyseConditions; + result = analyseCycleHelper.GetConditions( + analyseCycleEvents, + analysePoiEvents, + analyseConditions, + zIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + // Verification ... + ENUM_XPOI_EVENTS verificationPoiEvents[]; + ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; + X121SMCCycleConditions verificationConditions; + result = verificationCycleHelper.GetConditions( + verificationCycleEvents, + verificationPoiEvents, + verificationConditions, + zIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + // Consolidation ... + ENUM_XPOI_EVENTS consolidationPoiEvents[]; + ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; + X121SMCCycleConditions consolidationConditions; + result = consolidationCycleHelper.GetConditions( + consolidationCycleEvents, + consolidationPoiEvents, + consolidationConditions, + zIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + // Vision ... + ENUM_XPOI_EVENTS visionPoiEvents[]; + ENUM_X_CYCLE_EVENTS visionCycleEvents[]; + X121SMCCycleConditions visionConditions; + result = visionCycleHelper.GetConditions( + visionCycleEvents, + visionPoiEvents, + visionConditions, + zIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + // Cycles POI States ... + XPOIState triggerState = triggerConditions.state; + XPOIState decisionState = decisionConditions.state; + XPOIState analyseState = analyseConditions.state; + XPOIState verificationState = verificationConditions.state; + XPOIState consolidationState = consolidationConditions.state; + XPOIState visionState = visionConditions.state; + + // + // Cycle X121Conditions ... + X121Conditions triggerXConditions = triggerConditions.x121Conditions; + X121Conditions decisionXConditions = decisionConditions.x121Conditions; + X121Conditions analyseXConditions = analyseConditions.x121Conditions; + X121Conditions verificationXConditions = verificationConditions.x121Conditions; + X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; + X121Conditions visionXConditions = visionConditions.x121Conditions; + + // + // Setup Conditions ... + + // + // Detect Trend ... + + // + // Consolidation ... + ENUM_X_DIRECTION consolidationTrendDir; + bool hasConsolidationTrend = + consolidationCycleHelper + .DetectMarketStructure( + consolidationTrendDir // + ); + bool hasConsolidationBullishTrend = + hasConsolidationTrend && + IsBullish(consolidationTrendDir); + bool hasConsolidationBearishTrend = + hasConsolidationTrend && + IsBearish(consolidationTrendDir); + + // + // Verification ... + ENUM_X_DIRECTION verificationTrendDir; + bool hasVerificationTrend = + verificationCycleHelper + .DetectMarketStructure( + verificationTrendDir // + ); + bool hasVerificationBullishTrend = + hasVerificationTrend && + IsBullish(verificationTrendDir); + bool hasVerificationBearishTrend = + hasVerificationTrend && + IsBearish(verificationTrendDir); + + // + // Analyse ... + ENUM_X_DIRECTION analyseTrendDir; + bool hasAnalyseTrend = + analyseCycleHelper + .DetectMarketStructure( + analyseTrendDir // + ); + bool hasAnalyseBullishTrend = + hasAnalyseTrend && + IsBullish(analyseTrendDir); + bool hasAnalyseBearishTrend = + hasAnalyseTrend && + IsBearish(analyseTrendDir); + + // + // Decision ... + ENUM_X_DIRECTION decisionTrendDir; + bool hasDecisionTrend = + decisionCycleHelper + .DetectMarketStructure( + decisionTrendDir // + ); + bool hasDecisionBullishTrend = + hasDecisionTrend && + IsBullish(decisionTrendDir); + bool hasDecisionBearishTrend = + hasDecisionTrend && + IsBearish(decisionTrendDir); + + // + // Detect Bar State ... + + // + // PinBar ... + ENUM_X_DIRECTION cBarPinDir; + bool isCBarPin = decisionCycleHelper + .mBarAnalyser + .IsPinBar( + cBar, + cBarPinDir, + 1 // + ); + bool isCBarBullishPin = + isCBarPin && + IsBullish(cBarPinDir); + bool isCBarBearishPin = + isCBarPin && + IsBearish(cBarPinDir); + + // + // Engulf ... + ENUM_X_DIRECTION cBarEngulfDir; + bool isCBarEngulfed = decisionCycleHelper + .mBarAnalyser + .IsEngulfBar( + cBar, + cBarEngulfDir, + 0 // Extended ... + ); + bool isCBarBullishEngulfed = + isCBarEngulfed && + IsBullish(cBarEngulfDir); + bool isCBarBearishEngulfed = + isCBarEngulfed && + IsBearish(cBarEngulfDir); + + // + // Momentum ... + ENUM_X_DIRECTION cBarMomentumDir; + bool isCBarMomentum = decisionCycleHelper + .mBarAnalyser + .IsMomentumBar( + cBar, + cBarMomentumDir, + 0 // Extended ... + ); + bool isCBarBullishMomentum = + isCBarMomentum && + IsBullish(cBarMomentumDir); + bool isCBarBearishMomentum = + isCBarMomentum && + IsBearish(cBarMomentumDir); + + // + // Reject ... + ENUM_X_DIRECTION cBarRejectDir; + bool isCBarRejected = decisionCycleHelper + .mBarAnalyser + .IsRejectionBar( + cBar, + cBarRejectDir, + 0 // Extended ... + ); + bool isCBarBullishRejected = + isCBarRejected && + IsBullish(cBarRejectDir); + bool isCBarBearishRejected = + isCBarRejected && + IsBearish(cBarRejectDir); + + // + // Pull Back ... + ENUM_X_DIRECTION cBarPullbackDir; + bool isCBarPullbacked = + decisionCycleHelper + .mBarAnalyser + .HasPullBack( + cBarPullbackDir, + cBar // + ); + bool isCBarBullishPullbacked = + isCBarPullbacked && + IsBullish(cBarPullbackDir); + bool isCBarBearishPullbacked = + isCBarPullbacked && + IsBearish(cBarPullbackDir); + + // + // HH/LL Break ... + + // + bool isCBarBreaksUpHH = IsBarBreak( + hh, + X_DIRECTION_BULLISH, + cBar // + ); + + // + bool isCBarBreaksDownLL = IsBarBreak( + hh, + X_DIRECTION_BEARISH, + cBar // + ); + + // + // Bars Pattern and Power and Pressures ... + + // + bool hasCBarBullishPattern = + decisionCycleHelper + .mBarAnalyser + .HasBullishPattern( + cBar, + 2 // + ); + + // + bool hasCBarBearishPattern = + decisionCycleHelper + .mBarAnalyser + .HasBearishPattern( + cBar, + 2 // + ); + + // + bool isCBarHasBullishPower = + decisionCycleHelper + .mBarAnalyser + .HasBullishPower( + cBar, + 2 // + ); + + // + bool isCBarHasBearishPower = + decisionCycleHelper + .mBarAnalyser + .HasBearishPower( + cBar, + 2 // + ); + + // + bool isCBarHasBullishPressure = + decisionCycleHelper + .mBarAnalyser + .HasBullishPressure( + cBar, + 2 // + ); + + // + bool isCBarHasBearishPressure = + decisionCycleHelper + .mBarAnalyser + .HasBearishPressure( + cBar, + 2 // + ); + + // + // Bar Checking Summary ... + + // + // Bullish ... + bool isCBarBullishFormed = + // + ( + // + hasCBarBullishPattern && + isCBarHasBullishPower && + isCBarHasBullishPressure + // + ) + // + || + // + ( + // + isCBarBullishPin || + isCBarBreaksUpHH || + isCBarBullishEngulfed || + isCBarBullishMomentum || + isCBarBullishRejected + // + ) + // + ; + + // + // Bearish ... + bool isCBarBearishFormed = + // + ( + // + hasCBarBearishPattern && + isCBarHasBearishPower && + isCBarHasBearishPressure + // + ) + // + || + // + ( + // + isCBarBearishPin || + isCBarBreaksDownLL || + isCBarBearishEngulfed || + isCBarBearishMomentum || + isCBarBearishRejected + // + ) + // + ; + + // + // Detect Cycle State ... + + // + double upper = 0; + double lower = 0; + + // + // + // + + // + // Summarize Conditions ... + + // + bool isCondition1Bullish = + // + false + // + ; + + // + bool isCondition1Bearish = + // + false + // + ; + + // + bool hasCondition1 = isCondition1Bullish || + isCondition1Bearish; + if (hasCondition1) + { + // + ENUM_X_DIRECTION pzDir = + isCondition1Bullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + double point = GetEntry( + conditions.symbol, + pzDir // + ); + + // + double longPivot = lower; // triggerXConditions.valesBuffer[1]; + double shortPivot = upper; // triggerXConditions.peaksBuffer[1]; + + // + // Manipulate Conditions Point ... + + // + conditions.point = + isCondition1Bullish + ? shortPivot + : longPivot; + + // + // Manipulate Conditions Pivot ... + + // + conditions.pivot = + isCondition1Bullish + ? longPivot + : shortPivot; + } + + // + // + // + + // + isBullish = + // + isCondition1Bullish + // + ; + + // + isBearish = + // + isCondition1Bearish + // + ; + + // + result = isBullish || + isBearish; + if (!result) + { + // + // Detect PriceOB Lifetime Bars ... + + // + // Cleanup Arrays ... + Clean(triggerPoiEvents); + Clean(triggerCycleEvents); + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + Clean(analysePoiEvents); + Clean(analyseCycleEvents); + Clean(verificationPoiEvents); + Clean(verificationCycleEvents); + Clean(consolidationPoiEvents); + Clean(consolidationCycleEvents); + Clean(visionPoiEvents); + Clean(visionCycleEvents); + + // + return result; + } + + // + conditions.setupTime = cTime; + conditions.dir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + // Cleanup Arrays ... + Clean(triggerPoiEvents); + Clean(triggerCycleEvents); + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + Clean(analysePoiEvents); + Clean(analyseCycleEvents); + Clean(verificationPoiEvents); + Clean(verificationCycleEvents); + Clean(consolidationPoiEvents); + Clean(consolidationCycleEvents); + Clean(visionPoiEvents); + Clean(visionCycleEvents); + + // + return result; +} + +// +// Detect Trigger Conditions ... +bool DetectX121SMCXOBSSignalTrigger( + // + X121SMCStrategyXOBSSignalConditions &conditions, + // + string _symbol, + ENUM_TIMEFRAMES _period, + // + XC121SMCCycleHelper *triggerCycleHelper, + XC121SMCCycleHelper *decisionCycleHelper, + XC121SMCCycleHelper *analyseCycleHelper, + XC121SMCCycleHelper *verificationCycleHelper, + XC121SMCCycleHelper *consolidationCycleHelper, + XC121SMCCycleHelper *visionCycleHelper, + // + int maxAllowedSetupAge = 60 // + // +) +{ + // + bool result = false; + + // + result = conditions.IsSetuped(); + if (!result) + { + return result; + } + + // + datetime setupTime = conditions.setupTime; + ENUM_X_DIRECTION setupDir = conditions.dir; + + // + bool isBullish = IsBullish(setupDir); + bool isBearish = IsBearish(setupDir); + + // + int zIndex = 0; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + int loopback = 10; + + // + string symbol = _symbol; + ENUM_TIMEFRAMES period = _period; + + // + XOHCL zBar; + result = decisionCycleHelper.GetBar( + zBar, + zIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL cBar; + result = decisionCycleHelper.GetBar( + cBar, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = decisionCycleHelper.GetBar( + pBar, + pIndex // + ); + if (!result) + { + return result; + } + + // + double ask = GetAsk(symbol); + double bid = GetBid(symbol); + datetime cTime = TimeCurrent(); + double points = GetPoints(symbol); + + // + int swingLoopback = 9; + double ll = cBar.FindLowest(swingLoopback, MODE_LOW); + double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); + double llDown = cBar.FindLowesttDown(swingLoopback); + double hhUp = cBar.FindHighestUp(swingLoopback); + + // + // Cycles Conditions ... + + // + // Decision ... + ENUM_XPOI_EVENTS decisionPoiEvents[]; + ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; + X121SMCCycleConditions decisionConditions; + result = decisionCycleHelper.GetConditions( + decisionCycleEvents, + decisionPoiEvents, + decisionConditions, + zIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + // Cycles POI States ... + XPOIState decisionState = decisionConditions.state; + + // + // Cycle X121Conditions ... + X121Conditions decisionXConditions = decisionConditions.x121Conditions; + + // + // Trigger Conditions ... + + // + // Slopes ... + + // + bool isRsiSlopeBullish = decisionXConditions.isRsiSlopeBullish; + bool isStrSlopeBullish = decisionXConditions.isStrSlopeBullish; + bool isAtrUpperSlopeBullish = decisionXConditions.isAtrUpperSlopeBullish; + bool isAtrLowerSlopeBullish = decisionXConditions.isAtrLowerSlopeBullish; + bool isVwapFastSlopeBullish = decisionXConditions.isVwapFastSlopeBullish; + bool isVwapMidSlopeBullish = decisionXConditions.isVwapMidSlopeBullish; + bool isVwapSlowSlopeBullish = decisionXConditions.isVwapSlowSlopeBullish; + + // + bool isRsiSlopeBearish = decisionXConditions.isRsiSlopeBearish; + bool isStrSlopeBearish = decisionXConditions.isStrSlopeBearish; + bool isAtrUpperSlopeBearish = decisionXConditions.isAtrUpperSlopeBearish; + bool isAtrLowerSlopeBearish = decisionXConditions.isAtrLowerSlopeBearish; + bool isVwapFastSlopeBearish = decisionXConditions.isVwapFastSlopeBearish; + bool isVwapMidSlopeBearish = decisionXConditions.isVwapMidSlopeBearish; + bool isVwapSlowSlopeBearish = decisionXConditions.isVwapSlowSlopeBearish; + + // + bool isSlopesBullish = + isRsiSlopeBullish && + isStrSlopeBullish && + isAtrUpperSlopeBullish && + isAtrLowerSlopeBullish && + isVwapFastSlopeBullish && + isVwapMidSlopeBullish && + isVwapSlowSlopeBullish; + + // + bool isSlopesBearish = + isRsiSlopeBearish && + isStrSlopeBearish && + isAtrUpperSlopeBearish && + isAtrLowerSlopeBearish && + isVwapFastSlopeBearish && + isVwapMidSlopeBearish && + isVwapSlowSlopeBearish; + + // + double point = conditions.point; + bool isPointBreaked = IsBarBreak( + point, + setupDir, + cBar // + ); + + // + // Summary ... + + // + isBullish = + // + isBullish && + isPointBreaked && + isSlopesBullish + // + ; + + // + isBearish = + // + isBearish && + isPointBreaked && + isSlopesBearish + // + ; + + // + result = isBullish || + isBearish; + if (!result) + { + // + // Cleanup Setup Conditions ... + int setupAge = conditions.GetSetupAge(); + if (IsValidSize(setupAge) && + IsValidSize(maxAllowedSetupAge) && + setupAge >= maxAllowedSetupAge) + { + conditions.Clean(); + } + + // + // Cleanup Arrays ... + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + + // + return result; + } + + // + // Detect Nearest Pivot Point ... + + // + double entry = GetEntry( + conditions.symbol, + setupDir // + ); + + // + double sls[]; + Add( + conditions.pivot, + sls // + ); + + // + double iAtr = decisionConditions.x121Conditions.atrBuffer[1]; + iAtr *= 1.5; + + // + double slsMin = GetMin(sls); + double slsMax = GetMax(sls); + + // + double sl = isBullish + ? slsMin - iAtr + : slsMax + iAtr; + double risk = MathAbs(entry - sl); + + // + // Filling Conditions Props ... + conditions.sl = sl; + // conditions.target = target; + conditions.triggerTime = cTime; + conditions.type = isBullish + ? X_POSITION_TYPE_LONG + : X_POSITION_TYPE_SHORT; + + // + // Cleanup Arrays ... + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + + // + return result; +} + +// +// Detect Guards ... +bool DetectX121SMCXOBSGuards( + X121SMCGuard &guards[], + const XPosition &positions[], + XC121SMCCycleHelper *triggerCycleHelper, + XC121SMCCycleHelper *decisionCycleHelper, + XC121SMCCycleHelper *analyseCycleHelper, + XC121SMCCycleHelper *verificationCycleHelper, + XC121SMCCycleHelper *consolidationCycleHelper, + XC121SMCCycleHelper *visionCycleHelper // +) +{ + // + bool result = false; + + // + string provider = ToString(X_121_SMC_PROVIDER_X); + + // + result = DetectX121SMCGuards( + provider, + guards, + positions, + triggerCycleHelper, + decisionCycleHelper, + analyseCycleHelper, + verificationCycleHelper, + consolidationCycleHelper, + visionCycleHelper, + // + true, // CloseOnTPNear Guard ... + true, // CloseLongsOnBearishTrend Guard ... + true, // CloseShortsOnBullishTrend Guard ... + true, // CloseAllWeekend Guard ... + true, // PartialCloseOnTrendChange Guard ... + true, // TrailStop Guard ... + true, // TrailTarget Guard ... + true // Hedge Guard ... + // + ); + + // + return result; +} + +// +// Add Conditions to Conditions Collection ... +int AddX121SMCXOBSConditionsIfNotExists( + X121SMCStrategyXOBSSignalConditions &item, + X121SMCStrategyXOBSSignalConditions &items[], + int maxAllowed = 10 // +) +{ + // + int result = 0; + + // + bool isSetuped = IsValid(item.setupTime) && + HasDirection(item.dir); + if (!isSetuped) + { + return result; + } + + // + int count = ArraySize(items); + if (IsValidSize(count)) + { + // + // Copy Original Items ... + X121SMCStrategyXOBSSignalConditions tmpItems[]; + Copy( + items, + tmpItems // + ); + + // + // Prese Item Data ... + bool isBullish = IsBullish(item.dir); + + // + for (int i = 0; i < count; i++) + { + // + X121SMCStrategyXOBSSignalConditions iItem = tmpItems[i]; + + // + bool canRemove = item.dir == iItem.dir && + item.pivot == iItem.pivot; + if (canRemove) + { + // + ArrayRemove( + items, + i, + 1 // + ); + } + } + + // + Clean(tmpItems); + } + + // + AddRef( + item, + items // + ); + + // + // Remove Olds ... + CleanupArray( + items, + maxAllowed // + ); + + // + result = ArraySize(items); + + // + return result; +} + +// diff --git a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 index 426a9a0c..5f6a1c93 100644 --- a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 @@ -28,8 +28,10 @@ // #include "../Signals/x-121.smc.x.signal.lib.mq5" +#include "../Signals/x-121.smc.xobs.signal.lib.mq5" #include "../Signals/x-121.smc.xhkpv.signal.lib.mq5" #include "../Signals/x-121.smc.xobpv.signal.lib.mq5" +#include "../Signals/x-121.smc.xiobpv.signal.lib.mq5" // // Definitions ... @@ -44,8 +46,10 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // // Props ... bool useXSignal; + bool useXOBSSignal; bool useXHKPVSignal; bool useXOBPVSignal; + bool useXIOBPVSignal; // // Constructor(s) ... @@ -68,9 +72,11 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy Destroy(); // - ArrayFree(mXConditionsCollection); - ArrayFree(mXHKPVConditionsCollection); - ArrayFree(mXOBPVConditionsCollection); + Clean(mXConditionsCollection); + Clean(mXOBSConditionsCollection); + Clean(mXHKPVConditionsCollection); + Clean(mXOBPVConditionsCollection); + Clean(mXIOBPVConditionsCollection); } // @@ -197,8 +203,10 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // bool hasXSignal = false; + bool hasXOBSSignal = false; bool hasXHKPVSignal = false; bool hasXOBPVSignal = false; + bool hasXIOBPVSignal = false; // // X Signal ... @@ -209,6 +217,15 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy hasSignal = hasXSignal; } + // + // XOBS Signal ... + if (useXOBSSignal && !hasSignal) + { + // + hasXOBSSignal = DetectXOBSSignal(conditions); + hasSignal = hasXOBSSignal; + } + // // XHKPV Signal ... if (useXHKPVSignal && !hasSignal) @@ -227,6 +244,15 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy hasSignal = hasXOBPVSignal; } + // + // XIOBPV Signal ... + if (useXIOBPVSignal && !hasSignal) + { + // + hasXIOBPVSignal = DetectXIOBPVSignal(conditions); + hasSignal = hasXIOBPVSignal; + } + // result = hasSignal; if (!result) @@ -399,6 +425,23 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy ); } + // + // XOBS Guard Detection ... + if (useXOBSSignal) + { + // + bool hasGuard = DetectX121SMCXOBSGuards( + guards, + positions, + mTriggerCycleHelper, + mDecisionCycleHelper, + mAnalyseCycleHelper, + mVerificationCycleHelper, + mConsolidationCycleHelper, + mVisionCycleHelper // + ); + } + // // XHKPV Guard Detection ... if (useXHKPVSignal) @@ -417,7 +460,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy } // - // XPZ Guard Detection ... + // XOBPV Guard Detection ... if (useXOBPVSignal) { // @@ -433,6 +476,23 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy ); } + // + // XIOBPV Guard Detection ... + if (useXIOBPVSignal) + { + // + bool hasGuard = DetectX121SMCXIOBPVGuards( + guards, + positions, + mTriggerCycleHelper, + mDecisionCycleHelper, + mAnalyseCycleHelper, + mVerificationCycleHelper, + mConsolidationCycleHelper, + mVisionCycleHelper // + ); + } + // count = ArraySize(guards); result = IsValidSize(count); @@ -706,6 +766,224 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy return result; } + // + // XOBS Signal ... + bool DetectXOBSSignal( + X121SMCStrategyConditions &conditions // + ) + { + // + bool result = false; + + // + bool isBullish = false; + bool isBearish = false; + + // + int zIndex = 0; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + string symbol = GetSymbol(); + ENUM_TIMEFRAMES period = GetPeriod(); + + // + XOHCL zBar; + result = zBar.Init( + symbol, + period, + zIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL cBar; + result = cBar.Init( + symbol, + period, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = pBar.Init( + symbol, + period, + pIndex // + ); + if (!result) + { + return result; + } + + // + double cLL = cBar.FindLowest(7, MODE_LOW); + double cHH = cBar.FindHighest(7, MODE_HIGH); + + // + datetime cTime = TimeCurrent(); + + // + ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XOBS; + string providerStr = ToString(provider); + + // + // Detect Setup Conditions ... + datetime setupTime = mXOBSConditions.setupTime; + bool isSetuped = mXOBSConditions.IsSetuped(); + ENUM_X_DIRECTION setupDir = mXOBSConditions.dir; + if (!isSetuped) + { + // + // Detect Signal Setup ... + isSetuped = DetectX121SMCXOBSSignalSetup( + symbol, + period, + mXOBSConditions, + mTriggerCycleHelper, + mDecisionCycleHelper, + mAnalyseCycleHelper, + mVerificationCycleHelper, + mConsolidationCycleHelper, + mVisionCycleHelper // + ); + + // + setupDir = mXOBSConditions.dir; + setupTime = mXOBSConditions.setupTime; + + // + if (isSetuped) + { + // + int items = AddX121SMCXOBSConditionsIfNotExists( + mXOBSConditions, + mXOBSConditionsCollection // + ); + + // + mXOBSConditions.Clean(); + } + } + + // + int conditionsCount = ArraySize(mXOBSConditionsCollection); + result = IsValidSize(conditionsCount); + if (!result) + { + return result; + } + + // + // Looking For Conditions ... + int selectedIndex = 0; + X121SMCStrategyXOBSSignalConditions mTmpConditions[]; + Copy( + mXOBSConditionsCollection, + mTmpConditions // + ); + X121SMCStrategyXOBSSignalConditions mConditions; + for (int i = 0; i < conditionsCount; i++) + { + // + // Check Triggers ... + bool canTrigger = mTmpConditions[i].CanTrigger(); + datetime triggerTime = mTmpConditions[i].triggerTime; + if (!canTrigger) + { + // + // Detect Signal Trigger ... + canTrigger = DetectX121SMCXOBSSignalTrigger( + mTmpConditions[i], + symbol, + period, + mTriggerCycleHelper, + mDecisionCycleHelper, + mAnalyseCycleHelper, + mVerificationCycleHelper, + mConsolidationCycleHelper, + mVisionCycleHelper // + ); + + // + result = canTrigger; + if (!result) + { + // + bool isISetuped = mTmpConditions[i].IsSetuped(); + if (!isISetuped) + { + // + ArrayRemove( + mXOBSConditionsCollection, + i, + 1 // + ); + } + continue; + } + + // + triggerTime = mTmpConditions[i].triggerTime; + } + + // + if (canTrigger) + { + // + selectedIndex = i; + mConditions = mTmpConditions[i]; + break; + } + } + + // + result = IsValid(mConditions.setupTime) && + HasDirection(mConditions.dir); + if (!result) + { + return result; + } + + // + // Remove Selected Index from Main Collection ... + ArrayRemove( + mXOBSConditionsCollection, + selectedIndex, + 1 // + ); + + // + // Check Signal Direction ... + isBullish = IsBullish(mConditions.dir); + isBearish = IsBearish(mConditions.dir); + result = isBullish || + isBearish; + if (!result) + { + return result; + } + + // + // Issues Signal on Conditions ... + conditions.sl = mConditions.sl; + conditions.provider = providerStr; + conditions.signalDir = mConditions.dir; + conditions.target = mConditions.target; + + // + return result; + } + // // XHKPV Signal ... bool DetectXHKPVSignal( @@ -1142,6 +1420,224 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy return result; } + // + // XIOBPV Signal ... + bool DetectXIOBPVSignal( + X121SMCStrategyConditions &conditions // + ) + { + // + bool result = false; + + // + bool isBullish = false; + bool isBearish = false; + + // + int zIndex = 0; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + string symbol = GetSymbol(); + ENUM_TIMEFRAMES period = GetPeriod(); + + // + XOHCL zBar; + result = zBar.Init( + symbol, + period, + zIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL cBar; + result = cBar.Init( + symbol, + period, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = pBar.Init( + symbol, + period, + pIndex // + ); + if (!result) + { + return result; + } + + // + double cLL = cBar.FindLowest(7, MODE_LOW); + double cHH = cBar.FindHighest(7, MODE_HIGH); + + // + datetime cTime = TimeCurrent(); + + // + ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XIOBPV; + string providerStr = ToString(provider); + + // + // Detect Setup Conditions ... + datetime setupTime = mXIOBPVConditions.setupTime; + bool isSetuped = mXIOBPVConditions.IsSetuped(); + ENUM_X_DIRECTION setupDir = mXIOBPVConditions.dir; + if (!isSetuped) + { + // + // Detect Signal Setup ... + isSetuped = DetectX121SMCXIOBPVSignalSetup( + symbol, + period, + mXIOBPVConditions, + mTriggerCycleHelper, + mDecisionCycleHelper, + mAnalyseCycleHelper, + mVerificationCycleHelper, + mConsolidationCycleHelper, + mVisionCycleHelper // + ); + + // + setupDir = mXIOBPVConditions.dir; + setupTime = mXIOBPVConditions.setupTime; + + // + if (isSetuped) + { + // + int items = AddX121SMCXIOBPVConditionsIfNotExists( + mXIOBPVConditions, + mXIOBPVConditionsCollection // + ); + + // + mXIOBPVConditions.Clean(); + } + } + + // + int conditionsCount = ArraySize(mXIOBPVConditionsCollection); + result = IsValidSize(conditionsCount); + if (!result) + { + return result; + } + + // + // Looking For Conditions ... + int selectedIndex = 0; + X121SMCStrategyXIOBPVSignalConditions mTmpConditions[]; + Copy( + mXIOBPVConditionsCollection, + mTmpConditions // + ); + X121SMCStrategyXIOBPVSignalConditions mConditions; + for (int i = 0; i < conditionsCount; i++) + { + // + // Check Triggers ... + bool canTrigger = mTmpConditions[i].CanTrigger(); + datetime triggerTime = mTmpConditions[i].triggerTime; + if (!canTrigger) + { + // + // Detect Signal Trigger ... + canTrigger = DetectX121SMCXIOBPVSignalTrigger( + mTmpConditions[i], + symbol, + period, + mTriggerCycleHelper, + mDecisionCycleHelper, + mAnalyseCycleHelper, + mVerificationCycleHelper, + mConsolidationCycleHelper, + mVisionCycleHelper // + ); + + // + result = canTrigger; + if (!result) + { + // + bool isISetuped = mTmpConditions[i].IsSetuped(); + if (!isISetuped) + { + // + ArrayRemove( + mXIOBPVConditionsCollection, + i, + 1 // + ); + } + continue; + } + + // + triggerTime = mTmpConditions[i].triggerTime; + } + + // + if (canTrigger) + { + // + selectedIndex = i; + mConditions = mTmpConditions[i]; + break; + } + } + + // + result = IsValid(mConditions.setupTime) && + HasDirection(mConditions.dir); + if (!result) + { + return result; + } + + // + // Remove Selected Index from Main Collection ... + ArrayRemove( + mXIOBPVConditionsCollection, + selectedIndex, + 1 // + ); + + // + // Check Signal Direction ... + isBullish = IsBullish(mConditions.dir); + isBearish = IsBearish(mConditions.dir); + result = isBullish || + isBearish; + if (!result) + { + return result; + } + + // + // Issues Signal on Conditions ... + conditions.sl = mConditions.sl; + conditions.provider = providerStr; + conditions.signalDir = mConditions.dir; + conditions.target = mConditions.target; + + // + return result; + } + // // Private ... private: @@ -1158,8 +1654,10 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy { // useXSignal = false; - useXHKPVSignal = true; - useXOBPVSignal = true; + useXOBSSignal = true; + useXHKPVSignal = false; + useXOBPVSignal = false; + useXIOBPVSignal = false; // string symbol = GetSymbol();