From 6157bbe1257936b9ac2659e82179ec68585e3aeb Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Thu, 6 Mar 2025 23:35:44 +0330 Subject: [PATCH] add support for Cycle Provider ... --- Classes/x-saherelm.x-poi.drawer.class.mq5 | 107 +- .../x-121.smc.market.cycle.helper.class.mq5 | 401 ++++ X121SMCEA/Libraries/x-121.smc.guard.lib.mq5 | 1742 ++++++++--------- .../Signals/x-121.smc.xwz.signal.class.mq5 | 669 +------ .../Signals/x-121.smc.xwz.signal.lib.mq5 | 326 +-- .../Strategy/x-121.smc.strategy.class.mq5 | 28 +- 6 files changed, 1488 insertions(+), 1785 deletions(-) diff --git a/Classes/x-saherelm.x-poi.drawer.class.mq5 b/Classes/x-saherelm.x-poi.drawer.class.mq5 index 2cd03112..8b3d51d6 100644 --- a/Classes/x-saherelm.x-poi.drawer.class.mq5 +++ b/Classes/x-saherelm.x-poi.drawer.class.mq5 @@ -4695,49 +4695,88 @@ class XCPOIDrawer : public XCBase // // Fair Value Gap ... - has = item.HasFVGs(); - if (has && - drawFairValueGaps) + XCFVG *fvg; + has = item.GetMainFVG(fvg); + if (has) { // - count = item.CountFVGs(); - for (int i = 0; i < count; i++) + Clean(tmpObjects); + int fvgsCount = DrawFairValueGap( + fvg, + tmpObjects, + drawFVGStartedBar, + drawFVGActivatedBar, + drawFVGBreakedBar, + drawFVGWorkedBar, + widthFVGStartedBar, + clrFVGStartedBar, + styleFVGStartedBar, + widthFVGActivatedBar, + clrFVGActivatedBar, + styleFVGActivatedBar, + widthFVGBreakedBar, + clrFVGBreakedBar, + styleFVGBreakedBar, + widthFVGWorkedBar, + clrFVGWorkedBar, + styleFVGWorkedBar // + ); + has = IsValidSize(fvgsCount); + if (has) { // - Clean(tmpObjects); - int fvgsCount = DrawFairValueGap( - item.fvgs[i], + Copy( tmpObjects, - drawFVGStartedBar, - drawFVGActivatedBar, - drawFVGBreakedBar, - drawFVGWorkedBar, - widthFVGStartedBar, - clrFVGStartedBar, - styleFVGStartedBar, - widthFVGActivatedBar, - clrFVGActivatedBar, - styleFVGActivatedBar, - widthFVGBreakedBar, - clrFVGBreakedBar, - styleFVGBreakedBar, - widthFVGWorkedBar, - clrFVGWorkedBar, - styleFVGWorkedBar // + objects, + false // ); - has = IsValidSize(fvgsCount); - if (has) - { - // - Copy( - tmpObjects, - objects, - false // - ); - } } } + // // + // has = item.HasFVGs(); + // if (has && + // drawFairValueGaps) + // { + // // + // count = item.CountFVGs(); + // for (int i = 0; i < count; i++) + // { + // // + // Clean(tmpObjects); + // int fvgsCount = DrawFairValueGap( + // item.fvgs[i], + // tmpObjects, + // drawFVGStartedBar, + // drawFVGActivatedBar, + // drawFVGBreakedBar, + // drawFVGWorkedBar, + // widthFVGStartedBar, + // clrFVGStartedBar, + // styleFVGStartedBar, + // widthFVGActivatedBar, + // clrFVGActivatedBar, + // styleFVGActivatedBar, + // widthFVGBreakedBar, + // clrFVGBreakedBar, + // styleFVGBreakedBar, + // widthFVGWorkedBar, + // clrFVGWorkedBar, + // styleFVGWorkedBar // + // ); + // has = IsValidSize(fvgsCount); + // if (has) + // { + // // + // Copy( + // tmpObjects, + // objects, + // false // + // ); + // } + // } + // } + // Clean(tmpObjects); diff --git a/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 b/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 index e013813e..94612298 100644 --- a/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 @@ -69,6 +69,7 @@ enum ENUM_X_CYCLE_EVENTS VALE_PIVOT_ENDED, }; +// class XC121SMCCycleHelper : public XCBase { // @@ -676,3 +677,403 @@ class XC121SMCCycleHelper : public XCBase // }; + +// +struct X121SMCStrategySignalProviderData +{ + // + // Props ... + + // + // Decision ... + XPOIState decisionState; + double decisionBullishScore; + double decisionBearishScore; + X121Conditions decisionXConditions; + ENUM_XPOI_EVENTS decisionPoiEvents[]; + XC121SMCCycleHelper *decisionCycleHelper; + ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; + X121SMCCycleConditions decisionConditions; + + // + // Analyse ... + XPOIState analyseState; + double analyseBullishScore; + double analyseBearishScore; + X121Conditions analyseXConditions; + ENUM_XPOI_EVENTS analysePoiEvents[]; + XC121SMCCycleHelper *analyseCycleHelper; + ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; + X121SMCCycleConditions analyseConditions; + + // + // Consolidation ... + XPOIState consolidationState; + double consolidationBullishScore; + double consolidationBearishScore; + X121Conditions consolidationXConditions; + ENUM_XPOI_EVENTS consolidationPoiEvents[]; + XC121SMCCycleHelper *consolidationCycleHelper; + ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; + X121SMCCycleConditions consolidationConditions; + + // + // Vision ... + XPOIState visionState; + double visionBullishScore; + double visionBearishScore; + X121Conditions visionXConditions; + ENUM_XPOI_EVENTS visionPoiEvents[]; + XC121SMCCycleHelper *visionCycleHelper; + ENUM_X_CYCLE_EVENTS visionCycleEvents[]; + X121SMCCycleConditions visionConditions; + + // + // Constructor ... + X121SMCStrategySignalProviderData() + { + Clean(); + } + + // + // Tools ... + + // + // Cleanup ... + void Clean() + { + // + // Decision ... + decisionState.Clean(); + decisionBullishScore = 0; + decisionBearishScore = 0; + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + decisionConditions.Clean(); + decisionXConditions.Clean(); + + // + // Analyse ... + analyseState.Clean(); + analyseBullishScore = 0; + analyseBearishScore = 0; + Clean(analysePoiEvents); + Clean(analyseCycleEvents); + analyseConditions.Clean(); + analyseXConditions.Clean(); + + // + // Consolidation ... + consolidationState.Clean(); + consolidationBullishScore = 0; + consolidationBearishScore = 0; + Clean(consolidationPoiEvents); + Clean(consolidationCycleEvents); + consolidationConditions.Clean(); + consolidationXConditions.Clean(); + + // + // Vision ... + visionState.Clean(); + visionBullishScore = 0; + visionBearishScore = 0; + Clean(visionPoiEvents); + Clean(visionCycleEvents); + visionConditions.Clean(); + visionXConditions.Clean(); + } + + // + void Destroy() + { + // + Clean(); + + // + ZeroMemory(decisionCycleHelper); + ZeroMemory(analyseCycleHelper); + ZeroMemory(consolidationCycleHelper); + ZeroMemory(visionCycleHelper); + + // + ZeroMemory(this); + } + + // + bool IsValid() + { + // + bool result = false; + + // + result = + visionCycleHelper != NULL && + analyseCycleHelper != NULL && + decisionCycleHelper != NULL && + consolidationCycleHelper != NULL; + + // + return result; + } + + // + // Initialize ... + bool Init( + 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; + } + + // + visionCycleHelper = _visionCycleHelper; + analyseCycleHelper = _analyseCycleHelper; + decisionCycleHelper = _decisionCycleHelper; + consolidationCycleHelper = _consolidationCycleHelper; + + // + result = IsValid(); + + // + return result; + } + + // + // Prepare all ... + bool Prepare( + int barIndex = 0, + int loopback = 10 // + ) + { + // + bool result = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (loopback < 7) + { + loopback = 7; + } + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + // Decision ... + result = decisionCycleHelper.GetConditions( + decisionCycleEvents, + decisionPoiEvents, + decisionConditions, + barIndex, + loopback // + ); + if (!result) + { + // + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + + // + decisionConditions.Clean(); + + // + return result; + } + + // + // Analyse ... + result = analyseCycleHelper.GetConditions( + analyseCycleEvents, + analysePoiEvents, + analyseConditions, + barIndex, + loopback // + ); + if (!result) + { + // + Clean(analysePoiEvents); + Clean(decisionPoiEvents); + + // + Clean(analyseCycleEvents); + Clean(decisionCycleEvents); + + // + analyseConditions.Clean(); + decisionConditions.Clean(); + + // + return result; + } + + // + // Consolidation ... + result = consolidationCycleHelper.GetConditions( + consolidationCycleEvents, + consolidationPoiEvents, + consolidationConditions, + barIndex, + loopback // + ); + if (!result) + { + // + Clean(analysePoiEvents); + Clean(decisionPoiEvents); + Clean(consolidationPoiEvents); + + // + Clean(analyseCycleEvents); + Clean(decisionCycleEvents); + Clean(consolidationCycleEvents); + + // + analyseConditions.Clean(); + decisionConditions.Clean(); + consolidationConditions.Clean(); + + // + return result; + } + + // + // Vision ... + result = visionCycleHelper.GetConditions( + visionCycleEvents, + visionPoiEvents, + visionConditions, + barIndex, + loopback // + ); + if (!result) + { + // + Clean(visionPoiEvents); + Clean(analysePoiEvents); + Clean(decisionPoiEvents); + Clean(consolidationPoiEvents); + + // + Clean(visionCycleEvents); + Clean(analyseCycleEvents); + Clean(decisionCycleEvents); + Clean(consolidationCycleEvents); + + // + visionConditions.Clean(); + analyseConditions.Clean(); + decisionConditions.Clean(); + consolidationConditions.Clean(); + + // + return result; + } + + // + // Cycles POI States ... + decisionState = decisionConditions.state; + analyseState = analyseConditions.state; + consolidationState = consolidationConditions.state; + visionState = visionConditions.state; + + // + // Cycle X121Conditions ... + decisionXConditions = decisionConditions.x121Conditions; + analyseXConditions = analyseConditions.x121Conditions; + consolidationXConditions = consolidationConditions.x121Conditions; + visionXConditions = visionConditions.x121Conditions; + + // + // Decision ... + decisionXConditions.GenerateScore( + decisionBullishScore, + decisionBearishScore // + ); + + // + // Analyse ... + analyseXConditions.GenerateScore( + analyseBullishScore, + analyseBearishScore // + ); + + // + // Consolidation ... + consolidationXConditions.GenerateScore( + consolidationBullishScore, + consolidationBearishScore // + ); + + // + // Vision ... + visionXConditions.GenerateScore( + visionBullishScore, + visionBearishScore // + ); + + // + return result; + } + + // + void MaxRequiredPOIs(int value) + { + // + if (!IsValid()) + { + return; + } + + // + visionCycleHelper.mPOIDetector.MaxRequiredPOIs(value); + analyseCycleHelper.mPOIDetector.MaxRequiredPOIs(value); + decisionCycleHelper.mPOIDetector.MaxRequiredPOIs(value); + consolidationCycleHelper.mPOIDetector.MaxRequiredPOIs(value); + } + + // + void MaxAllowedLoopbackForInit(int value) + { + // + if (!IsValid()) + { + return; + } + + // + visionCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(value); + analyseCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(value); + decisionCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(value); + consolidationCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(value); + } + + // +}; diff --git a/X121SMCEA/Libraries/x-121.smc.guard.lib.mq5 b/X121SMCEA/Libraries/x-121.smc.guard.lib.mq5 index 87bebf7f..864501d6 100644 --- a/X121SMCEA/Libraries/x-121.smc.guard.lib.mq5 +++ b/X121SMCEA/Libraries/x-121.smc.guard.lib.mq5 @@ -25,16 +25,12 @@ #include "../Libraries/x-121.smc.lib.mq5" // -XConsolidationZone x121SMCConsolidationZone; bool DetectX121SMCGuards( // - string provider, // Provider ... + string signalProvider, // Provider ... X121SMCGuard &guards[], const XPosition &positions[], - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, + X121SMCStrategySignalProviderData &provider, // // Guard Types ... ENUM_X_121_SMC_GUARD_ACTIONS &ignoreGuards[], @@ -47,927 +43,927 @@ bool DetectX121SMCGuards( // bool result = false; - // - bool isCycleHelpersValid = - // - visionCycleHelper != NULL && - analyseCycleHelper != NULL && - decisionCycleHelper != NULL && - consolidationCycleHelper != NULL - // - ; - - // - // Ignore Guards ... - bool hasIgnoreGuards = HasChild(ignoreGuards); - bool isColseIgnored = - hasIgnoreGuards && - Contains( - X_121_SMC_GUARD_ACTION_CLOSE, - ignoreGuards // - ); - bool isColseAllIgnored = - hasIgnoreGuards && - Contains( - X_121_SMC_GUARD_ACTION_CLOSE_ALL, - ignoreGuards // - ); - bool isColseLongsIgnored = - hasIgnoreGuards && - Contains( - X_121_SMC_GUARD_ACTION_CLOSE_LONGS, - ignoreGuards // - ); - bool isColseShortsIgnored = - hasIgnoreGuards && - Contains( - X_121_SMC_GUARD_ACTION_CLOSE_SHORTS, - ignoreGuards // - ); - bool isPartialColseIgnored = - hasIgnoreGuards && - Contains( - X_121_SMC_GUARD_ACTION_PARTIAL_CLOSE, - ignoreGuards // - ); - bool isTrailStopIgnored = - hasIgnoreGuards && - Contains( - X_121_SMC_GUARD_ACTION_TRAIL_STOP, - ignoreGuards // - ); - bool isTrailTargetIgnored = - hasIgnoreGuards && - Contains( - X_121_SMC_GUARD_ACTION_TRAIL_TARGET, - ignoreGuards // - ); - bool isHedgeIgnored = - hasIgnoreGuards && - Contains( - X_121_SMC_GUARD_ACTION_HEDGE, - ignoreGuards // - ); - - // - bool isAllIgnores = - // - isColseIgnored && - isHedgeIgnored && - isColseAllIgnored && - isTrailStopIgnored && - isColseLongsIgnored && - isColseShortsIgnored && - isTrailTargetIgnored && - isPartialColseIgnored - // - ; - result = !isAllIgnores && - 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(); - - // - 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; - } - - // - // 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) - { - // - zBar.Clean(); - result = HasChild(guards); - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - result = HasChild(guards); - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - result = HasChild(guards); - return result; - } - - // - XOHCL ppBar; - result = ppBar.Init( - symbol, - period, - ppIndex // - ); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - ppBar.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); - - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionConditions.Clean(); - 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(); - - // - Clean(analysePoiEvents); - Clean(analyseCycleEvents); - - // - analyseConditions.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(); - - // - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - consolidationConditions.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(); - - // - Clean(visionPoiEvents); - Clean(visionCycleEvents); - - // - visionConditions.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; - - // - // - // + // // + // bool isCycleHelpersValid = + // // + // visionCycleHelper != NULL && + // analyseCycleHelper != NULL && + // decisionCycleHelper != NULL && + // consolidationCycleHelper != NULL + // // + // ; // // - // // Detect Consolidation Zone ... + // // Ignore Guards ... + // bool hasIgnoreGuards = HasChild(ignoreGuards); + // bool isColseIgnored = + // hasIgnoreGuards && + // Contains( + // X_121_SMC_GUARD_ACTION_CLOSE, + // ignoreGuards // + // ); + // bool isColseAllIgnored = + // hasIgnoreGuards && + // Contains( + // X_121_SMC_GUARD_ACTION_CLOSE_ALL, + // ignoreGuards // + // ); + // bool isColseLongsIgnored = + // hasIgnoreGuards && + // Contains( + // X_121_SMC_GUARD_ACTION_CLOSE_LONGS, + // ignoreGuards // + // ); + // bool isColseShortsIgnored = + // hasIgnoreGuards && + // Contains( + // X_121_SMC_GUARD_ACTION_CLOSE_SHORTS, + // ignoreGuards // + // ); + // bool isPartialColseIgnored = + // hasIgnoreGuards && + // Contains( + // X_121_SMC_GUARD_ACTION_PARTIAL_CLOSE, + // ignoreGuards // + // ); + // bool isTrailStopIgnored = + // hasIgnoreGuards && + // Contains( + // X_121_SMC_GUARD_ACTION_TRAIL_STOP, + // ignoreGuards // + // ); + // bool isTrailTargetIgnored = + // hasIgnoreGuards && + // Contains( + // X_121_SMC_GUARD_ACTION_TRAIL_TARGET, + // ignoreGuards // + // ); + // bool isHedgeIgnored = + // hasIgnoreGuards && + // Contains( + // X_121_SMC_GUARD_ACTION_HEDGE, + // ignoreGuards // + // ); // // - // // Detect Consolidation Zones ... + // bool isAllIgnores = + // // + // isColseIgnored && + // isHedgeIgnored && + // isColseAllIgnored && + // isTrailStopIgnored && + // isColseLongsIgnored && + // isColseShortsIgnored && + // isTrailTargetIgnored && + // isPartialColseIgnored + // // + // ; + // result = !isAllIgnores && + // isCycleHelpersValid; + // if (!result) + // { + // return result; + // } // // - // XBoxZone lastBullishBox; - // XBoxZone prevLastBullishBox; - // bool hasLastBullishBox = false; - // bool hasPrevLastBullishBox = false; - // XConsolidationZone lastBullishZone; - // bool isLastBullishAbovePrev = false; - // bool isLastBullishBelowPrev = false; - // XConsolidationZone prevLastBullishZone; + // int count = ArraySize(positions); + // result = IsValidSize(count); + // if (!result) + // { + // return result; + // } // // - // XBoxZone lastBearishBox; - // XBoxZone prevLastBearishBox; - // bool hasLastBearishBox = false; - // bool hasPrevLastBearishBox = false; - // XConsolidationZone lastBearishZone; - // bool isLastBearishAbovePrev = false; - // bool isLastBearishBelowPrev = false; - // XConsolidationZone prevLastBearishZone; + // string symbol = decisionCycleHelper.GetSymbol(); + // ENUM_TIMEFRAMES period = decisionCycleHelper.GetPeriod(); // // - // 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) + // XPosition ownPositions[]; + // XPosition ownLongPositions[]; + // XPosition ownShortPositions[]; + // for (int i = 0; i < count; i++) // { // // - // bullishConsolidationZonesCount = decisionCycleHelper - // .FillConsolidationZones( - // X_DIRECTION_BULLISH, - // bullishConsolidationZones // - // ); - // hasBullishConsolidationZones = IsValidSize(bullishConsolidationZonesCount); - - // // - // bearishConsolidationZonesCount = decisionCycleHelper - // .FillConsolidationZones( - // X_DIRECTION_BEARISH, - // bearishConsolidationZones // - // ); - // hasBearishConsolidationZones = IsValidSize(bearishConsolidationZonesCount); - - // // - // // - // // - - // // - // if (hasBullishConsolidationZones && - // bullishConsolidationZonesCount >= 2) + // XPosition iPosition = positions[i]; + // bool isOwn = iPosition + // .IsFiltersPassed( + // symbol, + // provider, + // NULL, + // X_POSITION_TYPE_ALL, + // iPosition.magic // + // ); + // if (isOwn) // { // // - // lastBullishZone = bullishConsolidationZones[bullishConsolidationZonesCount - 1]; - // prevLastBullishZone = bullishConsolidationZones[bullishConsolidationZonesCount - 2]; - - // // - // hasLastBullishBox = ToBox( - // lastBullishBox, - // lastBullishZone // - // ); - // hasPrevLastBullishBox = ToBox( - // prevLastBullishBox, - // prevLastBullishZone // + // AddRef( + // iPosition, + // ownPositions // // ); // // - // isLastBullishAbovePrev = hasLastBullishBox && - // hasPrevLastBullishBox && - // IsBoxAbove( - // lastBullishBox, - // prevLastBullishBox // - // ); - - // // - // isLastBullishBelowPrev = hasLastBullishBox && - // hasPrevLastBullishBox && - // IsBoxBelow( - // lastBullishBox, - // prevLastBullishBox // - // ); + // 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); // // - // if (hasBearishConsolidationZones && - // bearishConsolidationZonesCount >= 2) - // { - // // - // lastBearishZone = bearishConsolidationZones[bearishConsolidationZonesCount - 1]; - // prevLastBearishZone = bearishConsolidationZones[bearishConsolidationZonesCount - 2]; + // return result; + // } - // // - // hasLastBearishBox = ToBox( - // lastBearishBox, - // lastBearishZone // - // ); - // hasPrevLastBearishBox = ToBox( - // prevLastBearishBox, - // prevLastBearishZone // - // ); + // // + // // Here we Are Sure there is Positions to Guard ... + // // based on Current Provider ... - // // - // isLastBearishAbovePrev = hasLastBearishBox && - // hasPrevLastBearishBox && - // IsBoxAbove( - // lastBearishBox, - // prevLastBearishBox // - // ); + // // + // // Detect Required Data for Analyse Market to Guard Positions ... - // // - // isLastBearishBelowPrev = hasLastBearishBox && - // hasPrevLastBearishBox && - // IsBoxBelow( - // lastBearishBox, - // prevLastBearishBox // - // ); - // } + // // + // 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) + // { + // // + // zBar.Clean(); + // result = HasChild(guards); + // return result; + // } + + // // + // XOHCL cBar; + // result = cBar.Init( + // symbol, + // period, + // cIndex // + // ); + // if (!result) + // { + // // + // zBar.Clean(); + // cBar.Clean(); + // result = HasChild(guards); + // return result; + // } + + // // + // XOHCL pBar; + // result = pBar.Init( + // symbol, + // period, + // pIndex // + // ); + // if (!result) + // { + // // + // zBar.Clean(); + // cBar.Clean(); + // pBar.Clean(); + // result = HasChild(guards); + // return result; + // } + + // // + // XOHCL ppBar; + // result = ppBar.Init( + // symbol, + // period, + // ppIndex // + // ); + // if (!result) + // { + // // + // zBar.Clean(); + // cBar.Clean(); + // pBar.Clean(); + // ppBar.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); + + // // + // Clean(decisionPoiEvents); + // Clean(decisionCycleEvents); + + // // + // decisionConditions.Clean(); + // 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(); + + // // + // Clean(analysePoiEvents); + // Clean(analyseCycleEvents); + + // // + // analyseConditions.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(); + + // // + // Clean(consolidationPoiEvents); + // Clean(consolidationCycleEvents); + + // // + // consolidationConditions.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(); + + // // + // Clean(visionPoiEvents); + // Clean(visionCycleEvents); + + // // + // visionConditions.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 ... + + // // // + // // // Detect Consolidation Zones ... + + // // // + // // 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 ... + // if (!isColseIgnored) + // { + // // + // // TODO: + // // - [] Implement Close on Nearest on TP ... + // } + + // // + // // X_121_SMC_GUARD_ACTION_CLOSE_ALL: + // // Close All Positions on Specified Conditions ... + // if (!isColseAllIgnored) + // { + // // + // // TODO: + // // - [] Implement Close All Positions on Weekend ... + // } + + // // + // // X_121_SMC_GUARD_ACTION_CLOSE_LONGS: + // // Close All Long Positions on Specified Conditions ... + // if (!isColseLongsIgnored) + // { // // // } - // - // Detect High Probability Swings ... - // bool isSwingLow = + // // + // // X_121_SMC_GUARD_ACTION_CLOSE_SHORTS: + // // Close All Short Positions on Specified Conditions ... + // if (!isColseShortsIgnored) + // { // // - // 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; + // // X_121_SMC_GUARD_ACTION_PARTIAL_CLOSE: + // // Partial Close Specified Position on Specified Conditions ... + // if (!isPartialColseIgnored) + // { + // // + // // Breake Even ... + // // Usually Break Even Works on TP2 Reached ... + // // when tp reached to required Level, we Close 50% of Entered Volume ... + // bool canBreakEven = breakEvenTPLevel >= 0; + + // // + // for (int i = 0; i < count; i++) + // { + // // + // XPosition iPosition = ownPositions[i]; + + // // + // bool isInProfit = iPosition.profit > 0; + + // // + // double reachedTPLevel = 0; + // double reachedTPPrice = 0; + // if (isInProfit) + // { + // // + // iPosition.CalculateReahedTP( + // reachedTPLevel, + // reachedTPPrice // + // ); + // } + + // // + // // Break Event ... + // if (canBreakEven) + // { + // // + // // Position Must be In Profit ... + // if (!isInProfit) + // { + // continue; + // } + + // // + // bool canDoBreakEven = reachedTPLevel == breakEvenTPLevel && + // reachedTPPrice > 0; + // if (canDoBreakEven) + // { + // // + // X121SMCGuard iGuard; + + // // + // iGuard.time = cTime; + // iGuard.symbol = symbol; + // iGuard.provider = provider; + // iGuard.action = X_121_SMC_GUARD_ACTION_PARTIAL_CLOSE; + + // // + // iGuard.ticket = iPosition.ticket; + + // // + // iGuard.volumeMultiplier = 0.5; + + // // + // AddGuard( + // iGuard, + // guards // + // ); + // } + // } + // } + // } // // - // bool isStrongSwingHighBelowLastBearishBox = - // isStrongSwingHigh && - // hasLastBearishBox && - // pBar.high < lastBearishBox.lower; + // // X_121_SMC_GUARD_ACTION_TRAIL_STOP: + // // Trail Stop Specified Position on Specified Conditions ... + // if (!isTrailStopIgnored) + // { + // // + // for (int i = 0; i < count; i++) + // { + // // + // XPosition iPosition = ownPositions[i]; - // - // Here We Have all Requirements for Guarding Positions ... + // // + // bool isLong = IsLong(iPosition.type); + // bool isInProfit = iPosition.profit > 0; - // - // 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 + // // + // double reachedTPLevel = 0; + // double reachedTPPrice = 0; + // if (isInProfit) + // { + // // + // iPosition.CalculateReahedTP( + // reachedTPLevel, + // reachedTPPrice // + // ); + // } - // - // X_121_SMC_GUARD_ACTION_CLOSE: - // Close Specified Position on Specified Conditions ... - if (!isColseIgnored) - { - // - // TODO: - // - [] Implement Close on Nearest on TP ... - } + // // + // // Trai Stop ... + // if (!isInProfit) + // { + // continue; + // } - // - // X_121_SMC_GUARD_ACTION_CLOSE_ALL: - // Close All Positions on Specified Conditions ... - if (!isColseAllIgnored) - { - // - // TODO: - // - [] Implement Close All Positions on Weekend ... - } + // // + // double trailedStop = 0; - // - // X_121_SMC_GUARD_ACTION_CLOSE_LONGS: - // Close All Long Positions on Specified Conditions ... - if (!isColseLongsIgnored) - { - // - } + // // + // // Trail Stop Senarios ... + // // - occures two same type consolidation zones in order of positions type; + // // - occures a swing in order of consolidation zones ... - // - // X_121_SMC_GUARD_ACTION_CLOSE_SHORTS: - // Close All Short Positions on Specified Conditions ... - if (!isColseShortsIgnored) - { - // - } + // // // + // // bool canTrailBasedOnTwoZone = + // // isLong + // // ? isLastBullishAbovePrev + // // : isLastBearishBelowPrev; + // // if (canTrailBasedOnTwoZone) + // // { + // // // + // // trailedStop = + // // isLong + // // ? prevLastBullishBox.lower + // // : prevLastBearishBox.upper; + // // } - // - // X_121_SMC_GUARD_ACTION_PARTIAL_CLOSE: - // Partial Close Specified Position on Specified Conditions ... - if (!isPartialColseIgnored) - { - // - // Breake Even ... - // Usually Break Even Works on TP2 Reached ... - // when tp reached to required Level, we Close 50% of Entered Volume ... - bool canBreakEven = breakEvenTPLevel >= 0; + // // // + // // bool canTrailBasedOnZoneSwing = + // // trailedStop <= 0 && + // // (isLong + // // ? isStrongSwingLowAboveLastBullishBox + // // : isStrongSwingHighBelowLastBearishBox); + // // if (canTrailBasedOnZoneSwing) + // // { + // // // + // // trailedStop = + // // isLong + // // ? pBar.low + // // : pBar.high; + // // } - // - for (int i = 0; i < count; i++) - { - // - XPosition iPosition = ownPositions[i]; + // // // + // // bool canDoTrailStop = + // // trailedStop > 0 && + // // ( + // // // + // // iPosition.sl == 0 + // // ? (isLong + // // ? trailedStop > iPosition.entry && + // // trailedStop < iPosition.price + // // : trailedStop < iPosition.entry && + // // trailedStop > iPosition.price) + // // : (isLong + // // ? trailedStop > iPosition.sl && + // // trailedStop > iPosition.entry && + // // trailedStop < iPosition.price + // // : trailedStop < iPosition.sl && + // // trailedStop < iPosition.entry && + // // trailedStop > iPosition.price) + // // // + // // ) + // // // + // // ; - // - bool isInProfit = iPosition.profit > 0; + // // // + // // if (canDoTrailStop) + // // { + // // // + // // X121SMCGuard iGuard; - // - double reachedTPLevel = 0; - double reachedTPPrice = 0; - if (isInProfit) - { - // - iPosition.CalculateReahedTP( - reachedTPLevel, - reachedTPPrice // - ); - } + // // // + // // iGuard.time = cTime; + // // iGuard.symbol = symbol; + // // iGuard.provider = provider; + // // iGuard.action = X_121_SMC_GUARD_ACTION_TRAIL_STOP; - // - // Break Event ... - if (canBreakEven) - { - // - // Position Must be In Profit ... - if (!isInProfit) - { - continue; - } + // // // + // // iGuard.ticket = iPosition.ticket; - // - bool canDoBreakEven = reachedTPLevel == breakEvenTPLevel && - reachedTPPrice > 0; - if (canDoBreakEven) - { - // - X121SMCGuard iGuard; + // // // + // // iGuard.sl = trailedStop; - // - iGuard.time = cTime; - iGuard.symbol = symbol; - iGuard.provider = provider; - iGuard.action = X_121_SMC_GUARD_ACTION_PARTIAL_CLOSE; + // // // + // // AddGuard( + // // iGuard, + // // guards // + // // ); + // // } + // } + // } - // - iGuard.ticket = iPosition.ticket; + // // + // // X_121_SMC_GUARD_ACTION_TRAIL_TARGET: + // // Trail Target Specified Position on Specified Conditions ... + // if (!isTrailTargetIgnored) + // { + // // + // } - // - iGuard.volumeMultiplier = 0.5; + // // + // // X_121_SMC_GUARD_ACTION_HEDGE: + // // Hedge all Positions on Specified Conditions ... + // if (!isHedgeIgnored) + // { + // // + // } - // - AddGuard( - iGuard, - guards // - ); - } - } - } - } + // // + // // Cleanup Collections ... - // - // X_121_SMC_GUARD_ACTION_TRAIL_STOP: - // Trail Stop Specified Position on Specified Conditions ... - if (!isTrailStopIgnored) - { - // - for (int i = 0; i < count; i++) - { - // - XPosition iPosition = ownPositions[i]; + // // + // Clean(ownPositions); + // Clean(ownLongPositions); + // Clean(ownShortPositions); - // - bool isLong = IsLong(iPosition.type); - bool isInProfit = iPosition.profit > 0; + // // + // zBar.Clean(); + // cBar.Clean(); + // pBar.Clean(); + // ppBar.Clean(); - // - double reachedTPLevel = 0; - double reachedTPPrice = 0; - if (isInProfit) - { - // - iPosition.CalculateReahedTP( - reachedTPLevel, - reachedTPPrice // - ); - } + // // + // Clean(visionPoiEvents); + // Clean(analysePoiEvents); + // Clean(visionCycleEvents); + // Clean(decisionPoiEvents); + // Clean(analyseCycleEvents); + // Clean(decisionCycleEvents); + // Clean(consolidationPoiEvents); + // Clean(consolidationCycleEvents); - // - // Trai Stop ... - if (!isInProfit) - { - continue; - } + // // + // visionState.Clean(); + // analyseState.Clean(); + // decisionState.Clean(); + // visionConditions.Clean(); + // analyseConditions.Clean(); + // visionXConditions.Clean(); + // decisionConditions.Clean(); + // consolidationState.Clean(); + // analyseXConditions.Clean(); + // decisionXConditions.Clean(); + // consolidationConditions.Clean(); + // consolidationXConditions.Clean(); - // - double trailedStop = 0; + // // + // // lastBullishBox.Clean(); + // // lastBearishBox.Clean(); + // // lastBullishZone.Clean(); + // // lastBearishZone.Clean(); + // // prevLastBullishBox.Clean(); + // // prevLastBearishBox.Clean(); + // // prevLastBullishZone.Clean(); + // // prevLastBearishZone.Clean(); - // - // Trail Stop Senarios ... - // - occures two same type consolidation zones in order of positions type; - // - occures a swing in order of consolidation zones ... - - // // - // bool canTrailBasedOnTwoZone = - // isLong - // ? isLastBullishAbovePrev - // : isLastBearishBelowPrev; - // if (canTrailBasedOnTwoZone) - // { - // // - // trailedStop = - // isLong - // ? prevLastBullishBox.lower - // : prevLastBearishBox.upper; - // } - - // // - // bool canTrailBasedOnZoneSwing = - // trailedStop <= 0 && - // (isLong - // ? isStrongSwingLowAboveLastBullishBox - // : isStrongSwingHighBelowLastBearishBox); - // if (canTrailBasedOnZoneSwing) - // { - // // - // trailedStop = - // isLong - // ? pBar.low - // : pBar.high; - // } - - // // - // bool canDoTrailStop = - // trailedStop > 0 && - // ( - // // - // iPosition.sl == 0 - // ? (isLong - // ? trailedStop > iPosition.entry && - // trailedStop < iPosition.price - // : trailedStop < iPosition.entry && - // trailedStop > iPosition.price) - // : (isLong - // ? trailedStop > iPosition.sl && - // trailedStop > iPosition.entry && - // trailedStop < iPosition.price - // : trailedStop < iPosition.sl && - // trailedStop < iPosition.entry && - // trailedStop > iPosition.price) - // // - // ) - // // - // ; - - // // - // if (canDoTrailStop) - // { - // // - // X121SMCGuard iGuard; - - // // - // iGuard.time = cTime; - // iGuard.symbol = symbol; - // iGuard.provider = provider; - // iGuard.action = X_121_SMC_GUARD_ACTION_TRAIL_STOP; - - // // - // iGuard.ticket = iPosition.ticket; - - // // - // iGuard.sl = trailedStop; - - // // - // AddGuard( - // iGuard, - // guards // - // ); - // } - } - } - - // - // X_121_SMC_GUARD_ACTION_TRAIL_TARGET: - // Trail Target Specified Position on Specified Conditions ... - if (!isTrailTargetIgnored) - { - // - } - - // - // X_121_SMC_GUARD_ACTION_HEDGE: - // Hedge all Positions on Specified Conditions ... - if (!isHedgeIgnored) - { - // - } - - // - // 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); + // // + // count = ArraySize(guards); + // result = IsValidSize(count); // return result; diff --git a/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 b/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 index f22b8397..73bad417 100644 --- a/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 @@ -66,10 +66,7 @@ class XCX121SMCXWZSignalDetector : public XCBase // Detect Setup Conditions ... bool DetectSignalSetup( // - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, + X121SMCStrategySignalProviderData &provider, // double maxAllowedSLDistanceInPoint = 300 // @@ -80,14 +77,7 @@ class XCX121SMCXWZSignalDetector : public XCBase // // Validate Cycle Helpers ... - result = - // - visionCycleHelper != NULL && - analyseCycleHelper != NULL && - decisionCycleHelper != NULL && - consolidationCycleHelper != NULL - // - ; + result = provider.IsValid(); if (!result) { // @@ -122,10 +112,24 @@ class XCX121SMCXWZSignalDetector : public XCBase // // Cycles Conditions ... + result = provider.Prepare( + zIndex, + loopback // + ); + if (!result) + { + // + mConditions.Clean(); + return result; + } + + // + // Select Drawer Class ... + XCPOIDrawer *drawer = provider.visionCycleHelper.mPOIDrawer; // XOHCL consolidationZBar; - result = consolidationCycleHelper.GetBar( + result = provider.consolidationCycleHelper.GetBar( consolidationZBar, zIndex // ); @@ -143,189 +147,10 @@ class XCX121SMCXWZSignalDetector : public XCBase // DrawBar( consolidationZBar, - decisionCycleHelper.mPOIDrawer // + drawer // ); } - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionConditions.Clean(); - - // - mConditions.Clean(); - consolidationZBar.Clean(); - - // - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - // - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - - // - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - - // - analyseConditions.Clean(); - decisionConditions.Clean(); - - // - mConditions.Clean(); - consolidationZBar.Clean(); - - // - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - // - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(consolidationPoiEvents); - - // - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationCycleEvents); - - // - analyseConditions.Clean(); - decisionConditions.Clean(); - consolidationConditions.Clean(); - - // - mConditions.Clean(); - consolidationZBar.Clean(); - - // - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(consolidationPoiEvents); - - // - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationCycleEvents); - - // - visionConditions.Clean(); - analyseConditions.Clean(); - decisionConditions.Clean(); - consolidationConditions.Clean(); - - // - mConditions.Clean(); - consolidationZBar.Clean(); - - // - 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; - - // - // Select Drawer Class ... - XCPOIDrawer *drawer = visionCycleHelper.mPOIDrawer; - - // - // Scores ... - - // - // Decision ... - double decisionBullishScore = 0; - double decisionBearishScore = 0; - decisionXConditions.GenerateScore( - decisionBullishScore, - decisionBearishScore // - ); - - // - // Analyse ... - double analyseBullishScore = 0; - double analyseBearishScore = 0; - analyseXConditions.GenerateScore( - analyseBullishScore, - analyseBearishScore // - ); - // // // @@ -350,7 +175,7 @@ class XCX121SMCXWZSignalDetector : public XCBase ENUM_X_DIRECTION wzOveralDir = X_DIRECTION_NONE; ENUM_X_DIRECTION signalBoxDir = X_DIRECTION_NONE; ENUM_X121SMC_XWZ_PRIORITY priority = X121SMC_XWZ_PRIORITY_NONE; - ENUM_X121SMC_XWZ_PROVIDERS provider = X121SMC_XWZ_PROVIDER_NONE; + ENUM_X121SMC_XWZ_PROVIDERS signalProvider = X121SMC_XWZ_PROVIDER_NONE; // // @@ -366,10 +191,7 @@ class XCX121SMCXWZSignalDetector : public XCBase symbol, period, zIndex, - visionState, - consolidationState, - analyseState, - decisionState // + provider // ); } @@ -379,17 +201,11 @@ class XCX121SMCXWZSignalDetector : public XCBase { // // Reset POI Detector Required POI(s) ... - visionCycleHelper.mPOIDetector.MaxRequiredPOIs(50); - analyseCycleHelper.mPOIDetector.MaxRequiredPOIs(50); - decisionCycleHelper.mPOIDetector.MaxRequiredPOIs(50); - consolidationCycleHelper.mPOIDetector.MaxRequiredPOIs(50); + provider.MaxRequiredPOIs(50); // // Reset POI Detector Allowed Loopback ... - visionCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(578); - analyseCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(578); - decisionCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(578); - consolidationCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(578); + provider.MaxAllowedLoopbackForInit(578); // // Check Working Zone Overal Direction ... @@ -399,14 +215,7 @@ class XCX121SMCXWZSignalDetector : public XCBase // hasWaitingZones = workingZone.DetectZone( drawer, - // - consolidationPoiEvents, - analysePoiEvents, - consolidationPoiEvents, - // - consolidationState, - analyseState, - consolidationState // + provider // ); if (hasWaitingZones) { @@ -435,34 +244,7 @@ class XCX121SMCXWZSignalDetector : public XCBase // // Cleanup Resources ... - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(consolidationPoiEvents); - - // - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionState.Clean(); - consolidationState.Clean(); - - // - visionConditions.Clean(); - analyseConditions.Clean(); - decisionConditions.Clean(); - consolidationConditions.Clean(); - - // - visionXConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationXConditions.Clean(); + provider.Clean(); // mConditions.Clean(); @@ -478,9 +260,9 @@ class XCX121SMCXWZSignalDetector : public XCBase hasSignalBox = hasWorkingZone && hasWaitingZones && - workingZone.IsZoneValidForSignal( + workingZone.IsZoneActivated( activatedZone, - decisionXConditions, + provider, zIndex // ); if (hasSignalBox) @@ -493,7 +275,7 @@ class XCX121SMCXWZSignalDetector : public XCBase // signalBox.to = cTime; signalBoxDir = signalBox.dir; - provider = X121SMC_XWZ_PROVIDER_ACTIVATED_ZONE; + signalProvider = X121SMC_XWZ_PROVIDER_ACTIVATED_ZONE; // int idx = FindIndex( @@ -950,7 +732,7 @@ class XCX121SMCXWZSignalDetector : public XCBase mConditions.setupTime = cTime; mConditions.dir = signalBoxDir; mConditions.priority = priority; - mConditions.provider = provider; + mConditions.provider = signalProvider; mConditions.signalBox = signalBox; mConditions.amountPercent = amountPercent; } @@ -993,34 +775,7 @@ class XCX121SMCXWZSignalDetector : public XCBase Clean(targets); // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(consolidationPoiEvents); - - // - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionState.Clean(); - consolidationState.Clean(); - - // - visionConditions.Clean(); - analyseConditions.Clean(); - decisionConditions.Clean(); - consolidationConditions.Clean(); - - // - visionXConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationXConditions.Clean(); + provider.Clean(); // signalBox.Clean(); @@ -1037,10 +792,7 @@ class XCX121SMCXWZSignalDetector : public XCBase // X121SMCStrategyXWZSignalConditions &conditions, // - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, + X121SMCStrategySignalProviderData &provider, // int maxAllowedSetupAge = 60 // @@ -1052,10 +804,7 @@ class XCX121SMCXWZSignalDetector : public XCBase // result = // - visionCycleHelper != NULL && - analyseCycleHelper != NULL && - decisionCycleHelper != NULL && - consolidationCycleHelper != NULL + provider.IsValid() // ; if (!result) @@ -1095,77 +844,17 @@ class XCX121SMCXWZSignalDetector : public XCBase // // Cycles Conditions ... - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, + result = provider.Prepare( zIndex, loopback // ); if (!result) { - // - // Cleanup ... - - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionConditions.Clean(); - - // return result; } // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - // - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - - // - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - - // - analyseConditions.Clean(); - decisionConditions.Clean(); - - // - return result; - } - - // - // Cycles POI States ... - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - - // - // Cycle X121Conditions ... - X121Conditions decisionXConditions = decisionConditions.x121Conditions; - X121Conditions analyseXConditions = analyseConditions.x121Conditions; - - // - double iAtr = decisionXConditions.atrBuffer[1]; + double iAtr = provider.decisionXConditions.atrBuffer[1]; iAtr *= 1.5; // @@ -1193,22 +882,7 @@ class XCX121SMCXWZSignalDetector : public XCBase // Cleanup ... // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionState.Clean(); - decisionConditions.Clean(); - decisionXConditions.Clean(); - - // - Clean(analysePoiEvents); - Clean(analyseCycleEvents); - - // - analyseState.Clean(); - analyseConditions.Clean(); - analyseXConditions.Clean(); + provider.Clean(); // return result; @@ -1221,10 +895,7 @@ class XCX121SMCXWZSignalDetector : public XCBase X121SMCGuard &guards[], const XPosition &positions[], // - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper + X121SMCStrategySignalProviderData &provider // ) { @@ -1238,20 +909,36 @@ class XCX121SMCXWZSignalDetector : public XCBase // bool isCycleHelpersValid = // - visionCycleHelper != NULL && - analyseCycleHelper != NULL && - decisionCycleHelper != NULL && - consolidationCycleHelper != NULL + provider.IsValid() // ; // // Set Provider for Common Guards ... - string provider = ToString(X_121_SMC_PROVIDER_XWZ); + string signalProvider = ToString(X_121_SMC_PROVIDER_XWZ); + + // + int zIndex = 0; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + int loopback = 10; + + // + double ask = GetAsk(symbol); + double bid = GetBid(symbol); + datetime cTime = TimeCurrent(); + double points = GetPoints(symbol); // // Check Cycle Helpers Validation ... - result = isCycleHelpersValid; + result = isCycleHelpersValid && + provider.Prepare( + zIndex, + loopback // + ); if (!result) { return result; @@ -1277,7 +964,7 @@ class XCX121SMCXWZSignalDetector : public XCBase bool isOwn = iPosition .IsFiltersPassed( symbol, - provider, + signalProvider, NULL, X_POSITION_TYPE_ALL, iPosition.magic // @@ -1351,13 +1038,10 @@ class XCX121SMCXWZSignalDetector : public XCBase X_121_SMC_GUARD_ACTION_TRAIL_STOP // }; result = DetectX121SMCGuards( - provider, + signalProvider, guards, positions, - decisionCycleHelper, - analyseCycleHelper, - consolidationCycleHelper, - visionCycleHelper, + provider, // ignoreGuards // @@ -1374,191 +1058,6 @@ class XCX121SMCXWZSignalDetector : public XCBase // 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; - - // - 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) - { - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionConditions.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) - { - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionConditions.Clean(); - - // - Clean(analysePoiEvents); - Clean(analyseCycleEvents); - - // - analyseConditions.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) - { - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionConditions.Clean(); - - // - Clean(analysePoiEvents); - Clean(analyseCycleEvents); - - // - analyseConditions.Clean(); - - // - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - consolidationConditions.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) - { - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionConditions.Clean(); - - // - Clean(analysePoiEvents); - Clean(analyseCycleEvents); - - // - analyseConditions.Clean(); - - // - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - consolidationConditions.Clean(); - - // - Clean(visionPoiEvents); - Clean(visionCycleEvents); - - // - visionConditions.Clean(); - - // - result = HasChild(guards); - return result; - } - - // - // Cycles POI States ... - XPOIState visionState = visionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState consolidationState = consolidationConditions.state; - - // - // Cycle X121Conditions ... - X121Conditions visionXConditions = visionConditions.x121Conditions; - X121Conditions analyseXConditions = analyseConditions.x121Conditions; - X121Conditions decisionXConditions = decisionConditions.x121Conditions; - X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; - - // - // - // - // // Selected Consolidation Zones ... @@ -1569,30 +1068,30 @@ class XCX121SMCXWZSignalDetector : public XCBase // bool hasBullishConsolidationZone = false; XConsolidationZone bullishConsolidationZone; - has = decisionState.HasBullishConsolidationZones(); + has = provider.decisionState.HasBullishConsolidationZones(); if (has) { // - idx = GetYoungest(decisionState.bullishConsolidationZones); + idx = GetYoungest(provider.decisionState.bullishConsolidationZones); hasBullishConsolidationZone = IsValidIndex(idx); if (hasBullishConsolidationZone) { - bullishConsolidationZone = decisionState.bullishConsolidationZones[idx]; + bullishConsolidationZone = provider.decisionState.bullishConsolidationZones[idx]; } } // bool hasBearishConsolidationZone = false; XConsolidationZone bearishConsolidationZone; - has = decisionState.HasBearishConsolidationZones(); + has = provider.decisionState.HasBearishConsolidationZones(); if (has) { // - idx = GetYoungest(decisionState.bearishConsolidationZones); + idx = GetYoungest(provider.decisionState.bearishConsolidationZones); hasBearishConsolidationZone = IsValidIndex(idx); if (hasBearishConsolidationZone) { - bearishConsolidationZone = decisionState.bearishConsolidationZones[idx]; + bearishConsolidationZone = provider.decisionState.bearishConsolidationZones[idx]; } } @@ -1709,7 +1208,7 @@ class XCX121SMCXWZSignalDetector : public XCBase // iGuard.time = cTime; iGuard.symbol = symbol; - iGuard.provider = provider; + iGuard.provider = signalProvider; iGuard.action = X_121_SMC_GUARD_ACTION_TRAIL_STOP; // @@ -1738,39 +1237,7 @@ class XCX121SMCXWZSignalDetector : public XCBase // Cleanup Collections ... // - Clean(ownPositions); - Clean(ownLongPositions); - Clean(ownShortPositions); - - // - visionState.Clean(); - analyseState.Clean(); - decisionState.Clean(); - consolidationState.Clean(); - - // - visionConditions.Clean(); - analyseConditions.Clean(); - decisionConditions.Clean(); - consolidationConditions.Clean(); - - // - visionXConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationXConditions.Clean(); - - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(consolidationPoiEvents); - - // - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationCycleEvents); + provider.Clean(); // count = ArraySize(guards); diff --git a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 index 021d6ea7..0b65f1c0 100644 --- a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 @@ -139,10 +139,7 @@ struct X121SMCStrategyXWZWorkingZone string _symbol, ENUM_TIMEFRAMES _period, int barIndex, - XPOIState &htfState, - XPOIState &mtfState, - XPOIState &stfState, // - XPOIState &ttfState // + X121SMCStrategySignalProviderData &provider // ) { // @@ -160,15 +157,7 @@ struct X121SMCStrategyXWZWorkingZone IsValid(_symbol) && IsValid(_period) && // - htfState.IsValid() && - mtfState.IsValid() && - stfState.IsValid() && - ttfState.IsValid() && - // - htfState.HasChild() && - mtfState.HasChild() && - stfState.HasChild() && - ttfState.HasChild() + provider.IsValid() // ; if (!result) @@ -208,12 +197,17 @@ struct X121SMCStrategyXWZWorkingZone if (!has) { // - idx = GetHighest(mtfState.supplyZones); + idx = GetHighest(provider + .consolidationState + .supplyZones // + ); has = IsValidIndex(idx); if (has) { // - supplyZone = mtfState.supplyZones[idx]; + supplyZone = provider + .consolidationState + .supplyZones[idx]; has = hh5 < supplyZone.Lower(); if (!has) { @@ -228,12 +222,17 @@ struct X121SMCStrategyXWZWorkingZone if (!has) { // - idx = GetLowest(mtfState.demandZones); + idx = GetLowest(provider + .consolidationState + .demandZones // + ); has = IsValidIndex(idx); if (has) { // - demandZone = mtfState.demandZones[idx]; + demandZone = provider + .consolidationState + .demandZones[idx]; has = ll5 > demandZone.Upper(); if (!has) { @@ -275,12 +274,7 @@ struct X121SMCStrategyXWZWorkingZone // bool DetectZone( XCPOIDrawer *drawer, - ENUM_XPOI_EVENTS &obPOIEvents[], - ENUM_XPOI_EVENTS &fvgPOIEvents[], - ENUM_XPOI_EVENTS &supDemPOIEvents[], - XPOIState &obState, - XPOIState &fvgState, - XPOIState &supDemState // + X121SMCStrategySignalProviderData &provider // ) { // @@ -288,13 +282,7 @@ struct X121SMCStrategyXWZWorkingZone // result = IsValid() && - obState.IsValid() && - fvgState.IsValid() && - supDemState.IsValid() && - obState.HasOrderBlocks() && - fvgState.HasFairValueGaps() && - supDemState.HasSupplyZones() && - supDemState.HasDemandZones(); + provider.IsValid(); if (!result) { return result; @@ -323,17 +311,22 @@ struct X121SMCStrategyXWZWorkingZone bool hasNewSupply = Contains( X_SUPPLY_ZONE_DETECTED, - supDemPOIEvents // + provider.consolidationPoiEvents // ); if (hasNewSupply) { // - idx = GetYoungest(supDemState.supplyZones); + idx = GetYoungest(provider + .consolidationState + .supplyZones // + ); has = IsValidIndex(idx); if (has) { // - supply = supDemState.supplyZones[idx]; + supply = provider + .consolidationState + .supplyZones[idx]; has = ToBox( supplyBox, supply // @@ -353,17 +346,23 @@ struct X121SMCStrategyXWZWorkingZone bool hasNewDemand = Contains( X_DEMAND_ZONE_DETECTED, - supDemPOIEvents // + provider + .consolidationPoiEvents // ); if (hasNewDemand) { // - idx = GetYoungest(supDemState.demandZones); + idx = GetYoungest(provider + .consolidationState + .demandZones // + ); has = IsValidIndex(idx); if (has) { // - demand = supDemState.demandZones[idx]; + demand = provider + .consolidationState + .demandZones[idx]; has = ToBox( demandBox, demand // @@ -383,21 +382,28 @@ struct X121SMCStrategyXWZWorkingZone bool hasNewFairValueGap = Contains( X_BULLISH_FVG_DETECTED, - fvgPOIEvents // + provider + .analysePoiEvents // ) || Contains( X_BEARISH_FVG_DETECTED, - fvgPOIEvents // + provider + .analysePoiEvents // ); if (hasNewFairValueGap) { // - idx = GetYoungest(fvgState.fairValueGaps); + idx = GetYoungest(provider + .analyseState + .fairValueGaps // + ); has = IsValidIndex(idx); if (has) { // - fvg = fvgState.fairValueGaps[idx]; + fvg = provider + .analyseState + .fairValueGaps[idx]; has = ToBox( fvgBox, fvg // @@ -417,21 +423,28 @@ struct X121SMCStrategyXWZWorkingZone bool hasNewOrderBlock = Contains( X_BULLISH_ORDERBLOCK_DETECTED, - obPOIEvents // + provider + .consolidationPoiEvents // ) || Contains( X_BEARISH_ORDERBLOCK_DETECTED, - obPOIEvents // + provider + .consolidationPoiEvents // ); if (hasNewOrderBlock) { // - idx = GetYoungest(obState.orderBlocks); + idx = GetYoungest(provider + .consolidationState + .orderBlocks // + ); has = IsValidIndex(idx); if (has) { // - ob = obState.orderBlocks[idx]; + ob = provider + .consolidationState + .orderBlocks[idx]; has = ToBox( obBox, ob // @@ -683,226 +696,9 @@ struct X121SMCStrategyXWZWorkingZone } // - bool IsZoneRejected( + bool IsZoneActivated( XOBFVG &zone, - int barIndex = 0 // - ) - { - // - bool result = false; - - // - // Cleanup Result ... - zone.Clean(); - - // - // Normalize Bar Index ... - if (barIndex < 0) - { - barIndex = 0; - } - - // - // Validate ... - result = IsValid() && - HasWaitingZones(); - if (!result) - { - return result; - } - - // - // Detecting Rejected Waiting Zone ... - int count = CountWaitingZones(); - for (int i = 0; i < count; i++) - { - // - // Detecting XBoxZone Area of Waiting Zone ... - XBoxZone iBox; - bool hasBox = waitingZones[i] - .ToZone(iBox); - if (hasBox) - { - // - // Check Zone Rejection ... - int fromIDX = iBarShift( - iBox.symbol, - period, - iBox.from // - ); - bool has = IsValidIndex(fromIDX); - if (has) - { - // - // Looking for Rejection ... - bool isBullish = iBox.IsBullish(); - for (int j = barIndex; j < fromIDX; j++) - { - // - XOHCL iBar; - has = iBar.Init( - iBox.symbol, - period, - j // - ); - if (has) - { - // - // Checking Box Rejected ... - - // - bool isLowerReject = - // - isBullish && - (iBar.low < iBox.upper && - iBar.GetDown() > iBox.upper) - // - ; - - // - bool isUpperReject = - // - !isBullish && - (iBar.high > iBox.lower && - iBar.GetUp() < iBox.lower) - // - ; - - // - bool isRejected = - isLowerReject || - isUpperReject; - result = isRejected; - if (result) - { - // - iBar.Clean(); - break; - } - } - - // - iBar.Clean(); - } - } - } - - // - // Validate Result ... - if (result) - { - // - iBox.Clean(); - zone = waitingZones[i]; - break; - } - - // - iBox.Clean(); - } - - // - return result; - } - - // - // TODO: Remove this ... - bool IsZoneOBRejected( - XOBFVG &zone, - X121Conditions &conditions, - int barIndex = 0 // - ) - { - // - bool result = false; - - // - // Cleanup Result ... - zone.Clean(); - - // - // Normalize Bar Index ... - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (barIndex == 0) - { - barIndex = 1; - } - - // - XOHCL bar; - bool isInited = bar.Init( - symbol, - period, - barIndex // - ); - - // - // Validate ... - result = isInited && - IsValid() && - HasWaitingZones(); - if (!result) - { - return result; - } - - // - double points = GetPoints(bar.symbol); - - // - // Detecting Rejected Waiting Zone ... - int count = CountWaitingZones(); - for (int i = 0; i < count; i++) - { - // - // Detecting XBoxZone Area of Waiting Zone ... - XBoxZone iBox; - bool hasBox = waitingZones[i] - .ToZone(iBox); - if (hasBox) - { - // - double peak = conditions.peaksBuffer[1]; - double lower = waitingZones[i].ob.Lower(); - - // - double delta = MathAbs(lower - peak); - - // - result = delta == 0 || - delta < points * 2; - } - - // - // Validate Result ... - if (result) - { - // - iBox.Clean(); - zone = waitingZones[i]; - break; - } - - // - iBox.Clean(); - } - - // - bar.Clean(); - - // - return result; - } - - // - bool IsZoneValidForSignal( - XOBFVG &zone, - X121Conditions &conditions, + X121SMCStrategySignalProviderData &provider, int barIndex = 0 // ) { @@ -953,8 +749,8 @@ struct X121SMCStrategyXWZWorkingZone } // - double peak = conditions.peaksBuffer[1]; - double vale = conditions.valesBuffer[1]; + double peak = provider.decisionXConditions.peaksBuffer[1]; + double vale = provider.decisionXConditions.valesBuffer[1]; // int count = CountWaitingZones(); diff --git a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 index c028f6f1..effe5ef8 100644 --- a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 @@ -43,6 +43,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // Props ... bool useXWZSignal; XCX121SMCXWZSignalDetector *mXWZSignalDetector; + X121SMCStrategySignalProviderData cycleProvider; // // Constructor(s) ... @@ -117,6 +118,9 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // ZeroMemory(mXWZSignalDetector); + + // + cycleProvider.Destroy(); } /** @@ -417,10 +421,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy bool hasGuard = mXWZSignalDetector.DetectGuards( xwzGuards, positions, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // + cycleProvider // ); // @@ -540,10 +541,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // // Detect Signal Setup ... isSetuped = mXWZSignalDetector.DetectSignalSetup( - mDecisionCycleHelper, - mAnalyseCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // + cycleProvider // ); // @@ -592,10 +590,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy canTrigger = mXWZSignalDetector .DetectSignalTrigger( mTmpConditions[i], - mDecisionCycleHelper, - mAnalyseCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // + cycleProvider // ); // @@ -1051,6 +1046,15 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy mVisionCycleHelper.mPOIDrawer.BullishFVGColor(bullishColor); mVisionCycleHelper.mPOIDrawer.BearishFVGColor(bearishColor); } + + // + // Initial Cycle Provider ... + cycleProvider.Init( + mDecisionCycleHelper, + mAnalyseCycleHelper, + mConsolidationCycleHelper, + mVisionCycleHelper // + ); } //