From b9ce179fa308ee65880cb61fc007995d61c3f268 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Fri, 14 Feb 2025 09:21:04 +0330 Subject: [PATCH] last ... --- .../xsupdem}/x-121.smc.expert.alert.class.mq5 | 0 .../x-saherelm.x-121.smc.alert.ea.mq5 | 0 Experts/x-saherelm.x-121.smc.ea.mq5 | 2 +- Libraries/x-saherelm.x-poi.lib.mq5 | 80 + X121SMCEA/Libraries/x-121.smc.lib.mq5 | 13 +- .../Signals/x-121.smc.xwz.signal.class.mq5 | 2171 +++++++++++++++++ .../Signals/x-121.smc.xwz.signal.lib.mq5 | 824 +++++++ .../Strategy/x-121.smc.strategy.class.mq5 | 431 +++- 8 files changed, 3451 insertions(+), 70 deletions(-) rename {X121SMCEA/Experts => Documents/BKP/xsupdem}/x-121.smc.expert.alert.class.mq5 (100%) rename {Experts => Documents/BKP/xsupdem}/x-saherelm.x-121.smc.alert.ea.mq5 (100%) create mode 100644 X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 create mode 100644 X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 diff --git a/X121SMCEA/Experts/x-121.smc.expert.alert.class.mq5 b/Documents/BKP/xsupdem/x-121.smc.expert.alert.class.mq5 similarity index 100% rename from X121SMCEA/Experts/x-121.smc.expert.alert.class.mq5 rename to Documents/BKP/xsupdem/x-121.smc.expert.alert.class.mq5 diff --git a/Experts/x-saherelm.x-121.smc.alert.ea.mq5 b/Documents/BKP/xsupdem/x-saherelm.x-121.smc.alert.ea.mq5 similarity index 100% rename from Experts/x-saherelm.x-121.smc.alert.ea.mq5 rename to Documents/BKP/xsupdem/x-saherelm.x-121.smc.alert.ea.mq5 diff --git a/Experts/x-saherelm.x-121.smc.ea.mq5 b/Experts/x-saherelm.x-121.smc.ea.mq5 index a06703c3..24ebc11b 100644 --- a/Experts/x-saherelm.x-121.smc.ea.mq5 +++ b/Experts/x-saherelm.x-121.smc.ea.mq5 @@ -265,7 +265,7 @@ void OnTick() // Handle On Trade Event ... void OnTrade() { - eaExpert.HandleOnTrade(); + eaExpert.HandleOnTrade(); } // diff --git a/Libraries/x-saherelm.x-poi.lib.mq5 b/Libraries/x-saherelm.x-poi.lib.mq5 index f4208c51..ce729fdb 100644 --- a/Libraries/x-saherelm.x-poi.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.lib.mq5 @@ -7528,6 +7528,86 @@ bool IsBelowBox( return result; } +/** + * Check a Box is Used or not ... + * + * @param box: XBoxZone instance Reference ... + * @param fromIndex: int ... + * @param toIndex: int + * @param forPeriod: Specified Period ... + * + * @return ( bool ) + */ +bool IsBoxUsed( + XBoxZone &box, + int fromIndex, + int toIndex = 0, + ENUM_TIMEFRAMES forPeriod = NULL // +) +{ + // + bool result = false; + + // + if (toIndex < 0) + { + toIndex = 0; + } + + // + result = + // + box.IsValid() + fromIndex > 0 && + fromIndex > toIndex + // + ; + if (!result) + { + return result; + } + + // + if (!IsValid(forPeriod)) + { + forPeriod = box.period; + } + + // + EUM_X_DIRECT forDir = box.dir; + bool isBllish = IsBullish(forDir); + + // + for (int i = fromIndex; i >= toIndex; i--) + { + // + XOHCL iBar; + bool isInited = iBar.Init( + box.symbol, + forPeriod, + i // + ); + + // + bool isTouched = + isBullish + ? iBar.high > box.lower + : iBar.low < box.upper; + if (!isTouched) + { + continue; + } + + // + iBar.Clean(); + result = false; + break; + } + + // + return result; +} + // bool IsRejectBox( ENUM_X_DIRECTION &forDir, diff --git a/X121SMCEA/Libraries/x-121.smc.lib.mq5 b/X121SMCEA/Libraries/x-121.smc.lib.mq5 index ec1251a7..085aac6d 100644 --- a/X121SMCEA/Libraries/x-121.smc.lib.mq5 +++ b/X121SMCEA/Libraries/x-121.smc.lib.mq5 @@ -35,6 +35,7 @@ const string X121SMCStrategyToken = "X121SMC"; // +const string X121SMCXWZToken = "X121XWZ"; const string X121SMCXSupDemOBSToken = "X121XSupDemOBS"; // @@ -43,6 +44,7 @@ enum ENUM_X_121_SMC_PROVIDERS { // X_121_SMC_PROVIDER_NONE, + X_121_SMC_PROVIDER_XWZ, X_121_SMC_PROVIDER_XSUPDEMOBS, }; @@ -693,6 +695,11 @@ string ToString(ENUM_X_121_SMC_PROVIDERS value) switch (value) { // + case X_121_SMC_PROVIDER_XWZ: + result = X121SMCXWZToken; + break; + + // case X_121_SMC_PROVIDER_XSUPDEMOBS: result = X121SMCXSupDemOBSToken; break; @@ -721,7 +728,11 @@ ENUM_X_121_SMC_PROVIDERS ParseProvider(string value) } // - if (Contains(X121SMCXSupDemOBSToken, value)) + if (Contains(X121SMCXWZToken, value)) + { + result = X_121_SMC_PROVIDER_XWZ; + } + else if (Contains(X121SMCXSupDemOBSToken, value)) { result = X_121_SMC_PROVIDER_XSUPDEMOBS; } diff --git a/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 b/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 new file mode 100644 index 00000000..733db5d2 --- /dev/null +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 @@ -0,0 +1,2171 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 X121 SMC Signal Class +// ------------------------------------------------- +// Name: XWZ +// 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 "../Classes/x-121.smc.market.cycle.helper.class.mq5" +#include "../Libraries/x-121.smc.guard.lib.mq5" +#include "../Libraries/x-121.smc.lib.mq5" +#include "./x-121.smc.xwz.signal.lib.mq5" + +// +// Definition ... +class XCX121SMCXWZSignalDetector : public XCBase +{ + // + public: + // + // Props ... + X121SMCStrategyXWZSignalConditions mConditions; + X121SMCStrategyXWZSignalConditions mConditionsCollection[]; + + // + // Constructor(s) ... + XCX121SMCXWZSignalDetector() + { + Init(); + } + + // + // Deconstructor ... + ~XCX121SMCXWZSignalDetector() + { + DeInit(); + } + + // + // + // + + // + // Detect Setup Conditions ... + bool DetectSignalSetup( + // + string _symbol, + ENUM_TIMEFRAMES _period, + // + XC121SMCCycleHelper *decisionCycleHelper, + XC121SMCCycleHelper *analyseCycleHelper, + XC121SMCCycleHelper *consolidationCycleHelper, + XC121SMCCycleHelper *visionCycleHelper + // + ) + { + // + bool result = false; + + // + // Validate Cycle Helpers ... + result = + // + visionCycleHelper != NULL && + analyseCycleHelper != NULL && + decisionCycleHelper != NULL && + consolidationCycleHelper != NULL + // + ; + if (!result) + { + return result; + } + + // + 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; + + // + mConditions.symbol = symbol; + mConditions.period = period; + + // + double ask = GetAsk(symbol); + double bid = GetBid(symbol); + datetime cTime = TimeCurrent(); + double points = GetPoints(symbol); + + // + double target = 0; + + // + // 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; + } + + // + // Analyse ... + ENUM_XPOI_EVENTS analysePoiEvents[]; + ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; + X121SMCCycleConditions analyseConditions; + result = analyseCycleHelper.GetConditions( + analyseCycleEvents, + analysePoiEvents, + analyseConditions, + 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 decisionState = decisionConditions.state; + XPOIState analyseState = analyseConditions.state; + XPOIState consolidationState = consolidationConditions.state; + XPOIState visionState = visionConditions.state; + + // + // Cycle X121Conditions ... + X121Conditions decisionXConditions = decisionConditions.x121Conditions; + X121Conditions analyseXConditions = analyseConditions.x121Conditions; + X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; + X121Conditions visionXConditions = visionConditions.x121Conditions; + + // + // Setup Conditions ... + + // + XOHCL decisionZBar; + XOHCL decisionCBar; + XOHCL decisionPBar; + double decisionCBarBullishZoneChechValue = 0; + double decisionCBarBearishZoneChechValue = 0; + + // + result = decisionZBar.Init( + decisionState.symbol, + decisionState.period, + 0 // + ); + if (!result) + { + // + Clean(visionPoiEvents); + Clean(analysePoiEvents); + Clean(decisionPoiEvents); + Clean(visionCycleEvents); + Clean(analyseCycleEvents); + Clean(decisionCycleEvents); + Clean(consolidationPoiEvents); + Clean(consolidationCycleEvents); + + // + visionState.Clean(); + analyseState.Clean(); + decisionZBar.Clean(); + decisionCBar.Clean(); + decisionPBar.Clean(); + decisionState.Clean(); + visionConditions.Clean(); + analyseConditions.Clean(); + visionXConditions.Clean(); + consolidationState.Clean(); + decisionConditions.Clean(); + analyseXConditions.Clean(); + decisionXConditions.Clean(); + consolidationConditions.Clean(); + consolidationXConditions.Clean(); + + // + return result; + } + + // + result = decisionZBar + .GetPreviousBar(decisionCBar); + if (!result) + { + // + Clean(visionPoiEvents); + Clean(analysePoiEvents); + Clean(decisionPoiEvents); + Clean(visionCycleEvents); + Clean(analyseCycleEvents); + Clean(decisionCycleEvents); + Clean(consolidationPoiEvents); + Clean(consolidationCycleEvents); + + // + visionState.Clean(); + analyseState.Clean(); + decisionZBar.Clean(); + decisionCBar.Clean(); + decisionPBar.Clean(); + decisionState.Clean(); + visionConditions.Clean(); + analyseConditions.Clean(); + visionXConditions.Clean(); + consolidationState.Clean(); + decisionConditions.Clean(); + analyseXConditions.Clean(); + decisionXConditions.Clean(); + consolidationConditions.Clean(); + consolidationXConditions.Clean(); + + // + return result; + } + + // + result = decisionCBar + .GetPreviousBar(decisionPBar); + if (!result) + { + // + Clean(visionPoiEvents); + Clean(analysePoiEvents); + Clean(decisionPoiEvents); + Clean(visionCycleEvents); + Clean(analyseCycleEvents); + Clean(decisionCycleEvents); + Clean(consolidationPoiEvents); + Clean(consolidationCycleEvents); + + // + visionState.Clean(); + analyseState.Clean(); + decisionZBar.Clean(); + decisionCBar.Clean(); + decisionPBar.Clean(); + decisionState.Clean(); + visionConditions.Clean(); + analyseConditions.Clean(); + visionXConditions.Clean(); + consolidationState.Clean(); + decisionConditions.Clean(); + analyseXConditions.Clean(); + decisionXConditions.Clean(); + consolidationConditions.Clean(); + consolidationXConditions.Clean(); + + // + return result; + } + + // + decisionCBarBullishZoneChechValue = decisionCBar + .GetZoneCheckValue(X_DIRECTION_BULLISH); + decisionCBarBearishZoneChechValue = decisionCBar + .GetZoneCheckValue(X_DIRECTION_BEARISH); + + // + // Check Working Zone ... + bool hasWorkingZone = mConditions.HasWorkingZone(); + if (!hasWorkingZone) + { + // + hasWorkingZone = mConditions.ExtractWorkingZone( + visionState // + ); + } + + // + result = hasWorkingZone; + if (!result) + { + return result; + } + + // + RemoveWorkingZoneDraws(); + DrawWorkingZone( + mConditions, + visionCycleHelper.mPOIDrawer // + ); + + // + // Check Working Zone still Alive ... + ENUM_X_DIRECTION destroyedDir = X_DIRECTION_NONE; + bool isWorkingZoneDestroyed = mConditions + .IsWorkingZoneDestroyed( + destroyedDir, + zIndex, + decisionState.period // + ); + if (isWorkingZoneDestroyed) + { + RemoveWorkingZoneDraws(); + } + + // + result = !isWorkingZoneDestroyed; + if (!result) + { + return result; + } + + // + // Detect Overal Trend ... + ENUM_X_DIRECTION trend; + bool hasTrend = mConditions.DetectTrend( + trend, + zIndex // + ); + bool hasBullishTrend = + // + hasTrend && + IsBullish(trend) + // + ; + bool hasBearishTrend = + // + hasTrend && + IsBearish(trend) + // + ; + result = hasTrend; + if (!result) + { + return result; + } + + // + // Now We Have to Detect at least One OrderBlock with FVG ... + // for Trend Approvement ... + bool hasOrderBlock = mConditions.HasOrderBlock(); + bool hasFairValueGap = mConditions.HasFairValueGap(); + if (!hasOrderBlock && + !hasFairValueGap) + { + // + int count = 0; + bool has = false; + + // + XCFVG *fvg = NULL; + XCOrderBlock *ob = NULL; + + // + if (hasBullishTrend) + { + // + has = consolidationState.HasBullishOrderBlocks(); + count = consolidationState.CountBullishOrderBlocks(); + + // + if (has) + { + // + // Check Order Block ... + for (int i = 0; i < count; i++) + { + // + XCOrderBlock *iOB = consolidationState.bullishOrderBlocks[i]; + + // + iOB.To(cTime); + + // + // OB Must inside DemandZone ... + bool isInsideDemand = IsInsideDiff( + iOB, + mConditions.demandZone // + ); + if (!isInsideDemand) + { + continue; + } + + // + // Check OB Started ... + XOHCL startedBar; + ENUM_X_DIRECTION startedDir; + bool isStarted = iOB.IsStarted( + X_DIRECTION_BULLISH, + startedBar, + startedDir // + ); + if (!isStarted) + { + // + startedBar.Clean(); + continue; + } + + // + // Converts OB to Box ... + XBoxZone obBox; + bool hasOBBox = ToBox( + obBox, + iOB // + ); + if (!hasOBBox) + { + // + obBox.Clean(); + startedBar.Clean(); + continue; + } + + // + // Check Zone Must not Used before ... + bool isUsed = IsBoxUsed( + obBox, + startedBar.Index() - 1, + zIndex // + ); + if (isUsed) + { + // + obBox.Clean(); + startedBar.Clean(); + continue; + } + + // + ob = iOB; + + // + obBox.Clean(); + startedBar.Clean(); + + // + break; + } + + // + // Detect Fair Value Gap ... + if (ob != NULL && + ob.IsValid()) + { + // + has = analyseState.HasBullishFairValueGaps(); + count = analyseState.CountBullishFairValueGaps(); + if (has) + { + // + } + else + { + // + ob = NULL; + } + } + } + } + else if (hasBearishTrend) + { + // + } + + // + hasOrderBlock = mConditions.HasOrderBlock(); + hasFairValueGap = mConditions.HasFairValueGap(); + } + + // + bool isTrendApproved = hasOrderBlock && + hasFairValueGap; + result = isTrendApproved; + if (!result) + { + return result; + } + + // + // Detect 1H Sup Dem ... + int count = 0; + bool has = false; + + // // + // // Supply Zones ... + // count = consolidationState.CountSupplyZones(); + // has = consolidationState.HasSupplyZones(); + // if (has) + // { + // // + // for (int i = 0; i < count; i++) + // { + // // + // XCSupplyZoneObject *iObj; + // bool isCreated = visionCycleHelper + // .mPOIDrawer + // .CreateSupplyZone( + // consolidationState.supplyZones[i], + // iObj // + // ); + // } + // } + + // // + // // Demand Zones ... + // count = consolidationState.CountDemandZones(); + // has = consolidationState.HasDemandZones(); + // if (has) + // { + // // + // for (int i = 0; i < count; i++) + // { + // // + // XCDemandZoneObject *iObj; + // bool isCreated = visionCycleHelper + // .mPOIDrawer + // .CreateDemandZone( + // consolidationState.demandZones[i], + // iObj // + // ); + // } + // } + + // + return false; + + // + return result; + } + + // + // Detect Trigger Conditions ... + bool DetectSignalTrigger( + // + X121SMCStrategyXWZSignalConditions &conditions, + // + string _symbol, + ENUM_TIMEFRAMES _period, + // + XC121SMCCycleHelper *decisionCycleHelper, + XC121SMCCycleHelper *analyseCycleHelper, + XC121SMCCycleHelper *consolidationCycleHelper, + XC121SMCCycleHelper *visionCycleHelper, + // + int maxAllowedSetupAge = 60 + // + ) + { + // + bool result = false; + + // + result = + // + visionCycleHelper != NULL && + analyseCycleHelper != NULL && + decisionCycleHelper != NULL && + consolidationCycleHelper != NULL + // + ; + if (!result) + { + return result; + } + + // + 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) + { + // + // Cleanup ... + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + + // + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + + // + decisionConditions.Clean(); + + // + return result; + } + + // + // Cycles POI States ... + XPOIState decisionState = decisionConditions.state; + + // + // Cycle X121Conditions ... + X121Conditions decisionXConditions = decisionConditions.x121Conditions; + + // + // Trigger Conditions ... + + // + double point = conditions.point; + bool isPointBreaked = IsBarBreak( + point, + setupDir, + cBar // + ); + + // + // Summary ... + + // + isBullish = + // + isBullish && + isPointBreaked + // + ; + + // + isBearish = + // + isBearish && + isPointBreaked + // + ; + + // + result = isBullish || + isBearish; + if (!result) + { + // + // Cleanup Setup Conditions ... + int setupAge = conditions.GetSetupAge(); + if (IsValidSize(setupAge) && + IsValidSize(maxAllowedSetupAge) && + setupAge >= maxAllowedSetupAge) + { + conditions.Clean(); + } + + // + // Cleanup ... + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + + // + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + + // + decisionState.Clean(); + decisionConditions.Clean(); + decisionXConditions.Clean(); + + // + return result; + } + + // + // Detect Nearest Pivot Point ... + + // + double entry = GetEntry( + conditions.symbol, + setupDir // + ); + + // + // Manipulate SL Based on Consolidation Zones ... + + // + double sls[]; + Add( + conditions.pivot, + sls // + ); + + // + double iAtr = decisionXConditions.atrBuffer[1]; + iAtr *= 2; + + // + 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.triggerTime = cTime; + conditions.type = isBullish + ? X_POSITION_TYPE_LONG + : X_POSITION_TYPE_SHORT; + + // + // Cleanup ... + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + + // + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + + // + decisionState.Clean(); + decisionConditions.Clean(); + decisionXConditions.Clean(); + + // + return result; + } + + // + // Detect Guards ... + bool DetectGuards( + // + X121SMCGuard &guards[], + const XPosition &positions[], + // + XC121SMCCycleHelper *decisionCycleHelper, + XC121SMCCycleHelper *analyseCycleHelper, + XC121SMCCycleHelper *consolidationCycleHelper, + XC121SMCCycleHelper *visionCycleHelper + // + ) + { + // + bool result = false; + + // + Clean(guards); + + // + bool isCycleHelpersValid = + // + visionCycleHelper != NULL && + analyseCycleHelper != NULL && + decisionCycleHelper != NULL && + consolidationCycleHelper != NULL + // + ; + + // + result = isCycleHelpersValid; + if (!result) + { + return result; + } + + // + int count = ArraySize(positions); + result = IsValidSize(count); + if (!result) + { + return result; + } + + // + string symbol = decisionCycleHelper.GetSymbol(); + ENUM_TIMEFRAMES period = decisionCycleHelper.GetPeriod(); + string provider = ToString(X_121_SMC_PROVIDER_XWZ); + + // + XPosition ownPositions[]; + XPosition ownLongPositions[]; + XPosition ownShortPositions[]; + for (int i = 0; i < count; i++) + { + // + XPosition iPosition = positions[i]; + bool isOwn = iPosition + .IsFiltersPassed( + symbol, + provider, + NULL, + X_POSITION_TYPE_ALL, + iPosition.magic // + ); + if (isOwn) + { + // + AddRef( + iPosition, + ownPositions // + ); + + // + bool isLong = IsLong(positions[i].type); + if (isLong) + { + // + AddRef( + iPosition, + ownLongPositions // + ); + } + else + { + // + AddRef( + iPosition, + ownShortPositions // + ); + } + } + } + + // + count = ArraySize(ownPositions); + + // + int longsCount = ArraySize(ownLongPositions); + bool hasLongs = IsValidSize(longsCount); + + // + int shortsCount = ArraySize(ownShortPositions); + bool hasShorts = IsValidSize(shortsCount); + + // + result = IsValidSize(count); + if (!result) + { + // + Clean(ownPositions); + Clean(ownLongPositions); + Clean(ownShortPositions); + + // + return result; + } + + // + // + // + + // + // Get Global and Common Guards ... + + // + ENUM_X_121_SMC_GUARD_ACTIONS ignoreGuards[1] = { + X_121_SMC_GUARD_ACTION_TRAIL_STOP}; + result = DetectX121SMCGuards( + provider, + guards, + positions, + decisionCycleHelper, + analyseCycleHelper, + consolidationCycleHelper, + visionCycleHelper, + // + ignoreGuards + // + ); + + // + // + // + + // + // Get Custom Implemented Guards ... + + // + // Here we Are Sure there is Positions to Guard ... + // based on Current Provider ... + + // + // Detect Required Data for Analyse Market to Guard Positions ... + + // + int zIndex = 0; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + int loopback = 10; + + // + XOHCL zBar; + result = zBar.Init( + symbol, + period, + zIndex // + ); + if (!result) + { + // + result = HasChild(guards); + return result; + } + + // + XOHCL cBar; + result = cBar.Init( + symbol, + period, + cIndex // + ); + if (!result) + { + // + zBar.Clean(); + result = HasChild(guards); + return result; + } + + // + XOHCL pBar; + result = pBar.Init( + symbol, + period, + pIndex // + ); + if (!result) + { + // + zBar.Clean(); + cBar.Clean(); + result = HasChild(guards); + return result; + } + + // + XOHCL ppBar; + result = ppBar.Init( + symbol, + period, + ppIndex // + ); + if (!result) + { + // + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + result = HasChild(guards); + return result; + } + + // + double ask = GetAsk(symbol); + double bid = GetBid(symbol); + datetime cTime = TimeCurrent(); + double points = GetPoints(symbol); + + // + + // + // Cycles Conditions ... + + // + // Decision ... + ENUM_XPOI_EVENTS decisionPoiEvents[]; + ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; + X121SMCCycleConditions decisionConditions; + result = decisionCycleHelper.GetConditions( + decisionCycleEvents, + decisionPoiEvents, + decisionConditions, + zIndex, + loopback // + ); + if (!result) + { + // + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + ppBar.Clean(); + result = HasChild(guards); + return result; + } + + // + // Analyse ... + ENUM_XPOI_EVENTS analysePoiEvents[]; + ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; + X121SMCCycleConditions analyseConditions; + result = analyseCycleHelper.GetConditions( + analyseCycleEvents, + analysePoiEvents, + analyseConditions, + zIndex, + loopback // + ); + if (!result) + { + // + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + ppBar.Clean(); + + // + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + + // + decisionConditions.Clean(); + + // + result = HasChild(guards); + return result; + } + + // + // Consolidation ... + ENUM_XPOI_EVENTS consolidationPoiEvents[]; + ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; + X121SMCCycleConditions consolidationConditions; + result = consolidationCycleHelper.GetConditions( + consolidationCycleEvents, + consolidationPoiEvents, + consolidationConditions, + zIndex, + loopback // + ); + if (!result) + { + // + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + ppBar.Clean(); + + // + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + + // + decisionConditions.Clean(); + + // + Clean(analysePoiEvents); + Clean(analyseCycleEvents); + + // + analyseConditions.Clean(); + + // + result = HasChild(guards); + return result; + } + + // + // Vision ... + ENUM_XPOI_EVENTS visionPoiEvents[]; + ENUM_X_CYCLE_EVENTS visionCycleEvents[]; + X121SMCCycleConditions visionConditions; + result = visionCycleHelper.GetConditions( + visionCycleEvents, + visionPoiEvents, + visionConditions, + zIndex, + loopback // + ); + if (!result) + { + // + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + ppBar.Clean(); + + // + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + + // + decisionConditions.Clean(); + + // + Clean(analysePoiEvents); + Clean(analyseCycleEvents); + + // + analyseConditions.Clean(); + + // + Clean(consolidationPoiEvents); + Clean(consolidationCycleEvents); + + // + consolidationConditions.Clean(); + + // + result = HasChild(guards); + return result; + } + + // + // Cycles POI States ... + XPOIState decisionState = decisionConditions.state; + XPOIState analyseState = analyseConditions.state; + XPOIState consolidationState = consolidationConditions.state; + XPOIState visionState = visionConditions.state; + + // + // Cycle X121Conditions ... + X121Conditions decisionXConditions = decisionConditions.x121Conditions; + X121Conditions analyseXConditions = analyseConditions.x121Conditions; + X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; + X121Conditions visionXConditions = visionConditions.x121Conditions; + + // + // + // + + // + // Detect Consolidation Zone ... + + // + XBoxZone lastBullishBox; + XBoxZone prevLastBullishBox; + bool hasLastBullishBox = false; + bool hasPrevLastBullishBox = false; + XConsolidationZone lastBullishZone; + bool isLastBullishAbovePrev = false; + bool isLastBullishBelowPrev = false; + XConsolidationZone prevLastBullishZone; + + // + XBoxZone lastBearishBox; + XBoxZone prevLastBearishBox; + bool hasLastBearishBox = false; + bool hasPrevLastBearishBox = false; + XConsolidationZone lastBearishZone; + bool isLastBearishAbovePrev = false; + bool isLastBearishBelowPrev = false; + XConsolidationZone prevLastBearishZone; + + // + int bullishConsolidationZonesCount = 0; + int bearishConsolidationZonesCount = 0; + bool hasBullishConsolidationZones = false; + bool hasBearishConsolidationZones = false; + XConsolidationZone bullishConsolidationZones[]; + XConsolidationZone bearishConsolidationZones[]; + bool hasConsolidationZones = decisionCycleHelper.HasConsolidationZones(); + int consolidationZonesCount = decisionCycleHelper.CountConsolidationZones(); + if (hasConsolidationZones) + { + // + bullishConsolidationZonesCount = decisionCycleHelper + .FillConsolidationZones( + X_DIRECTION_BULLISH, + bullishConsolidationZones // + ); + hasBullishConsolidationZones = IsValidSize(bullishConsolidationZonesCount); + + // + bearishConsolidationZonesCount = decisionCycleHelper + .FillConsolidationZones( + X_DIRECTION_BEARISH, + bearishConsolidationZones // + ); + hasBearishConsolidationZones = IsValidSize(bearishConsolidationZonesCount); + + // + // + // + + // + if (hasBullishConsolidationZones && + bullishConsolidationZonesCount >= 2) + { + // + lastBullishZone = bullishConsolidationZones[bullishConsolidationZonesCount - 1]; + prevLastBullishZone = bullishConsolidationZones[bullishConsolidationZonesCount - 2]; + + // + hasLastBullishBox = ToBox( + lastBullishBox, + lastBullishZone // + ); + hasPrevLastBullishBox = ToBox( + prevLastBullishBox, + prevLastBullishZone // + ); + + // + isLastBullishAbovePrev = hasLastBullishBox && + hasPrevLastBullishBox && + IsBoxAbove( + lastBullishBox, + prevLastBullishBox // + ); + + // + isLastBullishBelowPrev = hasLastBullishBox && + hasPrevLastBullishBox && + IsBoxBelow( + lastBullishBox, + prevLastBullishBox // + ); + } + + // + if (hasBearishConsolidationZones && + bearishConsolidationZonesCount >= 2) + { + // + lastBearishZone = bearishConsolidationZones[bearishConsolidationZonesCount - 1]; + prevLastBearishZone = bearishConsolidationZones[bearishConsolidationZonesCount - 2]; + + // + hasLastBearishBox = ToBox( + lastBearishBox, + lastBearishZone // + ); + hasPrevLastBearishBox = ToBox( + prevLastBearishBox, + prevLastBearishZone // + ); + + // + isLastBearishAbovePrev = hasLastBearishBox && + hasPrevLastBearishBox && + IsBoxAbove( + lastBearishBox, + prevLastBearishBox // + ); + + // + isLastBearishBelowPrev = hasLastBearishBox && + hasPrevLastBearishBox && + IsBoxBelow( + lastBearishBox, + prevLastBearishBox // + ); + } + + // + } + + // + // Detect High Probability Swings ... + bool isSwingLow = + // + cBar.low > pBar.low && + ppBar.low > pBar.low && + // + zBar.low > pBar.low + // + ; + bool isSwingHigh = + // + cBar.high < pBar.high && + ppBar.high < pBar.high && + // + zBar.high < pBar.high + // + ; + bool isStrongSwingLow = + pBar.IsBullish() && + pBar.GetLowShadow() >= pBar.GetBody() * 2; + bool isStrongSwingHigh = + pBar.IsBearish() && + pBar.GetHighShadow() >= pBar.GetBody() * 2; + + // + bool isStrongSwingLowAboveLastBullishBox = + isStrongSwingLow && + hasLastBullishBox && + pBar.low > lastBullishBox.upper; + + // + bool isStrongSwingHighBelowLastBearishBox = + isStrongSwingHigh && + hasLastBearishBox && + pBar.high < lastBearishBox.lower; + + // + // Here We Have all Requirements for Guarding Positions ... + + // + // Available Guards: + // X_121_SMC_GUARD_ACTION_NONE + // X_121_SMC_GUARD_ACTION_CLOSE + // X_121_SMC_GUARD_ACTION_CLOSE_ALL + // X_121_SMC_GUARD_ACTION_CLOSE_LONGS + // X_121_SMC_GUARD_ACTION_CLOSE_SHORTS + // X_121_SMC_GUARD_ACTION_PARTIAL_CLOSE + // X_121_SMC_GUARD_ACTION_TRAIL_STOP + // X_121_SMC_GUARD_ACTION_TRAIL_TARGET + // X_121_SMC_GUARD_ACTION_HEDGE + + // + // X_121_SMC_GUARD_ACTION_CLOSE: + // Close Specified Position on Specified Conditions ... + + // + // X_121_SMC_GUARD_ACTION_CLOSE_ALL: + // Close All Positions on Specified Conditions ... + + // + // X_121_SMC_GUARD_ACTION_CLOSE_LONGS: + // Close All Long Positions on Specified Conditions ... + + // + // X_121_SMC_GUARD_ACTION_CLOSE_SHORTS: + // Close All Short Positions on Specified Conditions ... + + // + // X_121_SMC_GUARD_ACTION_PARTIAL_CLOSE: + // Partial Close Specified Position on Specified Conditions ... + + // + // X_121_SMC_GUARD_ACTION_TRAIL_STOP: + // Trail Stop Specified Position on Specified Conditions ... + + // + // X_121_SMC_GUARD_ACTION_TRAIL_TARGET: + // Trail Target Specified Position on Specified Conditions ... + + // + // X_121_SMC_GUARD_ACTION_HEDGE: + // Hedge all Positions on Specified Conditions ... + + // + // Cleanup Collections ... + + // + Clean(ownPositions); + Clean(ownLongPositions); + Clean(ownShortPositions); + + // + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + ppBar.Clean(); + + // + Clean(visionPoiEvents); + Clean(analysePoiEvents); + Clean(visionCycleEvents); + Clean(decisionPoiEvents); + Clean(analyseCycleEvents); + Clean(decisionCycleEvents); + Clean(consolidationPoiEvents); + Clean(consolidationCycleEvents); + + // + visionState.Clean(); + analyseState.Clean(); + decisionState.Clean(); + visionConditions.Clean(); + analyseConditions.Clean(); + visionXConditions.Clean(); + decisionConditions.Clean(); + consolidationState.Clean(); + analyseXConditions.Clean(); + decisionXConditions.Clean(); + consolidationConditions.Clean(); + consolidationXConditions.Clean(); + + // + lastBullishBox.Clean(); + lastBearishBox.Clean(); + lastBullishZone.Clean(); + lastBearishZone.Clean(); + prevLastBullishBox.Clean(); + prevLastBearishBox.Clean(); + prevLastBullishZone.Clean(); + prevLastBearishZone.Clean(); + + // + count = ArraySize(guards); + result = IsValidSize(count); + + // + return result; + } + + // + // + // + + // + // Add Conditions to Conditions Collection ... + int AddConditionsIfNotExists( + int maxAllowed = 10 // + ) + { + // + int result = 0; + + // + bool isSetuped = IsValid(mConditions.setupTime) && + HasDirection(mConditions.dir); + if (!isSetuped) + { + return result; + } + + // + int count = ArraySize(mConditionsCollection); + if (IsValidSize(count)) + { + // + // Copy Original Items ... + X121SMCStrategyXWZSignalConditions tmpItems[]; + Copy( + mConditionsCollection, + tmpItems // + ); + + // + // Prese Item Data ... + bool isBullish = IsBullish(mConditions.dir); + + // + for (int i = 0; i < count; i++) + { + // + X121SMCStrategyXWZSignalConditions iItem = tmpItems[i]; + + // + bool canRemove = mConditions.dir == iItem.dir && + mConditions.pivot == iItem.pivot; + if (canRemove) + { + // + ArrayRemove( + mConditionsCollection, + i, + 1 // + ); + } + } + + // + Clean(tmpItems); + } + + // + AddRef( + mConditions, + mConditionsCollection // + ); + + // + // Remove Olds ... + CleanupArray( + mConditionsCollection, + maxAllowed // + ); + + // + result = ArraySize(mConditionsCollection); + + // + return result; + } + + // + // Draw Functions ... + // + + // + void RemoveDraws() + { + mObjects.Clear(); + } + + // + void RemoveWorkingZoneDraws() + { + mWorkingZoneObjects.Clear(); + } + + // + void DrawOrderBlock( + XCOrderBlock *ob, + XCPOIDrawer *drawer // + ) + { + // + if (ob == NULL || + drawer == NULL) + { + return; + } + + // + ENUM_X_DIRECTION forDir = ob.GetDirection(); + + // + color bullishColor = drawer.BarBullishColor(); + color bearishColor = drawer.BarBearishColor(); + color forColor = IsBullish(forDir) + ? bullishColor + : bearishColor; + + // + // Draw Order Block ... + XCBaseObject *obj; + bool isCreated = drawer.CreateOrderBlock( + ob, + obj // + ); + if (isCreated) + { + mObjects.Add(obj); + } + + // + ulong chartID = drawer.ChartIdentification(); + int subWindow = drawer.SubWindowIdentification(); + + // + XOHCL startedBar; + ENUM_X_DIRECTION startedDir; + bool isStarted = ob.IsStarted( + forDir, + startedBar, + startedDir // + ); + if (isStarted) + { + // + datetime to = startedBar.time + (PeriodSeconds(startedBar.period)); + + // + XCOHCLObject *obj; + bool isCreated = drawer.CreateBar( + startedBar, + obj, + to // + ); + if (isCreated) + { + // + obj.BodyColor(clrYellow); + obj.HighShadowColor(clrYellow); + obj.LowShadowColor(clrYellow); + + // + obj.BodyStyle(STYLE_SOLID); + obj.HighShadowStyle(STYLE_SOLID); + obj.LowShadowStyle(STYLE_SOLID); + + // + mObjects.Add(obj); + } + + // + string startVLineName = "Start_" + ob.GetTag(); + + // + CChartObjectVLine *startVLine; + startVLine = new CChartObjectVLine(); + isCreated = startVLine.Create( + chartID, + startVLineName, + subWindow, + startedBar.time // + ); + if (isCreated) + { + // + startVLine.Color(forColor); + + // + mObjects.Add(startVLine); + } + } + } + + // + void DrawFairValueGap( + XCFVG *fvg, + XCPOIDrawer *drawer // + ) + { + // + if (fvg == NULL || + drawer == NULL) + { + return; + } + + // + ENUM_X_DIRECTION forDir = fvg.GetDirection(); + + // + color bullishColor = drawer.BarBullishColor(); + color bearishColor = drawer.BarBearishColor(); + color forColor = IsBullish(forDir) + ? bullishColor + : bearishColor; + + // + // Draw Order Block ... + XCBaseObject *obj; + bool isCreated = drawer.CreateFairValueGap( + fvg, + obj // + ); + if (isCreated) + { + mObjects.Add(obj); + } + + // + ulong chartID = drawer.ChartIdentification(); + int subWindow = drawer.SubWindowIdentification(); + + // + XOHCL startedBar; + ENUM_X_DIRECTION startedDir; + bool isStarted = fvg.IsStarted( + forDir, + startedBar, + startedDir // + ); + if (isStarted) + { + // + datetime to = startedBar.time + (PeriodSeconds(startedBar.period)); + + // + XCOHCLObject *obj; + bool isCreated = drawer.CreateBar( + startedBar, + obj, + to // + ); + if (isCreated) + { + // + obj.BodyColor(clrYellow); + obj.HighShadowColor(clrYellow); + obj.LowShadowColor(clrYellow); + + // + obj.BodyStyle(STYLE_SOLID); + obj.HighShadowStyle(STYLE_SOLID); + obj.LowShadowStyle(STYLE_SOLID); + + // + mObjects.Add(obj); + } + + // + string startVLineName = "Start_" + fvg.GetTag(); + + // + CChartObjectVLine *startVLine; + startVLine = new CChartObjectVLine(); + isCreated = startVLine.Create( + chartID, + startVLineName, + subWindow, + startedBar.time // + ); + if (isCreated) + { + // + startVLine.Color(forColor); + + // + mObjects.Add(startVLine); + } + } + } + + // + void DrawWorkingZone( + X121SMCStrategyXWZSignalConditions &conditions, + XCPOIDrawer *drawer // + ) + { + // + if (drawer == NULL) + { + return; + } + + // + bool hasWorkingZone = conditions.HasWorkingZone(); + if (!hasWorkingZone) + { + return; + } + + // + string prefix = "WKZ_" + conditions.workingZone.symbol + ToString(conditions.workingZone.period) + "_"; + string tag = prefix + ToString(conditions.workingZone.upper) + "_" + ToString(conditions.workingZone.lower); + string suffix = ToMD5(tag); + + // + string upperName = prefix + "_Upper_" + suffix; + string lowerName = prefix + "_Lower_" + suffix; + string zoneUpperName = prefix + "_ZoneUpper_" + suffix; + string zoneLowerName = prefix + "_ZoneLower_" + suffix; + + // + string q1Name = prefix + "_Q1_" + suffix; + string q2Name = prefix + "_Q2_" + suffix; + string q3Name = prefix + "_Q3_" + suffix; + + // + ulong chartID = drawer.ChartIdentification(); + int subWindow = drawer.SubWindowIdentification(); + + // + bool isCreated = false; + + // + XCSupplyZoneObject *iSupObj; + isCreated = drawer.CreateSupplyZone( + conditions.supplyZone, + iSupObj // + ); + if (isCreated) + { + mWorkingZoneObjects.Add(iSupObj); + } + + // + XCDemandZoneObject *iDemObj; + isCreated = drawer.CreateDemandZone( + conditions.demandZone, + iDemObj // + ); + if (isCreated) + { + mWorkingZoneObjects.Add(iDemObj); + } + + // + // Lower ... + CChartObjectHLine *lowerHLine; + lowerHLine = new CChartObjectHLine(); + isCreated = lowerHLine.Create( + chartID, + lowerName, + subWindow, + conditions.workingZone.lower // + ); + if (isCreated) + { + // + lowerHLine.Color(clrLime); + mWorkingZoneObjects.Add(lowerHLine); + } + + // + CChartObjectHLine *upperHLine; + upperHLine = new CChartObjectHLine(); + isCreated = upperHLine.Create( + chartID, + upperName, + subWindow, + conditions.workingZone.upper // + ); + if (isCreated) + { + // + upperHLine.Color(clrLime); + mWorkingZoneObjects.Add(upperHLine); + } + + // + CChartObjectHLine *zoneLowerHLine; + zoneLowerHLine = new CChartObjectHLine(); + isCreated = zoneLowerHLine.Create( + chartID, + zoneLowerName, + subWindow, + conditions.workingZone.zoneLower // + ); + if (isCreated) + { + // + zoneLowerHLine.Color(clrRed); + mWorkingZoneObjects.Add(zoneLowerHLine); + } + + // + CChartObjectHLine *zoneUpperHLine; + zoneUpperHLine = new CChartObjectHLine(); + isCreated = zoneUpperHLine.Create( + chartID, + zoneUpperName, + subWindow, + conditions.workingZone.zoneUpper // + ); + if (isCreated) + { + // + zoneUpperHLine.Color(clrRed); + mWorkingZoneObjects.Add(zoneUpperHLine); + } + + // + CChartObjectHLine *quarter1HLine; + quarter1HLine = new CChartObjectHLine(); + isCreated = quarter1HLine.Create( + chartID, + q1Name, + subWindow, + conditions.workingZone.quarter1 // + ); + if (isCreated) + { + // + quarter1HLine.Color(clrYellow); + mWorkingZoneObjects.Add(quarter1HLine); + } + + // + CChartObjectHLine *quarter2HLine; + quarter2HLine = new CChartObjectHLine(); + isCreated = quarter2HLine.Create( + chartID, + q2Name, + subWindow, + conditions.workingZone.quarter2 // + ); + if (isCreated) + { + // + quarter2HLine.Color(clrYellow); + mWorkingZoneObjects.Add(quarter2HLine); + } + + // + CChartObjectHLine *quarter3HLine; + quarter3HLine = new CChartObjectHLine(); + isCreated = quarter3HLine.Create( + chartID, + q3Name, + subWindow, + conditions.workingZone.quarter3 // + ); + if (isCreated) + { + // + quarter3HLine.Color(clrYellow); + mWorkingZoneObjects.Add(quarter3HLine); + } + + // + } + + // + void DrawConditions( + X121SMCStrategyXWZSignalConditions &conditions, + XCPOIDrawer *drawer, + bool forceClean = false // + ) + { + // + if (drawer == NULL) + { + return; + } + + // + if (forceClean) + { + mObjects.Clear(); + } + + // + bool isCreated = false; + } + + // + protected: + // + + // + private: + // + // Props ... + CArrayObj mObjects; + CArrayObj mWorkingZoneObjects; + + /** + * Initialize ... + */ + void Init() + { + } + + /** + * DeInitialize ... + */ + void DeInit() + { + // + RemoveDraws(); + mConditions.Clean(); + RemoveWorkingZoneDraws(); + Clean(mConditionsCollection); + } + + // + // Helpers ... + + // + bool CheckPriceInside( + XOHCL &zBar, + XOHCL &cBar, + double upper, + double lower // + ) + { + // + bool result = false; + + // + result = zBar.IsValid() && + cBar.IsValid() && + upper > 0 && + lower > 0 && + upper > lower && + zBar.time > cBar.time; + if (!result) + { + return result; + } + + // + result = + // + zBar.high < upper && + cBar.high < upper && + // + zBar.low > lower && + cBar.low > lower + // + ; + + // + return result; + } + + // + bool CalculateRiskReward( + ENUM_X121SMC_XWZ_PRIORITY priority, + double &reward, + double &amountPercent // + ) + { + // + bool result = false; + + // + reward = 0; + amountPercent = 0; + + // + result = priority != X121SMC_XWZ_PRIORITY_NONE; + if (!result) + { + return result; + } + + // + switch (priority) + { + // + case X121SMC_XWZ_PRIORITY_HIGH: + // + reward = 6; + amountPercent = 2; + break; + + // + case X121SMC_XWZ_PRIORITY_REGULAR: + // + reward = 6; + amountPercent = 1.5; + break; + + // + case X121SMC_XWZ_PRIORITY_LOW: + // + reward = 4; + amountPercent = 1; + break; + + // + case X121SMC_XWZ_PRIORITY_WEAK: + // + reward = 2; + amountPercent = 0.5; + break; + } + + // + result = + // + reward > 0 && + amountPercent > 0 + // + ; + + // + return result; + } + + // +}; + +// \ No newline at end of file diff --git a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 new file mode 100644 index 00000000..ab131365 --- /dev/null +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 @@ -0,0 +1,824 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 X121 SMC Signal Class +// ------------------------------------------------- +// Name: XWZ +// 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" + +// +enum ENUM_X121SMC_XWZ_PRIORITY +{ + X121SMC_XWZ_PRIORITY_NONE, + X121SMC_XWZ_PRIORITY_WEAK, + X121SMC_XWZ_PRIORITY_LOW, + X121SMC_XWZ_PRIORITY_REGULAR, + X121SMC_XWZ_PRIORITY_HIGH, +}; + +// +struct X121SMCXWZWorkingZone +{ + // + string symbol; + ENUM_TIMEFRAMES period; + + // + double upper; + double lower; + + // + double zoneUpper; + double zoneLower; + + // + double quarter1; + double quarter2; + double quarter3; + + // + datetime from; + + // + X121SMCXWZWorkingZone() + { + Clean(); + } + + // + void Clean() + { + // + upper = 0; + lower = 0; + quarter1 = 0; + quarter2 = 0; + quarter3 = 0; + zoneLower = 0; + zoneUpper = 0; + + // + from = NULL; + symbol = NULL; + period = NULL; + + // + ZeroMemory(this); + } + + // + bool IsValid() + { + // + bool result = false; + + // + result = + lower > 0 && + upper > 0 && + quarter1 > 0 && + quarter2 > 0 && + quarter3 > 0 && + upper > lower && + zoneLower > 0 && + zoneUpper > 0 && + IsValid(from) && + IsValid(symbol) && + IsValid(period) && + zoneUpper > upper && + zoneLower < lower; + + // + return result; + } + + // + bool DetectOveralTrend( + XOHCL &touchedBar, + ENUM_X_DIRECTION &trendDir, + int barIndex = 0 // + ) + { + // + bool result = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + trendDir = X_DIRECTION_NONE; + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + int fromBarIndex = iBarShift( + symbol, + period, + from // + ); + result = IsValidIndex(fromBarIndex); + if (!result) + { + return result; + } + + // + XOHCL nearestUpperTouchedBar; + XOHCL nearestLowerTouchedBar; + bool hasNearestUpperTouchedBar = false; + bool hasNearestLowerTouchedBar = false; + for (int i = barIndex; i < fromBarIndex; i++) + { + // + XOHCL iBar; + bool isInited = iBar.Init( + symbol, + period, + i // + ); + + // + hasNearestUpperTouchedBar = nearestUpperTouchedBar.IsValid(); + if (!hasNearestUpperTouchedBar) + { + // + bool isBarTouchedUpper = iBar.high > upper; + if (isBarTouchedUpper) + { + // + nearestUpperTouchedBar = iBar; + hasNearestUpperTouchedBar = true; + } + } + + // + hasNearestLowerTouchedBar = nearestLowerTouchedBar.IsValid(); + if (!hasNearestLowerTouchedBar) + { + // + bool isBarTouchedLower = iBar.low < lower; + if (isBarTouchedLower) + { + // + nearestLowerTouchedBar = iBar; + hasNearestLowerTouchedBar = true; + } + } + + // + if (hasNearestUpperTouchedBar && + hasNearestLowerTouchedBar) + { + break; + } + } + + // + result = hasNearestUpperTouchedBar || + hasNearestLowerTouchedBar; + if (result) + { + // + if (hasNearestUpperTouchedBar && + !hasNearestLowerTouchedBar) + { + // + trendDir = X_DIRECTION_BEARISH; + touchedBar = nearestUpperTouchedBar; + } + else if (!hasNearestUpperTouchedBar && + hasNearestLowerTouchedBar) + { + // + trendDir = X_DIRECTION_BULLISH; + touchedBar = nearestLowerTouchedBar; + } + else if (hasNearestUpperTouchedBar && + hasNearestLowerTouchedBar) + { + // + trendDir = + nearestUpperTouchedBar.time < nearestLowerTouchedBar.time + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + if (IsBullish(trendDir)) + { + touchedBar = nearestLowerTouchedBar; + } + else + { + touchedBar = nearestUpperTouchedBar; + } + } + } + + // + return result; + } + + // + bool IsDestroyed( + ENUM_X_DIRECTION &destroyedDir, + int barIndex = 0, + ENUM_TIMEFRAMES forPeriod = NULL // + ) + { + // + bool result = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (!IsValid(forPeriod)) + { + forPeriod = period; + } + + // + destroyedDir = X_DIRECTION_NONE; + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + XOHCL bar; + result = bar.Init( + symbol, + forPeriod, + barIndex // + ); + if (!result) + { + return result; + } + + // + bool isUpperBreaked = + bar.high > zoneUpper && + bar.close > zoneUpper; + + // + bool isLowerBreaked = + bar.low < zoneLower && + bar.close < zoneLower; + + // + result = isUpperBreaked || + isLowerBreaked; + if (result) + { + // + destroyedDir = + isUpperBreaked + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + } + + // + return result; + } + + // +}; + +// +// Definitions ... +struct X121SMCStrategyXWZSignalConditions +{ + // + // Props ... + + // + string symbol; + ENUM_TIMEFRAMES period; + + // + double sl; + double target; + double reward; + double amountPercent; + ENUM_X_DIRECTION dir; + ENUM_X_POSITION_TYPES type; + + // + // Setup Props ... + + // + datetime setupTime; + datetime triggerTime; + + // + double pivot; + double point; + + // + ENUM_X121SMC_XWZ_PRIORITY priority; + + // + // Working Zone ... + + // + XCFVG *fairValueGap; + XCOrderBlock *orderBlock; + XCSupplyZone *supplyZone; + XCDemandZone *demandZone; + X121SMCXWZWorkingZone workingZone; + + // + // Constructor ... + X121SMCStrategyXWZSignalConditions() + { + 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(); + + // + ZeroMemory(this); + } + + /** + * 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; + + // + target = 0; + reward = 0; + amountPercent = 0; + + // + delete supplyZone; + ZeroMemory(supplyZone); + + // + delete demandZone; + ZeroMemory(demandZone); + + // + workingZone.Clean(); + } + + // + // + // + + // + bool HasWorkingZone() + { + return workingZone.IsValid(); + } + + // + // Working Zone is an Area which + // we decide to trade inside it ... + bool ExtractWorkingZone( + XPOIState &state // + ) + { + // + bool result = false; + + // + result = !HasWorkingZone(); + if (!result) + { + return result; + } + + // + result = state.IsValid() && + state.HasChild() && + state.HasSupplyZones() && + state.HasDemandZones(); + if (!result) + { + return result; + } + + // + // Retrieve Highest Supply Zone ... + int hSupplyIDX = GetHighest(state.supplyZones); + int lDemandIDX = GetLowest(state.demandZones); + + // + result = + // + IsValidIndex(hSupplyIDX) && + IsValidIndex(lDemandIDX) + // + ; + if (!result) + { + return result; + } + + // + supplyZone = state.supplyZones[hSupplyIDX]; + demandZone = state.demandZones[lDemandIDX]; + + // + result = + // + supplyZone != NULL && + demandZone != NULL && + supplyZone.IsValid() && + demandZone.IsValid() + // + ; + if (!result) + { + // + Clean(); + return result; + } + + // + workingZone.symbol = symbol; + workingZone.period = period; + + // + workingZone.upper = supplyZone.Lower(); + workingZone.zoneUpper = supplyZone.Upper(); + + // + workingZone.lower = demandZone.Upper(); + workingZone.zoneLower = demandZone.Lower(); + + // + workingZone.from = MathMax(supplyZone.From(), demandZone.From()); + + // + double upper = workingZone.upper; + double range = + workingZone.upper - workingZone.lower; + double ranegPercent = range / 100; + double quarterValue = ranegPercent * 25; + + // + workingZone.quarter1 = upper - (quarterValue * 1); + workingZone.quarter2 = upper - (quarterValue * 2); + workingZone.quarter3 = upper - (quarterValue * 3); + + // + result = workingZone.IsValid(); + if (!result) + { + Clean(); + } + + // + return result; + } + + // + bool IsWorkingZoneDestroyed( + ENUM_X_DIRECTION &destroyedDir, + int barIndex = 0, + ENUM_TIMEFRAMES forPeriod = NULL // + ) + { + // + bool result = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (!IsValid(forPeriod)) + { + forPeriod = period; + } + + // + destroyedDir = X_DIRECTION_NONE; + + // + result = workingZone.IsValid(); + if (!result) + { + return result; + } + + // + result = workingZone.IsDestroyed( + destroyedDir, + barIndex, + forPeriod // + ); + + // + return result; + } + + // + bool DetectTrend( + ENUM_X_DIRECTION &trend, + int barIndex = 0, + ENUM_TIMEFRAMES forPeriod = NULL // + ) + { + // + bool result = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (forPeriod == NULL) + { + forPeriod = period; + } + + // + trend = X_DIRECTION_NONE; + + // + result = HasWorkingZone(); + if (!result) + { + return result; + } + + // + int FromIndex = iBarShift( + symbol, + forPeriod, + workingZone.from // + ); + + // + datetime supplyTouch = NULL; + datetime demandTouch = NULL; + for (int i = barIndex; i < FromIndex; i++) + { + // + XOHCL iBar; + bool isInited = iBar.Init( + symbol, + forPeriod, + i // + ); + if (!isInited) + { + continue; + } + + // + bool isTouchSupplyZone = + // + iBar.low < supplyZone.Lower() && + iBar.GetUp() > supplyZone.Lower() + // + ; + if (isTouchSupplyZone && + !IsValid(supplyTouch)) + { + supplyTouch = iBar.time; + } + + // + bool isTouchDemandZone = + // + iBar.high > demandZone.Upper() && + iBar.GetDown() < demandZone.Upper() + // + ; + if (isTouchDemandZone && + !IsValid(demandTouch)) + { + demandTouch = iBar.time; + } + + // + bool canBreak = + IsValid(supplyTouch) && + IsValid(demandTouch); + + // + iBar.Clean(); + + // + if (canBreak) + { + break; + } + } + + // + result = + // + IsValid(supplyTouch) && + IsValid(demandTouch) + // + ; + if (result) + { + // + trend = + // + supplyTouch > demandTouch + ? X_DIRECTION_BEARISH + : X_DIRECTION_BULLISH + // + ; + } + + // + return result; + } + + // + bool HasOrderBlock() + { + return orderBlock != NULL && + orderBlock.IsValid(); + } + + // + bool HasFairValueGap() + { + return fairValueGap != NULL && + fairValueGap.IsValid(); + } + + // + void UpdateTo(datetime value = NULL) + { + // + value = NormalizeTime(value); + + // + if (supplyZone != NULL) + { + supplyZone.To(value); + } + + // + if (demandZone != NULL) + { + demandZone.To(value); + } + + // + if (orderBlock != NULL) + { + orderBlock.To(value); + } + + // + if (fairValueGap != NULL) + { + fairValueGap.To(value); + } + } + + // +}; diff --git a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 index 93a123ce..6afe6f21 100644 --- a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 @@ -28,6 +28,7 @@ // #include "../Signals/x-121.smc.xsupdemobs.signal.class.mq5" +#include "../Signals/x-121.smc.xwz.signal.class.mq5" // // Definitions ... @@ -41,8 +42,10 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy public: // // Props ... + bool useXWZSignal; bool useXSupDemOBSSignal; - XCX121SMCXSupDemOBSSignalDetector *mXSupDemONSSignalDetector; + XCX121SMCXWZSignalDetector *mXWZSignalDetector; + XCX121SMCXSupDemOBSSignalDetector *mXSupDemOBSSignalDetector; // // Constructor(s) ... @@ -56,7 +59,10 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy { // InitialHelpers(); - mXSupDemONSSignalDetector = new XCX121SMCXSupDemOBSSignalDetector(); + + // + mXWZSignalDetector = new XCX121SMCXWZSignalDetector(); + mXSupDemOBSSignalDetector = new XCX121SMCXSupDemOBSSignalDetector(); } // @@ -104,12 +110,6 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy */ void Destroy() override { - // - ZeroMemory(mDecisionCycleHelper); - ZeroMemory(mAnalyseCycleHelper); - ZeroMemory(mConsolidationCycleHelper); - ZeroMemory(mVisionCycleHelper); - // delete mDecisionCycleHelper; delete mAnalyseCycleHelper; @@ -117,8 +117,18 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy delete mVisionCycleHelper; // - ZeroMemory(mXSupDemONSSignalDetector); - delete mXSupDemONSSignalDetector; + ZeroMemory(mDecisionCycleHelper); + ZeroMemory(mAnalyseCycleHelper); + ZeroMemory(mConsolidationCycleHelper); + ZeroMemory(mVisionCycleHelper); + + // + delete mXWZSignalDetector; + ZeroMemory(mXWZSignalDetector); + + // + delete mXSupDemOBSSignalDetector; + ZeroMemory(mXSupDemOBSSignalDetector); } /** @@ -197,8 +207,22 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy bool hasSignal = false; // + bool hasXWZSignal = false; bool hasXSupDemOBSSignal = false; + // + // XSupDemOBS Signal ... + X121SMCStrategyXWZSignalConditions mXWZConditions; + if (useXWZSignal && !hasSignal) + { + // + hasXWZSignal = DetectXWZSignal( + conditions, + mXWZConditions // + ); + hasSignal = hasXWZSignal; + } + // // XSupDemOBS Signal ... X121SMCStrategyXSupDemOBSSignalConditions mXSupDemOBSConditions; @@ -376,6 +400,20 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy signal.trailSL = true; signal.trailSLStartOnReachTPLevel = 3; signal.fullTPLevel = signal.GetRiskRewardRatio(); + + // // + // mXSupDemOBSSignalDetector.RemoveDraws(); + // mXSupDemOBSSignalDetector.DrawConditions( + // mXSupDemOBSConditions, + // mVisionCycleHelper.mPOIDrawer // + // ); + + // // + // mXSupDemOBSSignalDetector.RemoveWorkingZoneDraws(); + // mXSupDemOBSSignalDetector.DrawWorkingZone( + // mXSupDemOBSConditions, + // mVisionCycleHelper.mPOIDrawer // + // ); } // @@ -430,6 +468,72 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // Clean(guards); + // + int count = ArraySize(positions); + result = IsValidSize(count); + if (!result) + { + return result; + } + + // + // XWZ Guard Detection ... + if (useXWZSignal) + { + // + X121SMCGuard xwzGuards[]; + bool hasGuard = mXWZSignalDetector.DetectGuards( + xwzGuards, + positions, + mDecisionCycleHelper, + mAnalyseCycleHelper, + mConsolidationCycleHelper, + mVisionCycleHelper // + ); + + // + if (hasGuard) + { + // + Copy( + xwzGuards, + guards, + false // + ); + } + } + + // + // XSupDemOBS Guard Detection ... + if (useXSupDemOBSSignal) + { + // + X121SMCGuard xsupDemOBSGuards[]; + bool hasGuard = mXSupDemOBSSignalDetector.DetectGuards( + xsupDemOBSGuards, + positions, + mDecisionCycleHelper, + mAnalyseCycleHelper, + mConsolidationCycleHelper, + mVisionCycleHelper // + ); + + // + if (hasGuard) + { + // + Copy( + xsupDemOBSGuards, + guards, + false // + ); + } + } + + // + count = ArraySize(guards); + result = IsValidSize(count); + // return result; } @@ -439,53 +543,9 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy */ void DoUnwaitedTicksWork() override { - // - // Update All Cycle Helpers ... - int zIndex = 0; - int loopback = 7; - // // Decision ... mDecisionCycleHelper.Update(); - - // // - // // Analyse ... - // ENUM_XPOI_EVENTS analysePoiEvents[]; - // ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - // X121SMCCycleConditions analyseConditions; - // mAnalyseCycleHelper.GetConditions( - // analyseCycleEvents, - // analysePoiEvents, - // analyseConditions, - // zIndex, - // loopback // - // ); - - // // - // // Consolidation ... - // ENUM_XPOI_EVENTS consolidationPoiEvents[]; - // ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - // X121SMCCycleConditions consolidationConditions; - // mConsolidationCycleHelper.GetConditions( - // consolidationCycleEvents, - // consolidationPoiEvents, - // consolidationConditions, - // zIndex, - // loopback // - // ); - - // // - // // Vision ... - // ENUM_XPOI_EVENTS visionPoiEvents[]; - // ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - // X121SMCCycleConditions visionConditions; - // mVisionCycleHelper.GetConditions( - // visionCycleEvents, - // visionPoiEvents, - // visionConditions, - // zIndex, - // loopback // - // ); } /** @@ -519,6 +579,240 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // // Signalling Functions ... + // + // XWZ Signal ... + bool DetectXWZSignal( + X121SMCStrategyConditions &conditions, + X121SMCStrategyXWZSignalConditions &xSupDemOBSConditions // + ) + { + // + bool result = false; + + // + // Validate Cycle Helpers ... + result = + // + mVisionCycleHelper != NULL && + mAnalyseCycleHelper != NULL && + mDecisionCycleHelper != NULL && + mConsolidationCycleHelper != NULL + // + ; + if (!result) + { + return result; + } + + // + 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_XSUPDEMOBS; + string providerStr = ToString(provider); + + // + // Detect Setup Conditions ... + datetime setupTime = mXWZSignalDetector.mConditions.setupTime; + bool isSetuped = mXWZSignalDetector.mConditions.IsSetuped(); + ENUM_X_DIRECTION setupDir = mXWZSignalDetector.mConditions.dir; + if (!isSetuped) + { + // + // Detect Signal Setup ... + isSetuped = mXWZSignalDetector.DetectSignalSetup( + symbol, + period, + mDecisionCycleHelper, + mAnalyseCycleHelper, + mConsolidationCycleHelper, + mVisionCycleHelper // + ); + + // + setupDir = mXWZSignalDetector.mConditions.dir; + setupTime = mXWZSignalDetector.mConditions.setupTime; + + // + if (isSetuped) + { + // + int items = mXWZSignalDetector + .AddConditionsIfNotExists(); + + // + mXWZSignalDetector.mConditions.Clean(); + } + } + + // + int conditionsCount = ArraySize(mXWZSignalDetector.mConditionsCollection); + result = IsValidSize(conditionsCount); + if (!result) + { + return result; + } + + // + // Looking For Conditions ... + int selectedIndex = 0; + X121SMCStrategyXWZSignalConditions mTmpConditions[]; + Copy( + mXWZSignalDetector.mConditionsCollection, + mTmpConditions // + ); + X121SMCStrategyXWZSignalConditions 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 = mXWZSignalDetector + .DetectSignalTrigger( + mTmpConditions[i], + symbol, + period, + mDecisionCycleHelper, + mAnalyseCycleHelper, + mConsolidationCycleHelper, + mVisionCycleHelper // + ); + + // + result = canTrigger; + if (!result) + { + // + bool isISetuped = mTmpConditions[i].IsSetuped(); + if (!isISetuped) + { + // + ArrayRemove( + mXWZSignalDetector.mConditionsCollection, + 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( + mXWZSignalDetector.mConditionsCollection, + 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; + + // + xSupDemOBSConditions = mConditions; + + // + mConditions.Clean(); + + // + return result; + } + // // XSupDemOBS Signal ... bool DetectXSupDemOBSSignal( @@ -607,14 +901,14 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // // Detect Setup Conditions ... - datetime setupTime = mXSupDemONSSignalDetector.mConditions.setupTime; - bool isSetuped = mXSupDemONSSignalDetector.mConditions.IsSetuped(); - ENUM_X_DIRECTION setupDir = mXSupDemONSSignalDetector.mConditions.dir; + datetime setupTime = mXSupDemOBSSignalDetector.mConditions.setupTime; + bool isSetuped = mXSupDemOBSSignalDetector.mConditions.IsSetuped(); + ENUM_X_DIRECTION setupDir = mXSupDemOBSSignalDetector.mConditions.dir; if (!isSetuped) { // // Detect Signal Setup ... - isSetuped = mXSupDemONSSignalDetector.DetectSignalSetup( + isSetuped = mXSupDemOBSSignalDetector.DetectSignalSetup( symbol, period, mDecisionCycleHelper, @@ -624,23 +918,23 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy ); // - setupDir = mXSupDemONSSignalDetector.mConditions.dir; - setupTime = mXSupDemONSSignalDetector.mConditions.setupTime; + setupDir = mXSupDemOBSSignalDetector.mConditions.dir; + setupTime = mXSupDemOBSSignalDetector.mConditions.setupTime; // if (isSetuped) { // - int items = mXSupDemONSSignalDetector + int items = mXSupDemOBSSignalDetector .AddConditionsIfNotExists(); // - mXSupDemONSSignalDetector.mConditions.Clean(); + mXSupDemOBSSignalDetector.mConditions.Clean(); } } // - int conditionsCount = ArraySize(mXSupDemONSSignalDetector.mConditionsCollection); + int conditionsCount = ArraySize(mXSupDemOBSSignalDetector.mConditionsCollection); result = IsValidSize(conditionsCount); if (!result) { @@ -652,7 +946,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy int selectedIndex = 0; X121SMCStrategyXSupDemOBSSignalConditions mTmpConditions[]; Copy( - mXSupDemONSSignalDetector.mConditionsCollection, + mXSupDemOBSSignalDetector.mConditionsCollection, mTmpConditions // ); X121SMCStrategyXSupDemOBSSignalConditions mConditions; @@ -666,7 +960,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy { // // Detect Signal Trigger ... - canTrigger = mXSupDemONSSignalDetector + canTrigger = mXSupDemOBSSignalDetector .DetectSignalTrigger( mTmpConditions[i], symbol, @@ -687,7 +981,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy { // ArrayRemove( - mXSupDemONSSignalDetector.mConditionsCollection, + mXSupDemOBSSignalDetector.mConditionsCollection, i, 1 // ); @@ -720,7 +1014,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // // Remove Selected Index from Main Collection ... ArrayRemove( - mXSupDemONSSignalDetector.mConditionsCollection, + mXSupDemOBSSignalDetector.mConditionsCollection, selectedIndex, 1 // ); @@ -768,7 +1062,8 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy void InitialHelpers() { // - useXSupDemOBSSignal = true; + useXWZSignal = true; + useXSupDemOBSSignal = false; // string symbol = GetSymbol();