From 6a3fb91e9cac787643ad5187267c8a1286a506b9 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Mon, 3 Mar 2025 02:29:55 +0330 Subject: [PATCH] last ... --- Documents/BKP/1.mq5 | 6436 +++++++++++++++++ {Experts => Documents/BKP}/Test.mq5 | 0 .../BKP/x-121.smc.xwz.signal.class copy.mq5 | 2124 ++++++ .../BKP/x-121.smc.xwz.signal.lib copy.mq5 | 4871 +++++++++++++ Indicators/x-saherelm.x121.xwz.mq5 | 102 +- Libraries/x-saherelm.common.lib.mq5 | 34 + Libraries/x-saherelm.x-poi.extensions.lib.mq5 | 59 + .../Signals/x-121.smc.xwz.signal.class.mq5 | 876 +-- .../Signals/x-121.smc.xwz.signal.lib.mq5 | 4582 ++---------- .../Strategy/x-121.smc.strategy.class.mq5 | 2 +- 10 files changed, 14692 insertions(+), 4394 deletions(-) rename {Experts => Documents/BKP}/Test.mq5 (100%) create mode 100644 Documents/BKP/x-121.smc.xwz.signal.class copy.mq5 create mode 100644 Documents/BKP/x-121.smc.xwz.signal.lib copy.mq5 diff --git a/Documents/BKP/1.mq5 b/Documents/BKP/1.mq5 index 90eefe41..66a5551e 100644 --- a/Documents/BKP/1.mq5 +++ b/Documents/BKP/1.mq5 @@ -1427,3 +1427,6439 @@ if (isPassed) // bool isStrongSwingHigh = // pBar.IsBearish() && // pBar.GetHighShadow() >= pBar.GetBody() * 2; + + +/////////////////////////////////////////////////////////////////////////////// + +// +// +// + +bool DetectX121Conditions( + double &pivot, + double &point, + double &sls[], + double &targets[], + ENUM_X_DIRECTION &dir, + XPOIState &stfState, + XPOIState &ttfState, + X121Conditions &conditions, + XCPOIDrawer *drawer = NULL // +) +{ + // + bool result = false; + + // + bool canDraw = drawer != NULL; + + // + pivot = 0; + point = 0; + Clean(sls); + Clean(targets); + dir = X_DIRECTION_NONE; + + // + result = + stfState.IsValid() && + ttfState.IsValid() && + stfState.HasChild() && + ttfState.HasChild(); + if (!result) + { + return result; + } + + // + int idx = -1; + int count = 0; + bool has = false; + + // + // Detect Inside STF Order Blocks Zones ... + + // + XOBFVG tmpWaitingZones[]; + count = ExtractOBFVGs( + tmpWaitingZones, + stfState, + ttfState // + ); + has = IsValidSize(count); + if (has) + { + // + if (canDraw) + { + // + for (int i = 0; i < count; i++) + { + // + XOBFVG iOBFVG = tmpWaitingZones[i]; + + // + iOBFVG.UpdateTo(); + + // + XCBaseObject *iOBFVGObjects[]; + int iOBFVGObjectsCount = drawer.DrawOBFVG( + iOBFVG, + iOBFVGObjects // + ); + } + } + } + + // + + // + return result; +} + + +////////////////////////////////////////////////////////////////////////// + + +/** + * Check an XOBFVG instance has Required Conditions ... + * + * @param zone: XBoxZone instance ... + * @param state: XPOIState instance ... + * @param conditions: X121Conditions instance ... + * + * @return ( bool ) + */ +bool DetectSelectedBoxConditions( + bool &isReversal, + XBoxZone &zone, + XPOIState &state, + X121Conditions &conditions // +) +{ + // + bool result = false; + + // + isReversal = false; + + // + result = + zone.IsValid() && + state.IsValid() && + state.HasChild(); + if (!result) + { + return result; + } + + // + bool isBullish = zone.IsBullish(); + bool isBearish = zone.IsBearish(); + + // + bool isBullishTrend = conditions.isTrendBullish || + conditions.isTrendSwitchedToBullish; + bool isBearishTrend = conditions.isTrendBearish || + conditions.isTrendSwitchedToBearish; + + // + double bullishScore = 0; + double bearishScore = 0; + double scoreMultiplier = 1.5; + conditions.GenerateScore( + bullishScore, + bearishScore // + ); + + // + bool isBullishScorePassed = bullishScore > 0 && + bearishScore >= 0 && + bullishScore > bearishScore * scoreMultiplier; + + // + bool isBearishScorePassed = bearishScore > 0 && + bullishScore >= 0 && + bearishScore > bullishScore * scoreMultiplier; + + // + // VWap ... + + // + double vwapFast = conditions.vwapFastBuffer[0]; + double vwapMid = conditions.vwapMidBuffer[0]; + double vwapSlow = conditions.vwapSlowBuffer[0]; + + // + bool isVWapInside = + // + vwapFast > zone.lower && + vwapFast < zone.upper + // + && + vwapMid > zone.lower && + vwapMid < zone.upper + // + ; + + // + bool isVWapBullish = + // + (conditions.isVWapBullishState && + conditions.isVWapSwitchedToBullishOrdered) + // + || + // + (conditions.isVWapBullishOrdered && + conditions.isVWapSwitchedToBullishState) + // + ; + + // + bool isVWapBearish = + // + (conditions.isVWapBearishState && + conditions.isVWapSwitchedToBearishOrdered) + // + || + // + (conditions.isVWapBearishOrdered && + conditions.isVWapSwitchedToBearishState) + // + ; + + // + // X3Ma ... + + // + double x3maFast = conditions.x3maFastBuffer[0]; + double x3maMid = conditions.x3maMidBuffer[0]; + double x3maSlow = conditions.x3maSlowBuffer[0]; + + // + bool isX3MaInside = + // + x3maFast > zone.lower && + x3maFast < zone.upper + // + && + x3maMid > zone.lower && + x3maMid < zone.upper + // + ; + + // + bool isX3MaBullish = + // + (conditions.isX3MaBullishState && + conditions.isX3MaSwitchedToBullishOrdered) + // + || + // + (conditions.isX3MaBullishOrdered && + conditions.isX3MaSwitchedToBullishState) + // + ; + + // + bool isX3MaBearish = + // + (conditions.isX3MaBearishState && + conditions.isX3MaSwitchedToBearishOrdered) + // + || + // + (conditions.isX3MaBearishOrdered && + conditions.isX3MaSwitchedToBearishState) + // + ; + + // + // + // + + // + bool isInside = + // + isVWapInside || + isX3MaInside + // + ; + + // + bool isVWap3MaBullish = + isVWapBullish || + isX3MaBullish; + + // + bool isVWap3MaBearish = + isVWapBearish || + isX3MaBearish; + + // + // + // + + // + bool isDirectionalBullishPassed = + // + isInside && + isBullish && + isBullishTrend && + isVWap3MaBullish && + isBullishScorePassed + // + ; + + // + bool isDirectionalBearishPassed = + // + isInside && + isBearish && + isBearishTrend && + isVWap3MaBearish && + isBearishScorePassed + // + ; + + // + bool isDirectionalPassed = + isDirectionalBullishPassed || + isDirectionalBearishPassed; + + // + bool isReversalBullishPassed = + // + isInside && + isBullish && + isBearishTrend && + isVWap3MaBearish && + isBearishScorePassed + // + ; + + // + bool isReversalBearishPassed = + // + isInside && + isBearish && + isBullishTrend && + isVWap3MaBullish && + isBullishScorePassed + // + ; + + // + bool isReversalPassed = isReversalBullishPassed || + isReversalBearishPassed; + + // + result = isReversalPassed || + isDirectionalPassed; + + // + if (result) + { + isReversal = isReversalPassed; + } + + // + return result; +} + +/////////////////////////////////////////////////////////////////////////////// + + + // if (hasWaitingZones) + // { + // // + // int idx = -1; + // int count = 0; + // XOBFVG youngest; + // bool has = false; + // XCFVG *selectedFVG; + // XCFVG *unActivatedFVGs[]; + + // // + // idx = GetYoungest(workingZone.waitingZones); + // has = IsValidIndex(idx); + // if (has) + // { + // // + // youngest = workingZone.waitingZones[idx]; + // selectedZoneDir = youngest.GetDirection(); + + // // + // if (IsBullish(selectedZoneDir)) + // { + // // + // Copy( + // analyseState.bullishFairValueGaps, + // unActivatedFVGs // + // ); + // } + // else + // { + // // + // Copy( + // analyseState.bearishFairValueGaps, + // unActivatedFVGs // + // ); + // } + // } + + // // + // count = ArraySize(unActivatedFVGs); + // has = IsValidSize(count); + // if (has) + // { + // // + // idx = GetYoungest(unActivatedFVGs); + // has = IsValidIndex(idx); + // if (has) + // { + // selectedFVG = unActivatedFVGs[idx]; + // } + // } + + // // + // has = selectedFVG != NULL; + // if (has) + // { + // // + // XCBaseObject *iObj; + // bool isCreated = drawer.CreateFairValueGap( + // selectedFVG, + // iObj // + // ); + + // // + // if (isCreated) + // { + // Print("Salam"); + // } + // } + // } + + +////////////////////////////////////////////////////////////////////////////////////////// + + +/** + * Check an XOBFVG instance has Required Conditions ... + * + * @param zone: XOBFVG instance ... + * @param state: XPOIState instance ... + * @param conditions: X121Conditions instance ... + * + * @return ( bool ) + */ +bool DetectInsideSelectedZoneConditions( + bool &isReversal, + XOBFVG &zone, + XPOIState &state, + X121Conditions &conditions // +) +{ + // + bool result = false; + + // + isReversal = false; + + // + result = + zone.IsValid() && + state.IsValid() && + state.HasChild(); + if (!result) + { + return result; + } + + // + bool isBullish = zone.IsBullish(); + bool isBearish = zone.IsBearish(); + + // + bool isBullishTrend = conditions.isTrendBullish || + conditions.isTrendSwitchedToBullish; + bool isBearishTrend = conditions.isTrendBearish || + conditions.isTrendSwitchedToBearish; + + // + double bullishScore = 0; + double bearishScore = 0; + double scoreMultiplier = 1.5; + conditions.GenerateScore( + bullishScore, + bearishScore // + ); + + // + bool isBullishScorePassed = bullishScore > 0 && + bearishScore >= 0 && + bullishScore > bearishScore * scoreMultiplier; + + // + bool isBearishScorePassed = bearishScore > 0 && + bullishScore >= 0 && + bearishScore > bullishScore * scoreMultiplier; + + // + // VWap ... + + // + double vwapFast = conditions.vwapFastBuffer[0]; + double vwapMid = conditions.vwapMidBuffer[0]; + double vwapSlow = conditions.vwapSlowBuffer[0]; + + // + bool isVWapInside = + // + vwapFast > zone.ob.Lower() && + vwapFast < zone.ob.Upper() + // + && + vwapMid > zone.ob.Lower() && + vwapMid < zone.ob.Upper() + // + ; + + // + bool isVWapBullish = + // + (conditions.isVWapBullishState && + conditions.isVWapSwitchedToBullishOrdered) + // + || + // + (conditions.isVWapBullishOrdered && + conditions.isVWapSwitchedToBullishState) + // + ; + + // + bool isVWapBearish = + // + (conditions.isVWapBearishState && + conditions.isVWapSwitchedToBearishOrdered) + // + || + // + (conditions.isVWapBearishOrdered && + conditions.isVWapSwitchedToBearishState) + // + ; + + // + // X3Ma ... + + // + double x3maFast = conditions.x3maFastBuffer[0]; + double x3maMid = conditions.x3maMidBuffer[0]; + double x3maSlow = conditions.x3maSlowBuffer[0]; + + // + bool isX3MaInside = + // + x3maFast > zone.ob.Lower() && + x3maFast < zone.ob.Upper() + // + && + x3maMid > zone.ob.Lower() && + x3maMid < zone.ob.Upper() + // + ; + + // + bool isX3MaBullish = + // + (conditions.isX3MaBullishState && + conditions.isX3MaSwitchedToBullishOrdered) + // + || + // + (conditions.isX3MaBullishOrdered && + conditions.isX3MaSwitchedToBullishState) + // + ; + + // + bool isX3MaBearish = + // + (conditions.isX3MaBearishState && + conditions.isX3MaSwitchedToBearishOrdered) + // + || + // + (conditions.isX3MaBearishOrdered && + conditions.isX3MaSwitchedToBearishState) + // + ; + + // + // + // + + // + bool isInside = + // + isVWapInside || + isX3MaInside + // + ; + + // + bool isVWap3MaBullish = + isVWapBullish || + isX3MaBullish; + + // + bool isVWap3MaBearish = + isVWapBearish || + isX3MaBearish; + + // + // + // + + // + bool isDirectionalBullishPassed = + // + isInside && + isBullish && + isBullishTrend && + isVWap3MaBullish && + isBullishScorePassed + // + ; + + // + bool isDirectionalBearishPassed = + // + isInside && + isBearish && + isBearishTrend && + isVWap3MaBearish && + isBearishScorePassed + // + ; + + // + bool isDirectionalPassed = + isDirectionalBullishPassed || + isDirectionalBearishPassed; + + // + bool isReversalBullishPassed = + // + isInside && + isBullish && + isBearishTrend && + isVWap3MaBearish && + isBearishScorePassed + // + ; + + // + bool isReversalBearishPassed = + // + isInside && + isBearish && + isBullishTrend && + isVWap3MaBullish && + isBullishScorePassed + // + ; + + // + bool isReversalPassed = isReversalBullishPassed || + isReversalBearishPassed; + + // + result = isReversalPassed || + isDirectionalPassed; + + // + if (result) + { + isReversal = isReversalPassed; + } + + // + return result; +} + +bool DetectBreakedSelectedZoneConditions( + bool &isReversal, + XOBFVG &zone, + XPOIState &mtfState, + XPOIState &stfState, + XPOIState &ttfState, + X121Conditions &conditions // +) +{ + // + bool result = false; + + // + isReversal = false; + + // + result = + // + zone.IsValid() && + mtfState.IsValid() && + stfState.IsValid() && + ttfState.IsValid() && + mtfState.HasChild() && + stfState.HasChild() && + ttfState.HasChild() + // + ; + if (!result) + { + return result; + } + + // + XBoxZone iBox; + result = ToBox( + iBox, + zone.ob // + ); + if (!result) + { + return result; + } + + // + ENUM_X_DIRECTION iDir = iBox.dir; + bool isBullish = IsBullish(iDir); + bool isBearish = IsBearish(iDir); + + // + // X3Ma ... + + // + double x3maFast = conditions.x3maFastBuffer[0]; + double x3maMid = conditions.x3maMidBuffer[0]; + double x3maSlow = conditions.x3maSlowBuffer[0]; + + // + bool isX3mInside = + // + (x3maFast < iBox.upper && + x3maMid < iBox.upper && + x3maSlow < iBox.upper) + // + && + // + (x3maFast > iBox.lower && + x3maMid > iBox.lower && + x3maSlow > iBox.lower) + // + ; + + // + bool isBullishConditions = + isBullish && + isX3mInside; + + // + bool isBearishConditions = + isBearish && + isX3mInside; + + // + result = isBullishConditions || + isBearishConditions; + + // + return result; +} + +/** + * Detect Targets Based on Selected Zone for Specified type of Directions ... + * + * @param targets: double Collection ... + * @param selectedZone: XOBFVG instance, selected Zone ... + * @param forDir: ENUM_X_DIRECTION specified Position Direction ... + * @param workingone: X121SMCStrategyXWZWorkingZone instance, Specified Working Zone ... + * @param barIndex: int Specified Bar Index ... + * + * @return ( bool ) + */ +bool DetectSelectedZonesTargets( + double &targets[], + XOBFVG &selectedZone, + ENUM_X_DIRECTION forDir, + ENUM_X121SMC_XWZ_PRIORITY forPriority, + X121SMCStrategyXWZWorkingZone &workingZone, + int barIndex = 0 // +) +{ + // + bool result = false; + + // + Clean(targets); + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (barIndex == 0) + { + barIndex++; + } + + // + result = + // + selectedZone.IsValid() && + HasDirection(forDir) && + workingZone.IsValid() && + forPriority != X121SMC_XWZ_PRIORITY_NONE + // + ; + if (!result) + { + return result; + } + + // + bool isBullish = IsBullish(forDir); + + // + XOHCL cBar; + result = cBar.Init( + workingZone.symbol, + workingZone.period, + barIndex // + ); + if (!result) + { + // + cBar.Clean(); + return result; + } + + // + int idx = -1; + bool has = false; + XOBFVG tmpZones[]; + + // + // Based On Waiting Zones ... + has = workingZone.HasWaitingZones(); + if (has) + { + // + Copy( + workingZone.waitingZones, + tmpZones // + ); + + // + while (HasChild(tmpZones)) + { + // + XOBFVG iOBFVG; + + // + idx = GetYoungest(tmpZones); + if (!IsValidIndex(idx)) + { + // + iOBFVG.Clean(); + break; + } + + // + iOBFVG = tmpZones[idx]; + ArrayRemove( + tmpZones, + idx, + 1 // + ); + + // + double iTarget = + isBullish + ? iOBFVG.ob.Lower() + : iOBFVG.ob.Upper(); + + // + has = + isBullish + ? cBar.high < iTarget + : cBar.low > iTarget; + + // + if (has) + { + // + Add( + iTarget, + targets // + ); + } + + // + iOBFVG.Clean(); + } + + // + Clean(tmpZones); + } + + // + // Based On Breaked Zones ... + has = workingZone.HasBreakedZones(); + if (has) + { + Copy( + workingZone.breakedZones, + tmpZones // + ); + + // + while (HasChild(tmpZones)) + { + // + XOBFVG iOBFVG; + + // + idx = GetYoungest(tmpZones); + if (!IsValidIndex(idx)) + { + // + iOBFVG.Clean(); + break; + } + + // + iOBFVG = tmpZones[idx]; + ArrayRemove( + tmpZones, + idx, + 1 // + ); + + // + double iTarget = + isBullish + ? iOBFVG.ob.Lower() + : iOBFVG.ob.Upper(); + + // + has = + isBullish + ? cBar.high < iTarget + : cBar.low > iTarget; + + // + if (has) + { + // + Add( + iTarget, + targets // + ); + } + + // + iOBFVG.Clean(); + } + + // + Clean(tmpZones); + } + + // + // Based On Priority ... + has = forPriority != X121SMC_XWZ_PRIORITY_NONE; + if (has) + { + // + switch (forPriority) + { + // + case X121SMC_XWZ_PRIORITY_WEAK: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + } + break; + + // + case X121SMC_XWZ_PRIORITY_LOW: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + } + break; + + // + case X121SMC_XWZ_PRIORITY_REGULAR: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + } + break; + + // + case X121SMC_XWZ_PRIORITY_HIGH: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter3, + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter1, + targets // + ); + } + break; + + // + case X121SMC_XWZ_PRIORITY_STRONG_HIGH: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Strong High ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Strong High ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + } + break; + } + } + + // + result = HasChild(targets); + + // + // Cleanup ... + cBar.Clean(); + Clean(tmpZones); + + // + return result; +} + +/** + * Detect Targets Based on Selected Zone for Specified type of Directions ... + * + * @param targets: double Collection ... + * @param selectedZone: XBoxZone instance, selected Zone ... + * @param forDir: ENUM_X_DIRECTION specified Position Direction ... + * @param workingone: X121SMCStrategyXWZWorkingZone instance, Specified Working Zone ... + * @param barIndex: int Specified Bar Index ... + * + * @return ( bool ) + */ +bool DetectSelectedZonesTargets( + double &targets[], + XBoxZone &selectedZone, + ENUM_X_DIRECTION forDir, + ENUM_X121SMC_XWZ_PRIORITY forPriority, + X121SMCStrategyXWZWorkingZone &workingZone, + int barIndex = 0 // +) +{ + // + bool result = false; + + // + Clean(targets); + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (barIndex == 0) + { + barIndex++; + } + + // + result = + // + selectedZone.IsValid() && + HasDirection(forDir) && + workingZone.IsValid() && + forPriority != X121SMC_XWZ_PRIORITY_NONE + // + ; + if (!result) + { + return result; + } + + // + bool isBullish = IsBullish(forDir); + + // + XOHCL cBar; + result = cBar.Init( + workingZone.symbol, + workingZone.period, + barIndex // + ); + if (!result) + { + // + cBar.Clean(); + return result; + } + + // + int idx = -1; + bool has = false; + XOBFVG tmpZones[]; + + // + // Based On Waiting Zones ... + has = workingZone.HasWaitingZones(); + if (has) + { + // + Copy( + workingZone.waitingZones, + tmpZones // + ); + + // + while (HasChild(tmpZones)) + { + // + XOBFVG iOBFVG; + + // + idx = GetYoungest(tmpZones); + if (!IsValidIndex(idx)) + { + // + iOBFVG.Clean(); + break; + } + + // + iOBFVG = tmpZones[idx]; + ArrayRemove( + tmpZones, + idx, + 1 // + ); + + // + double iTarget = + isBullish + ? iOBFVG.ob.Lower() + : iOBFVG.ob.Upper(); + + // + has = + isBullish + ? cBar.high < iTarget + : cBar.low > iTarget; + + // + if (has) + { + // + Add( + iTarget, + targets // + ); + } + + // + iOBFVG.Clean(); + } + + // + Clean(tmpZones); + } + + // + // Based On Breaked Zones ... + has = workingZone.HasBreakedZones(); + if (has) + { + Copy( + workingZone.breakedZones, + tmpZones // + ); + + // + while (HasChild(tmpZones)) + { + // + XOBFVG iOBFVG; + + // + idx = GetYoungest(tmpZones); + if (!IsValidIndex(idx)) + { + // + iOBFVG.Clean(); + break; + } + + // + iOBFVG = tmpZones[idx]; + ArrayRemove( + tmpZones, + idx, + 1 // + ); + + // + double iTarget = + isBullish + ? iOBFVG.ob.Lower() + : iOBFVG.ob.Upper(); + + // + has = + isBullish + ? cBar.high < iTarget + : cBar.low > iTarget; + + // + if (has) + { + // + Add( + iTarget, + targets // + ); + } + + // + iOBFVG.Clean(); + } + + // + Clean(tmpZones); + } + + // + // Based On Priority ... + has = forPriority != X121SMC_XWZ_PRIORITY_NONE; + if (has) + { + // + switch (forPriority) + { + // + case X121SMC_XWZ_PRIORITY_WEAK: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + } + break; + + // + case X121SMC_XWZ_PRIORITY_LOW: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + } + break; + + // + case X121SMC_XWZ_PRIORITY_REGULAR: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + } + break; + + // + case X121SMC_XWZ_PRIORITY_HIGH: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter3, + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter1, + targets // + ); + } + break; + + // + case X121SMC_XWZ_PRIORITY_STRONG_HIGH: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Strong High ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Strong High ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + } + break; + } + } + + // + result = HasChild(targets); + + // + // Cleanup ... + cBar.Clean(); + Clean(tmpZones); + + // + return result; +} + +/** + * Detect SL Candidates Based on Selected Zone for Specified type of Directions ... + * + * @param sls: double Collection ... + * @param selectedZone: XOBFVG instance, selected Zone ... + * @param forDir: ENUM_X_DIRECTION specified Position Direction ... + * @param workingZone: X121SMCStrategyXWZWorkingZone instance, Specified Working Zone ... + * @param barIndex: int Specified Bar Index ... + * @param maxAllowedSLDistanceInPoint: doube max Allowe SL distance ... + * + * @return ( bool ) + */ +bool DetectSelectedZoneSLCandidates( + double &sls[], + XOBFVG &selectedZone, + ENUM_X_DIRECTION forDir, + X121SMCStrategyXWZWorkingZone &workingZone, + X121Conditions &conditions, + int barIndex = 0, + double maxAllowedSLDistanceInPoint = 300 // +) +{ + // + bool result = false; + + // + Clean(sls); + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (barIndex == 0) + { + barIndex++; + } + + // + result = + // + selectedZone.IsValid() && + HasDirection(forDir) && + workingZone.IsValid() + // + ; + if (!result) + { + return result; + } + + // + bool isBullish = IsBullish(forDir); + + // + double pivot = + isBullish + ? selectedZone.ob.Lower() + : selectedZone.ob.Upper(); + double points = GetPoints(workingZone.symbol); + + // + XOHCL cBar; + result = cBar.Init( + workingZone.symbol, + workingZone.period, + barIndex // + ); + if (!result) + { + // + cBar.Clean(); + return result; + } + + // + int idx = -1; + bool has = false; + + // + double pvSL = isBullish + ? conditions.valesBuffer[0] + : conditions.peaksBuffer[1]; + + // + Add( + pvSL, + sls // + ); + + // + // Based On Passed Bars ... + // XOHCL passedBar; + // bool isPassed = false; + // bool isBodyState = false; + // ENUM_X_DIRECTION passedDir = selectedZone.GetDirection(); + + // // + // // Started Bar ... + // isPassed = selectedZone.ob.IsStarted( + // passedDir, + // passedBar, + // isBodyState // + // ); + // if (isPassed) + // { + // // + // double iSL = + // isBullish + // ? passedBar.low + // : passedBar.high; + // double iSLDiff = MathAbs(iSL - pivot); + // has = + // iSLDiff > 0 && + // iSLDiff <= maxAllowedSLDistanceInPoint * points; + // if (has) + // { + // // + // Add( + // iSL, + // sls // + // ); + // } + // } + + // // + // // Activation Bar ... + // passedBar.Clean(); + // isPassed = selectedZone.ob.IsActivated( + // passedDir, + // passedBar, + // isBodyState // + // ); + // if (isPassed) + // { + // // + // double iSL = + // isBullish + // ? passedBar.low + // : passedBar.high; + // double iSLDiff = MathAbs(iSL - pivot); + // has = + // iSLDiff > 0 && + // iSLDiff <= maxAllowedSLDistanceInPoint * points; + // if (has) + // { + // // + // Add( + // iSL, + // sls // + // ); + // } + // } + + // // + // // Worked Bar ... + // passedBar.Clean(); + // isPassed = selectedZone.ob.IsActivated( + // passedDir, + // passedBar, + // isBodyState // + // ); + // if (isPassed) + // { + // // + // double iSL = + // isBullish + // ? passedBar.low + // : passedBar.high; + // double iSLDiff = MathAbs(iSL - pivot); + // has = + // iSLDiff > 0 && + // iSLDiff <= maxAllowedSLDistanceInPoint * points; + // if (has) + // { + // // + // Add( + // iSL, + // sls // + // ); + // } + // } + + // // + // // Breaked Bar ... + // passedBar.Clean(); + // isPassed = selectedZone.ob.IsActivated( + // passedDir, + // passedBar, + // isBodyState // + // ); + // if (isPassed) + // { + // // + // double iSL = + // isBullish + // ? passedBar.low + // : passedBar.high; + // double iSLDiff = MathAbs(iSL - pivot); + // has = + // iSLDiff > 0 && + // iSLDiff <= maxAllowedSLDistanceInPoint * points; + // if (has) + // { + // // + // Add( + // iSL, + // sls // + // ); + // } + // } + + // + // Based On Consolidation Zones ... + has = workingZone.HasConsolidationZones(); + if (has) + { + // + XConsolidationZone tmpZones[]; + Copy( + workingZone.consolidationZones, + tmpZones // + ); + XConsolidationZone selectedConsolidationZone; + + // + while (HasChild(tmpZones)) + { + // + idx = GetYoungest(tmpZones); + if (!IsValidIndex(idx)) + { + break; + } + + // + XConsolidationZone iZone = tmpZones[idx]; + + // + ArrayRemove( + tmpZones, + idx, + 1 // + ); + + // + has = + !selectedConsolidationZone.IsValid() + ? isBullish + ? cBar.low < iZone.upper + : cBar.high < iZone.lower + : isBullish + ? selectedConsolidationZone.lower < iZone.lower + : selectedConsolidationZone.upper > iZone.upper; + if (has) + { + // + selectedConsolidationZone = iZone; + iZone.Clean(); + break; + } + + // + iZone.Clean(); + } + + // + Clean(tmpZones); + has = selectedConsolidationZone.IsValid(); + if (has) + { + // + double iSL = + isBullish + ? selectedConsolidationZone.lower + : selectedConsolidationZone.upper; + double iSLDiff = MathAbs(iSL - pivot); + has = + iSLDiff > 0 && + iSLDiff <= maxAllowedSLDistanceInPoint * points; + if (has) + { + // + Add( + iSL, + sls // + ); + } + } + } + + // + // Based On Supply and Demand Zones ... + + // + // Demand Zones ... + has = workingZone.HasDemandZones(); + if (has) + { + // + XCDemandZone *tmpZones[]; + Copy( + workingZone.demandZones, + tmpZones // + ); + XCDemandZone *selectedDemand = NULL; + + // + while (HasChild(tmpZones)) + { + // + idx = GetLowest(tmpZones); + has = IsValidIndex(idx); + if (!has) + { + break; + } + + // + XCDemandZone *iZone = tmpZones[idx]; + ArrayRemove( + tmpZones, + idx, + 1 // + ); + + // + // Validate Zone ... + has = + isBullish + ? IsBelowDiff( + iZone, + selectedZone.ob, + true // Ignore Inside ... + ) + : IsAboveDiff( + iZone, + selectedZone.ob, + true // Ignore Inside ... + ); + if (!has) + { + continue; + } + + // + has = + selectedDemand == NULL + ? true + : isBullish + ? selectedDemand.Lower() < iZone.Lower() + : selectedDemand.Upper() > iZone.Upper(); + if (!has) + { + continue; + } + + // + selectedDemand = iZone; + } + + // + has = selectedDemand != NULL; + if (has) + { + // + double iSL = + isBullish + ? selectedDemand.Lower() + : selectedDemand.Upper(); + double iSLDiff = MathAbs(iSL - pivot); + has = + iSLDiff > 0 && + iSLDiff <= maxAllowedSLDistanceInPoint * points; + if (has) + { + // + Add( + iSL, + sls // + ); + } + } + + // + Clean(tmpZones); + ZeroMemory(selectedDemand); + } + + // + // Support Zones ... + // has = workingZone.HasSupportZones(); + // if (has) + // { + // // + // XCSupportZone *tmpZones[]; + // Copy( + // workingZone.supportZones, + // tmpZones // + // ); + // XCSupportZone *selectedSupport = NULL; + + // // + // while (HasChild(tmpZones)) + // { + // // + // idx = GetLowest(tmpZones); + // has = IsValidIndex(idx); + // if (!has) + // { + // break; + // } + + // // + // XCSupportZone *iZone = tmpZones[idx]; + // ArrayRemove( + // tmpZones, + // idx, + // 1 // + // ); + + // // + // // Validate Zone ... + // has = + // isBullish + // ? IsBelowDiff( + // iZone, + // selectedZone.ob, + // true // Ignore Inside ... + // ) + // : IsAboveDiff( + // iZone, + // selectedZone.ob, + // true // Ignore Inside ... + // ); + // if (!has) + // { + // continue; + // } + + // // + // has = + // selectedSupport == NULL + // ? true + // : isBullish + // ? selectedSupport.Lower() < iZone.Lower() + // : selectedSupport.Upper() > iZone.Upper(); + // if (!has) + // { + // continue; + // } + + // // + // selectedSupport = iZone; + + // // + // } + + // // + // has = selectedSupport != NULL; + // if (has) + // { + // // + // double iSL = isBullish + // ? selectedSupport.Lower() + // : selectedSupport.Upper(); + // double iSLDiff = MathAbs(iSL - pivot); + // has = + // iSLDiff > 0 && + // iSLDiff <= maxAllowedSLDistanceInPoint * points; + // if (has) + // { + // // + // Add( + // iSL, + // sls // + // ); + // } + // } + + // // + // Clean(tmpZones); + // ZeroMemory(selectedSupport); + // } + + // + // Supply Zones ... + has = workingZone.HasSupplyZones(); + if (has) + { + // + XCSupplyZone *tmpZones[]; + Copy( + workingZone.supplyZones, + tmpZones // + ); + XCSupplyZone *selectedSupply = NULL; + + // + while (HasChild(tmpZones)) + { + // + idx = GetHighest(tmpZones); + has = IsValidIndex(idx); + if (!has) + { + break; + } + + // + XCSupplyZone *iZone = tmpZones[idx]; + ArrayRemove( + tmpZones, + idx, + 1 // + ); + + // + // Validate Zone ... + has = + !isBullish + ? IsAboveDiff( + iZone, + selectedZone.ob, + true // Ignore Inside ... + ) + : IsBelowDiff( + iZone, + selectedZone.ob, + true // Ignore Inside ... + ); + if (!has) + { + continue; + } + + // + has = + selectedSupply == NULL + ? true + : !isBullish + ? selectedSupply.Upper() > iZone.Upper() + : selectedSupply.Lower() < iZone.Lower(); + if (!has) + { + continue; + } + + // + selectedSupply = iZone; + + // + } + + // + has = selectedSupply != NULL; + if (has) + { + // + double iSL = + !isBullish + ? selectedSupply.Upper() + : selectedSupply.Lower(); + double iSLDiff = MathAbs(iSL - pivot); + has = + iSLDiff > 0 && + iSLDiff <= maxAllowedSLDistanceInPoint * points; + if (has) + { + // + Add( + iSL, + sls // + ); + } + } + + // + Clean(tmpZones); + ZeroMemory(selectedSupply); + } + + // + // Resistance Zones ... + // has = workingZone.HasDemandZones(); + // if (has) + // { + // // + // XCResistanceZone *tmpZones[]; + // Copy( + // workingZone.resistanceZones, + // tmpZones // + // ); + // XCResistanceZone *selectedResistance = NULL; + + // // + // while (HasChild(tmpZones)) + // { + // // + // idx = GetHighest(tmpZones); + // has = IsValidIndex(idx); + // if (!has) + // { + // break; + // } + + // // + // XCResistanceZone *iZone = tmpZones[idx]; + // ArrayRemove( + // tmpZones, + // idx, + // 1 // + // ); + + // // + // // Validate Zone ... + // has = + // !isBullish + // ? IsAboveDiff( + // iZone, + // selectedZone.ob, + // true // Ignore Inside ... + // ) + // : IsBelowDiff( + // iZone, + // selectedZone.ob, + // true // Ignore Inside ... + // ); + // if (!has) + // { + // continue; + // } + + // // + // has = + // selectedResistance == NULL + // ? true + // : !isBullish + // ? selectedResistance.Upper() < iZone.Upper() + // : selectedResistance.Lower() > iZone.Lower(); + // if (!has) + // { + // continue; + // } + + // // + // selectedResistance = iZone; + + // // + // } + + // // + // has = selectedResistance != NULL; + // if (has) + // { + // // + // double iSL = + // !isBullish + // ? selectedResistance.Upper() + // : selectedResistance.Lower(); + // double iSLDiff = MathAbs(iSL - pivot); + // has = + // iSLDiff > 0 && + // iSLDiff <= maxAllowedSLDistanceInPoint * points; + // if (has) + // { + // // + // Add( + // iSL, + // sls // + // ); + // } + // } + + // // + // Clean(tmpZones); + // ZeroMemory(selectedResistance); + // } + + // + // Cleanp Resources ... + + // + cBar.Clean(); + // passedBar.Clean(); + result = HasChild(sls); + + // + return result; +} + +//////////////////////////////////////////////////////////////////////////////// + + +/** + * Detect Targets Based on Selected Zone for Specified type of Directions ... + * + * @param targets: double Collection ... + * @param selectedZone: XBoxZone instance, selected Zone ... + * @param forDir: ENUM_X_DIRECTION specified Position Direction ... + * @param workingone: X121SMCStrategyXWZWorkingZone instance, Specified Working Zone ... + * @param barIndex: int Specified Bar Index ... + * + * @return ( bool ) + */ +bool DetectSelectedZonesTargets( + double &targets[], + XBoxZone &selectedZone, + ENUM_X_DIRECTION forDir, + ENUM_X121SMC_XWZ_PRIORITY forPriority, + X121SMCStrategyXWZWorkingZone &workingZone, + int barIndex = 0 // +) +{ + // + bool result = false; + + // + Clean(targets); + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (barIndex == 0) + { + barIndex++; + } + + // + result = + // + selectedZone.IsValid() && + HasDirection(forDir) && + workingZone.IsValid() && + forPriority != X121SMC_XWZ_PRIORITY_NONE + // + ; + if (!result) + { + return result; + } + + // + bool isBullish = IsBullish(forDir); + + // + XOHCL cBar; + result = cBar.Init( + workingZone.symbol, + workingZone.period, + barIndex // + ); + if (!result) + { + // + cBar.Clean(); + return result; + } + + // + int idx = -1; + bool has = false; + XOBFVG tmpZones[]; + + // + // Based On Waiting Zones ... + has = workingZone.HasWaitingZones(); + if (has) + { + // + Copy( + workingZone.waitingZones, + tmpZones // + ); + + // + while (HasChild(tmpZones)) + { + // + XOBFVG iOBFVG; + + // + idx = GetYoungest(tmpZones); + if (!IsValidIndex(idx)) + { + // + iOBFVG.Clean(); + break; + } + + // + iOBFVG = tmpZones[idx]; + ArrayRemove( + tmpZones, + idx, + 1 // + ); + + // + double iTarget = + isBullish + ? iOBFVG.ob.Lower() + : iOBFVG.ob.Upper(); + + // + has = + isBullish + ? cBar.high < iTarget + : cBar.low > iTarget; + + // + if (has) + { + // + Add( + iTarget, + targets // + ); + } + + // + iOBFVG.Clean(); + } + + // + Clean(tmpZones); + } + + // + // Based On Breaked Zones ... + has = workingZone.HasBreakedZones(); + if (has) + { + Copy( + workingZone.breakedZones, + tmpZones // + ); + + // + while (HasChild(tmpZones)) + { + // + XOBFVG iOBFVG; + + // + idx = GetYoungest(tmpZones); + if (!IsValidIndex(idx)) + { + // + iOBFVG.Clean(); + break; + } + + // + iOBFVG = tmpZones[idx]; + ArrayRemove( + tmpZones, + idx, + 1 // + ); + + // + double iTarget = + isBullish + ? iOBFVG.ob.Lower() + : iOBFVG.ob.Upper(); + + // + has = + isBullish + ? cBar.high < iTarget + : cBar.low > iTarget; + + // + if (has) + { + // + Add( + iTarget, + targets // + ); + } + + // + iOBFVG.Clean(); + } + + // + Clean(tmpZones); + } + + // + // Based On Priority ... + has = forPriority != X121SMC_XWZ_PRIORITY_NONE; + if (has) + { + // + switch (forPriority) + { + // + case X121SMC_XWZ_PRIORITY_WEAK: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + } + break; + + // + case X121SMC_XWZ_PRIORITY_LOW: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + } + break; + + // + case X121SMC_XWZ_PRIORITY_REGULAR: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + } + break; + + // + case X121SMC_XWZ_PRIORITY_HIGH: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter3, + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter1, + targets // + ); + } + break; + + // + case X121SMC_XWZ_PRIORITY_STRONG_HIGH: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Strong High ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Strong High ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + } + break; + } + } + + // + result = HasChild(targets); + + // + // Cleanup ... + cBar.Clean(); + Clean(tmpZones); + + // + return result; +} + +/////////////////////////////////////////////////////////////////////// + + +// +struct X121SMCStrategyXWZWorkingZone +{ + // + // Props ... + + // + string symbol; + ENUM_TIMEFRAMES period; + + // + double quarter1; + double quarter2; + double quarter3; + + // + XCSupplyZone *supplyZone; + XCDemandZone *demandZone; + + // + XCSupplyZone *supplyZones[]; + XCDemandZone *demandZones[]; + + // + XCSupportZone *supportZones[]; + XCResistanceZone *resistanceZones[]; + + // + XOBFVG insideZones[]; + XOBFVG breakedZones[]; + XOBFVG waitingZones[]; + + // + XBoxZone insideBoxes[]; + XBoxZone breakedBoxes[]; + XConsolidationZone consolidationZones[]; + + // + CArrayObj mInsideZoneObjects; + CArrayObj mBreakedZoneObjects; + CArrayObj mWaitingZoneObjects; + CArrayObj mWorkingZoneObjects; + + // + // Constructor ... + X121SMCStrategyXWZWorkingZone() + { + Clean(); + } + + // + // Tools ... + + // + void Clean() + { + // + quarter1 = 0; + quarter2 = 0; + quarter3 = 0; + + // + symbol = NULL; + period = NULL; + + // + Clean(supplyZones); + Clean(demandZones); + + // + Clean(insideZones); + Clean(waitingZones); + Clean(breakedZones); + + // + Clean(insideBoxes); + Clean(breakedBoxes); + + // + Clean(supportZones); + Clean(resistanceZones); + + // + ZeroMemory(supplyZone); + ZeroMemory(demandZone); + + // + mInsideZoneObjects.Clear(); + mBreakedZoneObjects.Clear(); + mWaitingZoneObjects.Clear(); + mWorkingZoneObjects.Clear(); + } + + // + bool IsValid() + { + // + bool result = false; + + // + result = + // + quarter1 > 0 && + quarter2 > 0 && + quarter3 > 0 && + HasSupplyZone() && + HasDemandZone() && + quarter1 > quarter2 && + quarter2 > quarter3 + // + ; + + // + return result; + } + + // + bool Init( + string _symbol, + ENUM_TIMEFRAMES _period, + int barIndex, + XPOIState &htfState, + XPOIState &mtfState, + XPOIState &stfState, // + XPOIState &ttfState // + ) + { + // + bool result = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + result = + // + IsValid(_symbol) && + IsValid(_period) && + // + htfState.IsValid() && + mtfState.IsValid() && + stfState.IsValid() && + ttfState.IsValid() && + // + htfState.HasChild() && + mtfState.HasChild() && + stfState.HasChild() && + ttfState.HasChild() + // + ; + if (!result) + { + return result; + } + + // + symbol = _symbol; + period = _period; + + // + int idx = -1; + int count = 0; + bool has = false; + + // + XOHCL zBar; + has = zBar.Init( + symbol, + period, + barIndex // + ); + result = has; + if (!result) + { + zBar.Clean(); + return result; + } + double ll5 = zBar.FindLowest(5, MODE_LOW); + double hh5 = zBar.FindHighest(5, MODE_HIGH); + zBar.Clean(); + + // + // Supply Zone ... + has = HasSupplyZone(); + if (!has) + { + // + idx = GetHighest(htfState.supplyZones); + has = IsValidIndex(idx); + if (has) + { + // + supplyZone = htfState.supplyZones[idx]; + has = hh5 < supplyZone.Lower(); + if (!has) + { + supplyZone = NULL; + } + } + } + + // + // Demand Zone ... + has = HasDemandZone(); + if (!has) + { + // + idx = GetLowest(htfState.demandZones); + has = IsValidIndex(idx); + if (has) + { + // + demandZone = htfState.demandZones[idx]; + has = ll5 > demandZone.Upper(); + if (!has) + { + demandZone = NULL; + } + } + } + + // + // Supply Zones ... + has = HasSupplyZones(); + if (!has) + { + // + count = mtfState.FilterSupplyZones( + supplyZones, + period, + XZONE_STATE_PASSED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_IGNORED, + false // + ); + } + + // + // Demand Zones ... + has = HasDemandZones(); + if (!has) + { + // + count = mtfState.FilterDemandZones( + demandZones, + period, + XZONE_STATE_PASSED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_IGNORED, + false // + ); + } + + // + has = ttfState.HasConsolidationZones(); + if (has) + { + // + Copy( + ttfState.consolidationZones, + consolidationZones // + ); + CleanupArray( + consolidationZones, + 50 // + ); + } + + // + if (supplyZone != NULL && + demandZone != NULL && + supplyZone.IsValid() && + demandZone.IsValid()) + { + // + double upper = supplyZone.Lower(); + double lower = demandZone.Upper(); + + // + double delta = ((upper - lower) / 100) * 25; + + // + quarter1 = upper - (1 * delta); + quarter2 = upper - (2 * delta); + quarter3 = upper - (3 * delta); + } + + // + // Detect OBFVG(s) ... + ExtractOBFVGs( + waitingZones, + mtfState, + stfState); + + // + result = IsValid(); + if (!result) + { + Clean(); + } + + // + return result; + } + + // + void Update( + int barIndex, + XPOIState &htfState, + XPOIState &mtfState, + XPOIState &stfState, + XPOIState &ttfState // + ) + { + // + int idx = -1; + int count = 0; + bool has = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + has = + // + IsValid() && + // + htfState.IsValid() && + mtfState.IsValid() && + stfState.IsValid() && + // + htfState.HasChild() && + mtfState.HasChild() && + stfState.HasChild() + // + ; + if (!has) + { + return; + } + + // + XOHCL zBar; + has = zBar.Init( + symbol, + period, + barIndex // + ); + if (!has) + { + // + zBar.Clean(); + return; + } + + // + XOHCL cBar; + has = zBar.GetPreviousBar(cBar); + if (!has) + { + // + zBar.Clean(); + cBar.Clean(); + + // + return; + } + + // + // Adding New OBFVG to Waiting Zones if not Exists ... + XOBFVG tmpWaitingZones[]; + count = ExtractOBFVGs( + tmpWaitingZones, + mtfState, + stfState // + ); + has = IsValidSize(count); + if (has) + { + // + AddIfNotExists( + tmpWaitingZones, + waitingZones // + ); + } + + // + // Since Usig States for Extracting Supply/Demand or + // Support/Resistance Zones and State's has Max Alllowed Restrication ... + // we have to Manage new Zones and also Hold's Breaked Zones ... + + // + // MTF STF ... + + // + // Supply Zones ... + XCSupplyZone *tmpSupplies[]; + count = mtfState.FilterSupplyZones( + tmpSupplies, + NULL, + XZONE_STATE_PASSED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_IGNORED, + false // + ); + has = IsValidSize(count); + if (has) + { + // + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox; + has = ToBox( + iBox, + tmpSupplies[i] // + ); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + // Find Index ... + + // + idx = FindIndex( + iBox, + insideBoxes // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + idx = FindIndex( + iBox, + breakedBoxes // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + idx = FindIndex( + tmpSupplies[i], + supplyZones // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + // Checking Price Validation ... + has = cBar.high < tmpSupplies[i].Lower(); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + Add( + tmpSupplies[i], + supplyZones // + ); + + // + iBox.Clean(); + } + } + Clean(tmpSupplies); + + // + // Demand Zones ... + XCDemandZone *tmpDemands[]; + count = mtfState.FilterDemandZones( + tmpDemands, + NULL, + XZONE_STATE_PASSED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_IGNORED, + false // + ); + has = IsValidSize(count); + if (has) + { + // + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox; + has = ToBox( + iBox, + tmpDemands[i] // + ); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + // Find Index ... + + // + idx = FindIndex( + iBox, + insideBoxes // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + idx = FindIndex( + iBox, + breakedBoxes // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + idx = FindIndex( + tmpDemands[i], + demandZones // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + // Checking Price Validation ... + has = cBar.low > tmpDemands[i].Upper(); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + Add( + tmpDemands[i], + demandZones // + ); + + // + iBox.Clean(); + } + } + Clean(tmpDemands); + + // + // + // + + // + // Consolidation Zones ... + has = ttfState.HasConsolidationZones(); + if (has) + { + // + Copy( + ttfState.consolidationZones, + consolidationZones // + ); + CleanupArray( + consolidationZones, + 50 // + ); + } + + // + // + // + + // + // Detect Price Inside Zones ... + has = HasWaitingZones(); + if (has) + { + // + int mustRemove[]; + count = CountWaitingZones(); + for (int i = 0; i < count; i++) + { + // + XOBFVG iOBFVG = waitingZones[i]; + + // + bool isInside = + // + zBar.high < iOBFVG.ob.Upper() && + zBar.low > iOBFVG.ob.Lower() && + // + cBar.high < iOBFVG.ob.Upper() && + cBar.low > iOBFVG.ob.Lower() + // + ; + if (isInside) + { + // + idx = FindIndex( + iOBFVG, + insideZones // + ); + has = IsValidSize(idx); + if (!has) + { + // + Add( + i, + mustRemove // + ); + + // + AddRef( + iOBFVG, + insideZones // + ); + } + } + } + + // + has = HasChild(mustRemove); + if (has) + { + // + count = ArraySize(mustRemove); + for (int i = 0; i < count; i++) + { + // + ArrayRemove( + waitingZones, + mustRemove[i], + 1 // + ); + } + } + + // + Clean(mustRemove); + } + + // + // Here we Looking for Price Inside Supply or Demand Zones ... + + // + // Supply Zones ... + has = HasSupplyZones(); + if (has) + { + // + int mustRemove[]; + count = CountSupplyZones(); + for (int i = 0; i < count; i++) + { + // + XCSupplyZone *iZone = supplyZones[i]; + + // + bool isInside = + // + zBar.high < iZone.Upper() && + zBar.low > iZone.Lower() && + // + cBar.high < iZone.Upper() && + cBar.low > iZone.Lower() + // + ; + if (isInside) + { + // + XBoxZone iBox; + has = ToBox( + iBox, + iZone // + ); + if (has) + { + // + idx = FindIndex( + iBox, + insideBoxes // + ); + has = IsValidSize(idx); + if (!has) + { + // + Add( + i, + mustRemove // + ); + + // + AddRef( + iBox, + insideBoxes // + ); + } + } + + // + iBox.Clean(); + } + } + + // + has = HasChild(mustRemove); + if (has) + { + // + count = ArraySize(mustRemove); + for (int i = 0; i < count; i++) + { + // + ArrayRemove( + supplyZones, + mustRemove[i], + 1 // + ); + } + } + + // + Clean(mustRemove); + } + + // + // Demand Zones ... + has = HasDemandZones(); + if (has) + { + // + int mustRemove[]; + count = CountDemandZones(); + for (int i = 0; i < count; i++) + { + // + XCDemandZone *iZone = demandZones[i]; + + // + bool isInside = + // + zBar.high < iZone.Upper() && + zBar.low > iZone.Lower() && + // + cBar.high < iZone.Upper() && + cBar.low > iZone.Lower() + // + ; + if (isInside) + { + // + XBoxZone iBox; + has = ToBox( + iBox, + iZone // + ); + if (has) + { + // + idx = FindIndex( + iBox, + insideBoxes // + ); + has = IsValidSize(idx); + if (!has) + { + // + Add( + i, + mustRemove // + ); + + // + AddRef( + iBox, + insideBoxes // + ); + } + } + + // + iBox.Clean(); + } + } + + // + has = HasChild(mustRemove); + if (has) + { + // + count = ArraySize(mustRemove); + for (int i = 0; i < count; i++) + { + // + ArrayRemove( + demandZones, + mustRemove[i], + 1 // + ); + } + } + + // + Clean(mustRemove); + } + + // + // Here we Detect Breaked Zone/Box (s) ... + + // // + // // Detect Breaked Zones ... + // has = HasInsideZones(); + // if (has) + // { + // // + // int mustRemove[]; + // count = CountInsideZones(); + // for (int i = 0; i < count; i++) + // { + // // + // XOBFVG iOBFVG = insideZones[i]; + // ENUM_X_DIRECTION iDir = iOBFVG.GetDirection(); + // bool isBullish = IsBullish(iDir); + + // // + // bool isBullishBreaked = + // // + // zBar.high < iOBFVG.ob.Lower() && + // cBar.high < iOBFVG.ob.Lower() + // // + // ; + + // // + // bool isBearishBreaked = + // // + // zBar.low > iOBFVG.ob.Upper() && + // cBar.low > iOBFVG.ob.Upper() + // // + // ; + + // // + // bool isBreaked = + // isBullish + // ? isBullishBreaked + // : isBearishBreaked; + + // // + // if (isBreaked) + // { + // // + // idx = FindIndex( + // iOBFVG, + // breakedZones // + // ); + // has = IsValidIndex(idx); + // if (!has) + // { + // // + // Add( + // i, + // mustRemove // + // ); + + // // + // AddRef( + // iOBFVG, + // breakedZones // + // ); + // } + // } + // } + + // // + // has = HasChild(mustRemove); + // if (has) + // { + // // + // count = ArraySize(mustRemove); + // for (int i = 0; i < count; i++) + // { + // // + // ArrayRemove( + // insideZones, + // mustRemove[i], + // 1 // + // ); + // } + // } + + // // + // Clean(mustRemove); + // } + + // // + // // Detect Breaked Boxes ... + // has = HasInsideBoxes(); + // if (has) + // { + // // + // int mustRemove[]; + // count = CountInsideBoxes(); + // for (int i = 0; i < count; i++) + // { + // // + // XBoxZone iBox = insideBoxes[i]; + // ENUM_X_DIRECTION iDir = iBox.dir; + // bool isBullish = iBox.IsBullish(); + + // // + // bool isBullishBreaked = + // // + // zBar.high < iBox.lower && + // cBar.high < iBox.lower + // // + // ; + + // // + // bool isBearishBreaked = + // // + // zBar.low > iBox.upper && + // cBar.low > iBox.upper + // // + // ; + + // // + // bool isBreaked = + // isBullish + // ? isBullishBreaked + // : isBearishBreaked; + + // // + // if (isBreaked) + // { + // // + // idx = FindIndex( + // iBox, + // breakedBoxes // + // ); + // has = IsValidIndex(idx); + // if (!has) + // { + // // + // Add( + // i, + // mustRemove // + // ); + + // // + // AddRef( + // iBox, + // breakedBoxes // + // ); + // } + // } + // } + + // // + // has = HasChild(mustRemove); + // if (has) + // { + // // + // count = ArraySize(mustRemove); + // for (int i = 0; i < count; i++) + // { + // // + // ArrayRemove( + // insideBoxes, + // mustRemove[i], + // 1 // + // ); + // } + // } + + // // + // Clean(mustRemove); + // } + + // + // Cleanup Resource ... + + // + zBar.Clean(); + cBar.Clean(); + } + + // + bool HasSupplyZone() + { + return supplyZone != NULL && + supplyZone.IsValid(); + } + + // + bool HasDemandZone() + { + return demandZone != NULL && + demandZone.IsValid(); + } + + // + bool HasSupplyZones() + { + return HasChild(supplyZones); + } + + // + int CountSupplyZones() + { + return ArraySize(supplyZones); + } + + // + bool HasDemandZones() + { + return HasChild(demandZones); + } + + // + int CountDemandZones() + { + return ArraySize(demandZones); + } + + // + bool HasSupportZones() + { + return HasChild(supportZones); + } + + // + int CountSupportZones() + { + return ArraySize(supportZones); + } + + // + bool HasResistanceZones() + { + return HasChild(resistanceZones); + } + + // + int CountResistanceZones() + { + return ArraySize(resistanceZones); + } + + // + bool HasWaitingZones() + { + return HasChild(waitingZones); + } + + // + int CountWaitingZones() + { + return ArraySize(waitingZones); + } + + // + bool HasInsideZones() + { + return HasChild(insideZones); + } + + // + int CountInsideZones() + { + return ArraySize(insideZones); + } + + // + bool HasBreakedZones() + { + return HasChild(breakedZones); + } + + // + int CountBreakedZones() + { + return ArraySize(breakedZones); + } + + // + bool HasConsolidationZones() + { + return HasChild(consolidationZones); + } + + // + int CountConsolidationZones() + { + return ArraySize(consolidationZones); + } + + // + bool HasInsideBoxes() + { + return HasChild(insideBoxes); + } + + // + int CountInsideBoxes() + { + return ArraySize(insideBoxes); + } + + // + bool HasBreakedBoxes() + { + return HasChild(breakedBoxes); + } + + // + int CountBreakedBoxes() + { + return ArraySize(breakedBoxes); + } + + // + // + // + + // + bool IsDestroyed( + int barIndex = 0, + ENUM_TIMEFRAMES forPeriod = NULL // + ) + { + // + bool result = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (!IsValid(forPeriod)) + { + forPeriod = period; + } + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + XOHCL bar; + result = bar.Init( + symbol, + period, + barIndex // + ); + if (!result) + { + // + bar.Clean(); + return result; + } + + // + XOHCL cBar; + result = bar.GetPreviousBar(cBar); + if (!result) + { + // + bar.Clean(); + cBar.Clean(); + + // + return result; + } + + // + bool isSupplyZoneBreaked = + // + bar.low > supplyZone.Upper() && + cBar.low > supplyZone.Upper() + // + ; + + // + bool isDemandZoneBreaked = + // + bar.high < demandZone.Lower() && + cBar.high < demandZone.Lower() + // + ; + + // + bar.Clean(); + cBar.Clean(); + + // + result = isSupplyZoneBreaked || + isDemandZoneBreaked; + + // + return result; + } + + // + bool DetectPriority( + ENUM_X121SMC_XWZ_PRIORITY &priority, + ENUM_X_DIRECTION forDir, + int barIndex = 0, + ENUM_TIMEFRAMES forPeriod = NULL // + ) + { + // + bool result = false; + + // + priority = X121SMC_XWZ_PRIORITY_NONE; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (!IsValid(forPeriod)) + { + forPeriod = period; + } + + // + result = IsValid() && + HasDirection(forDir); + if (!result) + { + return result; + } + + // + bool isBullish = IsBullish(forDir); + + // + XOHCL bar; + result = bar.Init( + symbol, + forPeriod, + barIndex // + ); + if (!result) + { + // + bar.Clean(); + return result; + } + + // + if (bar.high < supplyZone.Upper() && + bar.low > supplyZone.Lower()) + { + // + priority = + isBullish + ? X121SMC_XWZ_PRIORITY_NONE + : X121SMC_XWZ_PRIORITY_STRONG_HIGH; + } + else if (bar.high < supplyZone.Lower() && + bar.low > quarter1) + { + // + priority = + isBullish + ? X121SMC_XWZ_PRIORITY_WEAK + : X121SMC_XWZ_PRIORITY_HIGH; + } + else if (bar.high < quarter1 && + bar.low > quarter2) + { + // + priority = + isBullish + ? X121SMC_XWZ_PRIORITY_LOW + : X121SMC_XWZ_PRIORITY_REGULAR; + } + else if (bar.high < quarter2 && + bar.low > quarter3) + { + // + priority = + isBullish + ? X121SMC_XWZ_PRIORITY_REGULAR + : X121SMC_XWZ_PRIORITY_LOW; + } + else if (bar.high < quarter3 && + bar.low > demandZone.Upper()) + { + // + priority = + isBullish + ? X121SMC_XWZ_PRIORITY_HIGH + : X121SMC_XWZ_PRIORITY_WEAK; + } + else if (bar.high < demandZone.Upper() && + bar.low > demandZone.Lower()) + { + // + priority = + isBullish + ? X121SMC_XWZ_PRIORITY_STRONG_HIGH + : X121SMC_XWZ_PRIORITY_NONE; + } + + // + result = priority != X121SMC_XWZ_PRIORITY_NONE && + priority != X121SMC_XWZ_PRIORITY_WEAK; + + // + bar.Clean(); + + // + return result; + } + + // + // + // + + // + void UpdateTo(datetime value = NULL) + { + // + value = NormalizeTime(value); + + // + int count = 0; + bool has = false; + + // + has = HasSupplyZone(); + if (has) + { + supplyZone.To(value); + } + + // + has = HasDemandZone(); + if (has) + { + demandZone.To(value); + } + + // + has = HasSupplyZones(); + if (has) + { + // + count = CountSupplyZones(); + for (int i = 0; i < count; i++) + { + supplyZones[i].To(value); + } + } + + // + has = HasDemandZones(); + if (has) + { + // + count = CountDemandZones(); + for (int i = 0; i < count; i++) + { + demandZones[i].To(value); + } + } + + // + has = HasSupportZones(); + if (has) + { + // + count = CountSupportZones(); + for (int i = 0; i < count; i++) + { + supportZones[i].To(value); + } + } + + // + has = HasResistanceZones(); + if (has) + { + // + count = CountResistanceZones(); + for (int i = 0; i < count; i++) + { + resistanceZones[i].To(value); + } + } + + // + has = HasWaitingZones(); + if (has) + { + // + count = CountWaitingZones(); + for (int i = 0; i < count; i++) + { + waitingZones[i].UpdateTo(value); + } + } + + // + has = HasInsideZones(); + if (has) + { + // + count = CountInsideZones(); + for (int i = 0; i < count; i++) + { + insideZones[i].UpdateTo(value); + } + } + + // + has = HasInsideBoxes(); + if (has) + { + // + count = CountInsideBoxes(); + for (int i = 0; i < count; i++) + { + insideBoxes[i].to = value; + } + } + + // + } + + // + void Draw( + XCPOIDrawer *drawer, + bool drawWaitingZones = true, + bool drawInsideZones = false, + bool drawBreakedZones = false, + bool drawSupplyZone = false, + bool drawDemandZone = false, + bool drawSupplyZones = false, + bool drawDemandZones = false, + bool drawSupportZones = false, + bool drawResistanceZones = false // + ) + { + // + if (drawer == NULL) + { + return; + } + + // + int count = 0; + bool has = false; + bool isCreated = false; + + // + ulong chartID = drawer.ChartIdentification(); + int subWindow = drawer.SubWindowIdentification(); + color bullishColor = drawer.BarBullishColor(); + color bearishColor = drawer.BarBearishColor(); + + // + // Supply Zone ... + if (drawSupplyZone) + { + // + has = HasSupplyZone(); + if (has) + { + // + XCSupplyZoneObject *iObj; + isCreated = drawer.CreateSupplyZone( + supplyZone, + iObj // + ); + + // + if (isCreated) + { + mWorkingZoneObjects.Add(iObj); + } + } + } + + // + // Demand Zone ... + if (drawDemandZone) + { + // + has = HasDemandZone(); + if (has) + { + // + XCDemandZoneObject *iObj; + isCreated = drawer.CreateDemandZone( + demandZone, + iObj // + ); + + // + if (isCreated) + { + mWorkingZoneObjects.Add(iObj); + } + } + } + + // + // + // + + // + // Supply Zones ... + if (drawSupplyZones) + { + // + has = HasSupplyZones(); + if (has) + { + // + count = CountSupplyZones(); + for (int i = 0; i < count; i++) + { + // + XCSupplyZoneObject *iObj; + isCreated = drawer.CreateSupplyZone( + supplyZones[i], + iObj // + ); + + // + if (isCreated) + { + mWorkingZoneObjects.Add(iObj); + } + } + } + } + + // + // Demand Zones ... + if (drawDemandZones) + { + // + has = HasDemandZones(); + if (has) + { + // + count = CountDemandZones(); + for (int i = 0; i < count; i++) + { + // + XCDemandZoneObject *iObj; + isCreated = drawer.CreateDemandZone( + demandZones[i], + iObj // + ); + + // + if (isCreated) + { + mWorkingZoneObjects.Add(iObj); + } + } + } + } + + // + // Support Zones ... + if (drawSupportZones) + { + // + has = HasSupportZones(); + if (has) + { + // + count = CountSupportZones(); + for (int i = 0; i < count; i++) + { + // + XCSupportZoneObject *iObj; + isCreated = drawer.CreateSupportZone( + supportZones[i], + iObj // + ); + + // + if (isCreated) + { + mWorkingZoneObjects.Add(iObj); + } + } + } + } + + // + // Resistance Zones ... + if (drawResistanceZones) + { + // + has = HasResistanceZones(); + if (has) + { + // + count = CountResistanceZones(); + for (int i = 0; i < count; i++) + { + // + XCResistanceZoneObject *iObj; + isCreated = drawer.CreateResistanceZone( + resistanceZones[i], + iObj // + ); + + // + if (isCreated) + { + mWorkingZoneObjects.Add(iObj); + } + } + } + } + + // + // + // + + // + // Waiting Zones ... + if (drawWaitingZones) + { + // + has = HasWaitingZones(); + if (has) + { + // + count = CountWaitingZones(); + for (int i = 0; i < count; i++) + { + // + XCBaseObject *objects[]; + int objectsCount = drawer.DrawOBFVG( + waitingZones[i], + objects // + ); + has = IsValidSize(objectsCount); + if (has) + { + // + for (int j = 0; j < objectsCount; j++) + { + mWaitingZoneObjects.Add(objects[j]); + } + } + } + } + } + + // + // Inside Zones ... + if (drawInsideZones) + { + // + // Zones ... + has = HasInsideZones(); + if (has) + { + // + count = CountInsideZones(); + for (int i = 0; i < count; i++) + { + // + XCBaseObject *objects[]; + int objectsCount = drawer.DrawOBFVG( + insideZones[i], + objects // + ); + + // + has = IsValidSize(objectsCount); + if (has) + { + // + for (int i = 0; i < objectsCount; i++) + { + mInsideZoneObjects.Add(objects[i]); + } + } + } + } + + // // + // // Boxes ... + // has = HasInsideBoxes(); + // if (has) + // { + // // + // count = CountInsideBoxes(); + // for (int i = 0; i < count; i++) + // { + // // + // XCBoxObject *object; + // bool isCreated = drawer.DrawBox( + // insideBoxes[i], + // object // + // ); + + // // + // if (isCreated) + // { + // mInsideZoneObjects.Add(object); + // } + // } + // } + } + + // + // Breaked Zones ... + if (drawBreakedZones) + { + // + has = HasBreakedZones(); + if (has) + { + // + count = CountBreakedZones(); + for (int i = 0; i < count; i++) + { + // + XCBaseObject *objects[]; + int objectsCount = drawer.DrawOBFVG( + breakedZones[i], + objects // + ); + + // + has = IsValidSize(objectsCount); + if (has) + { + // + for (int i = 0; i < objectsCount; i++) + { + mBreakedZoneObjects.Add(objects[i]); + } + } + } + } + + // // + // // Boxes ... + // has = HasBreakedBoxes(); + // if (has) + // { + // // + // count = CountBreakedBoxes(); + // for (int i = 0; i < count; i++) + // { + // // + // XCBoxObject *object; + // bool isCreated = drawer.DrawBox( + // breakedBoxes[i], + // object // + // ); + + // // + // if (isCreated) + // { + // mInsideZoneObjects.Add(object); + // } + // } + // } + } + + // + // + // + + // + // Quarters ... + has = IsValid(); + if (has) + { + // + double zoneUpper = supplyZone.Upper(); + double upper = supplyZone.Lower(); + + // + double lower = demandZone.Upper(); + double zoneLower = demandZone.Lower(); + + // + string prefix = "X121WZone_" + symbol + "_" + ToString(period); + + // + // Zone Upper ... + CChartObjectHLine *zoneUpperLine; + zoneUpperLine = new CChartObjectHLine(); + isCreated = zoneUpperLine.Create( + chartID, + prefix + "_ZoneTop", + subWindow, + zoneUpper // + ); + if (isCreated) + { + // + zoneUpperLine.Color(clrRed); + + // + mWaitingZoneObjects.Add(zoneUpperLine); + } + + // + // Zone Lower ... + CChartObjectHLine *zoneLowerLine; + zoneLowerLine = new CChartObjectHLine(); + isCreated = zoneLowerLine.Create( + chartID, + prefix + "_ZoneDown", + subWindow, + zoneLower // + ); + if (isCreated) + { + // + zoneLowerLine.Color(clrRed); + + // + mWaitingZoneObjects.Add(zoneLowerLine); + } + + // + // Upper ... + CChartObjectHLine *upperLine; + upperLine = new CChartObjectHLine(); + isCreated = upperLine.Create( + chartID, + prefix + "_Upper", + subWindow, + upper // + ); + if (isCreated) + { + // + upperLine.Color(clrLime); + + // + mWaitingZoneObjects.Add(upperLine); + } + + // + // Lower ... + CChartObjectHLine *lowerLine; + lowerLine = new CChartObjectHLine(); + isCreated = lowerLine.Create( + chartID, + prefix + "_Lower", + subWindow, + lower // + ); + if (isCreated) + { + // + lowerLine.Color(clrLime); + + // + mWaitingZoneObjects.Add(lowerLine); + } + + // + // Quarters ... + + // + // Quarter 1 ... + CChartObjectHLine *q1Line; + q1Line = new CChartObjectHLine(); + isCreated = q1Line.Create( + chartID, + prefix + "_Q1", + subWindow, + quarter1 // + ); + if (isCreated) + { + // + q1Line.Color(clrYellow); + + // + mWaitingZoneObjects.Add(q1Line); + } + + // + // Quarter 2 ... + CChartObjectHLine *q2Line; + q2Line = new CChartObjectHLine(); + isCreated = q2Line.Create( + chartID, + prefix + "_Q2", + subWindow, + quarter2 // + ); + if (isCreated) + { + // + q2Line.Color(clrYellow); + + // + mWaitingZoneObjects.Add(q2Line); + } + + // + // Quarter 3 ... + CChartObjectHLine *q3Line; + q3Line = new CChartObjectHLine(); + isCreated = q3Line.Create( + chartID, + prefix + "_Q3", + subWindow, + quarter3 // + ); + if (isCreated) + { + // + q3Line.Color(clrYellow); + + // + mWaitingZoneObjects.Add(q3Line); + } + } + } + + // +}; + +////////////////////////////////////////////////////// + + +/** + * Detect Targets Based on Selected Zone for Specified type of Directions ... + * + * @param targets: double Collection ... + * @param selectedZone: XOBFVG instance, selected Zone ... + * @param forDir: ENUM_X_DIRECTION specified Position Direction ... + * @param workingone: X121SMCStrategyXWZWorkingZone instance, Specified Working Zone ... + * @param barIndex: int Specified Bar Index ... + * + * @return ( bool ) + */ +bool DetectSelectedZonesTargets( + double &targets[], + XOBFVG &selectedZone, + ENUM_X_DIRECTION forDir, + ENUM_X121SMC_XWZ_PRIORITY forPriority, + X121SMCStrategyXWZWorkingZone &workingZone, + int barIndex = 0 // +) +{ + // + bool result = false; + + // + Clean(targets); + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (barIndex == 0) + { + barIndex++; + } + + // + result = + // + selectedZone.IsValid() && + HasDirection(forDir) && + workingZone.IsValid() && + forPriority != X121SMC_XWZ_PRIORITY_NONE + // + ; + if (!result) + { + return result; + } + + // + bool isBullish = IsBullish(forDir); + + // + XOHCL cBar; + result = cBar.Init( + workingZone.symbol, + workingZone.period, + barIndex // + ); + if (!result) + { + // + cBar.Clean(); + return result; + } + + // + int idx = -1; + bool has = false; + + // + // Based On Priority ... + has = forPriority != X121SMC_XWZ_PRIORITY_NONE; + if (has) + { + // + switch (forPriority) + { + // + case X121SMC_XWZ_PRIORITY_WEAK: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + } + break; + + // + case X121SMC_XWZ_PRIORITY_LOW: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + } + break; + + // + case X121SMC_XWZ_PRIORITY_REGULAR: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + } + break; + + // + case X121SMC_XWZ_PRIORITY_HIGH: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter3, + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter1, + targets // + ); + } + break; + + // + case X121SMC_XWZ_PRIORITY_STRONG_HIGH: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Strong High ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Strong High ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + } + break; + } + } + + // + result = HasChild(targets); + + // + // Cleanup ... + cBar.Clean(); + Clean(tmpZones); + + // + return result; +} + +///////////////////////////////////////////////////////////// + +/** + * Check an XOBFVG instance has Required Conditions ... + * + * @param zone: XOBFVG instance ... + * @param state: XPOIState instance ... + * @param conditions: X121Conditions instance ... + * + * @return ( bool ) + */ +bool DetectInsideSelectedZoneConditions( + bool &isReversal, + XOBFVG &zone, + XPOIState &state, + X121Conditions &conditions, + int barIndex = 0 // +) +{ + // + bool result = false; + + // + isReversal = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (barIndex == 0) + { + barIndex++; + } + + // + XOHCL bar; + result = bar.Init( + state.symbol, + state.period, + barIndex // + ); + if (!result) + { + // + bar.Clean(); + return result; + } + + // + result = + zone.IsValid() && + state.IsValid() && + state.HasChild(); + if (!result) + { + // + bar.Clean(); + return result; + } + + // + bool isBullish = zone.IsBullish(); + bool isBearish = zone.IsBearish(); + + // + double points = GetPoints(bar.symbol); + + // + double bullishScore = 0; + double bearishScore = 0; + double scoreMultiplier = 1.5; + conditions.GenerateScore( + bullishScore, + bearishScore // + ); + + // // + // bool isLowerBreaked = + // // + // conditions.isSarBearish && + // conditions.isCheBearish && + // bar.high < zone.ob.Lower() && + // bearishScore > bullishScore && + // conditions.isX3MaBearishState && + // conditions.isVWapBearishState && + // conditions.isX3MaBearishOrdered && + // conditions.isVWapBearishOrdered && + // bar.low < conditions.atrLowerBuffer[1] && + // conditions.atrLowerBuffer[1] < zone.ob.Lower() + // // + // ; + + // // + // bool isUpperBreaked = + // // + // conditions.isSarBullish && + // conditions.isCheBullish && + // bar.low > zone.ob.Upper() && + // bullishScore > bearishScore && + // conditions.isX3MaBullishState && + // conditions.isVWapBullishState && + // conditions.isX3MaBullishOrdered && + // conditions.isVWapBullishOrdered && + // bar.high > conditions.atrUpperBuffer[1] && + // conditions.atrUpperBuffer[1] > zone.ob.Upper() + // // + // ; + + // // + // bool isPeakEqualsToUpper = + // MathAbs(conditions.peaksBuffer[0] - zone.ob.Upper()) > points * 1; + + // // + // bool isValeEqualsToLower = + // MathAbs(conditions.valesBuffer[0] - zone.ob.Lower()) > points * 1; + + // + // bool isDirectionalBullishPassed = + // // + // isBullish && + // isUpperBreaked + // // ( + + // // || + // // isValeEqualsToLower) + // // + // ; + + // + // bool isDirectionalBearishPassed = + // // + // isBearish && + // isLowerBreaked + // // || + // // isPeakEqualsToUpper) + // // + // ; + + // + // bool isDirectionalPassed = + // isDirectionalBullishPassed || + // isDirectionalBearishPassed; + + // // + // bool isReversalBullishPassed = + // // + // // isBullish && + // // isLowerBreaked + // // ( || + // // isPeakEqualsToUpper) + // // + // ; + + // // + // bool isReversalBearishPassed = + // // + // // isBearish && + // // isUpperBreaked + // // || + // // isValeEqualsToLower) + // // + // ; + + // + // bool isReversalPassed = isReversalBullishPassed || + // isReversalBearishPassed; + + // + // result = isReversalPassed || + // isDirectionalPassed; + + // + result = false; + + // + if (result) + { + // isReversal = isReversalPassed; + } + + // + bar.Clean(); + return result; +} + +bool DetectBreakedSelectedZoneConditions( + bool &isReversal, + XOBFVG &zone, + XPOIState &mtfState, + XPOIState &stfState, + XPOIState &ttfState, + X121Conditions &conditions // +) +{ + // + bool result = false; + + // + isReversal = false; + + // + result = + // + zone.IsValid() && + mtfState.IsValid() && + stfState.IsValid() && + ttfState.IsValid() && + mtfState.HasChild() && + stfState.HasChild() && + ttfState.HasChild() + // + ; + if (!result) + { + return result; + } + + // + XBoxZone iBox; + result = ToBox( + iBox, + zone.ob // + ); + if (!result) + { + return result; + } + + // + ENUM_X_DIRECTION iDir = iBox.dir; + bool isBullish = IsBullish(iDir); + bool isBearish = IsBearish(iDir); + + // + // X3Ma ... + + // + double x3maFast = conditions.x3maFastBuffer[0]; + double x3maMid = conditions.x3maMidBuffer[0]; + double x3maSlow = conditions.x3maSlowBuffer[0]; + + // + bool isX3mInside = + // + (x3maFast < iBox.upper && + x3maMid < iBox.upper && + x3maSlow < iBox.upper) + // + && + // + (x3maFast > iBox.lower && + x3maMid > iBox.lower && + x3maSlow > iBox.lower) + // + ; + + // + bool isBullishConditions = + isBullish && + isX3mInside; + + // + bool isBearishConditions = + isBearish && + isX3mInside; + + // + result = isBullishConditions || + isBearishConditions; + + // + return result; +} + +/** + * Detect SL Candidates Based on Selected Zone for Specified type of Directions ... + * + * @param sls: double Collection ... + * @param selectedZone: XOBFVG instance, selected Zone ... + * @param forDir: ENUM_X_DIRECTION specified Position Direction ... + * @param workingZone: X121SMCStrategyXWZWorkingZone instance, Specified Working Zone ... + * @param barIndex: int Specified Bar Index ... + * @param maxAllowedSLDistanceInPoint: doube max Allowe SL distance ... + * + * @return ( bool ) + */ +bool DetectSelectedZoneSLCandidates( + double &sls[], + XOBFVG &selectedZone, + ENUM_X_DIRECTION forDir, + X121SMCStrategyXWZWorkingZone &workingZone, + X121Conditions &conditions, + int barIndex = 0, + double maxAllowedSLDistanceInPoint = 300 // +) +{ + // + bool result = false; + + // + Clean(sls); + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (barIndex == 0) + { + barIndex++; + } + + // + result = + // + selectedZone.IsValid() && + HasDirection(forDir) && + workingZone.IsValid() + // + ; + if (!result) + { + return result; + } + + // + bool isBullish = IsBullish(forDir); + + // + double pivot = + isBullish + ? selectedZone.ob.Lower() + : selectedZone.ob.Upper(); + double points = GetPoints(workingZone.symbol); + + // + XOHCL cBar; + result = cBar.Init( + workingZone.symbol, + workingZone.period, + barIndex // + ); + if (!result) + { + // + cBar.Clean(); + return result; + } + + // + int idx = -1; + bool has = false; + + // // + // double pvSL = isBullish + // ? conditions.valesBuffer[0] + // : conditions.peaksBuffer[1]; + + // // + // Add( + // pvSL, + // sls // + // ); + + // + // Based On Passed Bars ... + // XOHCL passedBar; + // bool isPassed = false; + // bool isBodyState = false; + // ENUM_X_DIRECTION passedDir = selectedZone.GetDirection(); + + // // + // // Started Bar ... + // isPassed = selectedZone.ob.IsStarted( + // passedDir, + // passedBar, + // isBodyState // + // ); + // if (isPassed) + // { + // // + // double iSL = + // isBullish + // ? passedBar.low + // : passedBar.high; + // double iSLDiff = MathAbs(iSL - pivot); + // has = + // iSLDiff > 0 && + // iSLDiff <= maxAllowedSLDistanceInPoint * points; + // if (has) + // { + // // + // Add( + // iSL, + // sls // + // ); + // } + // } + + // // + // // Activation Bar ... + // passedBar.Clean(); + // isPassed = selectedZone.ob.IsActivated( + // passedDir, + // passedBar, + // isBodyState // + // ); + // if (isPassed) + // { + // // + // double iSL = + // isBullish + // ? passedBar.low + // : passedBar.high; + // double iSLDiff = MathAbs(iSL - pivot); + // has = + // iSLDiff > 0 && + // iSLDiff <= maxAllowedSLDistanceInPoint * points; + // if (has) + // { + // // + // Add( + // iSL, + // sls // + // ); + // } + // } + + // // + // // Worked Bar ... + // passedBar.Clean(); + // isPassed = selectedZone.ob.IsActivated( + // passedDir, + // passedBar, + // isBodyState // + // ); + // if (isPassed) + // { + // // + // double iSL = + // isBullish + // ? passedBar.low + // : passedBar.high; + // double iSLDiff = MathAbs(iSL - pivot); + // has = + // iSLDiff > 0 && + // iSLDiff <= maxAllowedSLDistanceInPoint * points; + // if (has) + // { + // // + // Add( + // iSL, + // sls // + // ); + // } + // } + + // // + // // Breaked Bar ... + // passedBar.Clean(); + // isPassed = selectedZone.ob.IsActivated( + // passedDir, + // passedBar, + // isBodyState // + // ); + // if (isPassed) + // { + // // + // double iSL = + // isBullish + // ? passedBar.low + // : passedBar.high; + // double iSLDiff = MathAbs(iSL - pivot); + // has = + // iSLDiff > 0 && + // iSLDiff <= maxAllowedSLDistanceInPoint * points; + // if (has) + // { + // // + // Add( + // iSL, + // sls // + // ); + // } + // } + + // + // Based On Consolidation Zones ... + // has = workingZone.HasConsolidationZones(); + // if (has) + // { + // // + // XConsolidationZone tmpZones[]; + // Copy( + // workingZone.consolidationZones, + // tmpZones // + // ); + // XConsolidationZone selectedConsolidationZone; + + // // + // while (HasChild(tmpZones)) + // { + // // + // idx = GetYoungest(tmpZones); + // if (!IsValidIndex(idx)) + // { + // break; + // } + + // // + // XConsolidationZone iZone = tmpZones[idx]; + + // // + // ArrayRemove( + // tmpZones, + // idx, + // 1 // + // ); + + // // + // has = + // !selectedConsolidationZone.IsValid() + // ? isBullish + // ? cBar.low < iZone.upper + // : cBar.high < iZone.lower + // : isBullish + // ? selectedConsolidationZone.lower < iZone.lower + // : selectedConsolidationZone.upper > iZone.upper; + // if (has) + // { + // // + // selectedConsolidationZone = iZone; + // iZone.Clean(); + // break; + // } + + // // + // iZone.Clean(); + // } + + // // + // Clean(tmpZones); + // has = selectedConsolidationZone.IsValid(); + // if (has) + // { + // // + // double iSL = + // isBullish + // ? selectedConsolidationZone.lower + // : selectedConsolidationZone.upper; + // double iSLDiff = MathAbs(iSL - pivot); + // has = + // iSLDiff > 0 && + // iSLDiff <= maxAllowedSLDistanceInPoint * points; + // if (has) + // { + // // + // Add( + // iSL, + // sls // + // ); + // } + // } + // } + + // + // Based On Supply and Demand Zones ... + + // + // Demand Zones ... + // has = workingZone.HasDemandZones(); + // if (has) + // { + // // + // XCDemandZone *tmpZones[]; + // Copy( + // workingZone.demandZones, + // tmpZones // + // ); + // XCDemandZone *selectedDemand = NULL; + + // // + // while (HasChild(tmpZones)) + // { + // // + // idx = GetLowest(tmpZones); + // has = IsValidIndex(idx); + // if (!has) + // { + // break; + // } + + // // + // XCDemandZone *iZone = tmpZones[idx]; + // ArrayRemove( + // tmpZones, + // idx, + // 1 // + // ); + + // // + // // Validate Zone ... + // has = + // isBullish + // ? IsBelowDiff( + // iZone, + // selectedZone.ob, + // true // Ignore Inside ... + // ) + // : IsAboveDiff( + // iZone, + // selectedZone.ob, + // true // Ignore Inside ... + // ); + // if (!has) + // { + // continue; + // } + + // // + // has = + // selectedDemand == NULL + // ? true + // : isBullish + // ? selectedDemand.Lower() < iZone.Lower() + // : selectedDemand.Upper() > iZone.Upper(); + // if (!has) + // { + // continue; + // } + + // // + // selectedDemand = iZone; + // } + + // // + // has = selectedDemand != NULL; + // if (has) + // { + // // + // double iSL = + // isBullish + // ? selectedDemand.Lower() + // : selectedDemand.Upper(); + // double iSLDiff = MathAbs(iSL - pivot); + // has = + // iSLDiff > 0 && + // iSLDiff <= maxAllowedSLDistanceInPoint * points; + // if (has) + // { + // // + // Add( + // iSL, + // sls // + // ); + // } + // } + + // // + // Clean(tmpZones); + // ZeroMemory(selectedDemand); + // } + + // + // Support Zones ... + // has = workingZone.HasSupportZones(); + // if (has) + // { + // // + // XCSupportZone *tmpZones[]; + // Copy( + // workingZone.supportZones, + // tmpZones // + // ); + // XCSupportZone *selectedSupport = NULL; + + // // + // while (HasChild(tmpZones)) + // { + // // + // idx = GetLowest(tmpZones); + // has = IsValidIndex(idx); + // if (!has) + // { + // break; + // } + + // // + // XCSupportZone *iZone = tmpZones[idx]; + // ArrayRemove( + // tmpZones, + // idx, + // 1 // + // ); + + // // + // // Validate Zone ... + // has = + // isBullish + // ? IsBelowDiff( + // iZone, + // selectedZone.ob, + // true // Ignore Inside ... + // ) + // : IsAboveDiff( + // iZone, + // selectedZone.ob, + // true // Ignore Inside ... + // ); + // if (!has) + // { + // continue; + // } + + // // + // has = + // selectedSupport == NULL + // ? true + // : isBullish + // ? selectedSupport.Lower() < iZone.Lower() + // : selectedSupport.Upper() > iZone.Upper(); + // if (!has) + // { + // continue; + // } + + // // + // selectedSupport = iZone; + + // // + // } + + // // + // has = selectedSupport != NULL; + // if (has) + // { + // // + // double iSL = isBullish + // ? selectedSupport.Lower() + // : selectedSupport.Upper(); + // double iSLDiff = MathAbs(iSL - pivot); + // has = + // iSLDiff > 0 && + // iSLDiff <= maxAllowedSLDistanceInPoint * points; + // if (has) + // { + // // + // Add( + // iSL, + // sls // + // ); + // } + // } + + // // + // Clean(tmpZones); + // ZeroMemory(selectedSupport); + // } + + // + // Supply Zones ... + // has = workingZone.HasSupplyZones(); + // if (has) + // { + // // + // XCSupplyZone *tmpZones[]; + // Copy( + // workingZone.supplyZones, + // tmpZones // + // ); + // XCSupplyZone *selectedSupply = NULL; + + // // + // while (HasChild(tmpZones)) + // { + // // + // idx = GetHighest(tmpZones); + // has = IsValidIndex(idx); + // if (!has) + // { + // break; + // } + + // // + // XCSupplyZone *iZone = tmpZones[idx]; + // ArrayRemove( + // tmpZones, + // idx, + // 1 // + // ); + + // // + // // Validate Zone ... + // has = + // !isBullish + // ? IsAboveDiff( + // iZone, + // selectedZone.ob, + // true // Ignore Inside ... + // ) + // : IsBelowDiff( + // iZone, + // selectedZone.ob, + // true // Ignore Inside ... + // ); + // if (!has) + // { + // continue; + // } + + // // + // has = + // selectedSupply == NULL + // ? true + // : !isBullish + // ? selectedSupply.Upper() > iZone.Upper() + // : selectedSupply.Lower() < iZone.Lower(); + // if (!has) + // { + // continue; + // } + + // // + // selectedSupply = iZone; + + // // + // } + + // // + // has = selectedSupply != NULL; + // if (has) + // { + // // + // double iSL = + // !isBullish + // ? selectedSupply.Upper() + // : selectedSupply.Lower(); + // double iSLDiff = MathAbs(iSL - pivot); + // has = + // iSLDiff > 0 && + // iSLDiff <= maxAllowedSLDistanceInPoint * points; + // if (has) + // { + // // + // Add( + // iSL, + // sls // + // ); + // } + // } + + // // + // Clean(tmpZones); + // ZeroMemory(selectedSupply); + // } + + // + // Resistance Zones ... + // has = workingZone.HasDemandZones(); + // if (has) + // { + // // + // XCResistanceZone *tmpZones[]; + // Copy( + // workingZone.resistanceZones, + // tmpZones // + // ); + // XCResistanceZone *selectedResistance = NULL; + + // // + // while (HasChild(tmpZones)) + // { + // // + // idx = GetHighest(tmpZones); + // has = IsValidIndex(idx); + // if (!has) + // { + // break; + // } + + // // + // XCResistanceZone *iZone = tmpZones[idx]; + // ArrayRemove( + // tmpZones, + // idx, + // 1 // + // ); + + // // + // // Validate Zone ... + // has = + // !isBullish + // ? IsAboveDiff( + // iZone, + // selectedZone.ob, + // true // Ignore Inside ... + // ) + // : IsBelowDiff( + // iZone, + // selectedZone.ob, + // true // Ignore Inside ... + // ); + // if (!has) + // { + // continue; + // } + + // // + // has = + // selectedResistance == NULL + // ? true + // : !isBullish + // ? selectedResistance.Upper() < iZone.Upper() + // : selectedResistance.Lower() > iZone.Lower(); + // if (!has) + // { + // continue; + // } + + // // + // selectedResistance = iZone; + + // // + // } + + // // + // has = selectedResistance != NULL; + // if (has) + // { + // // + // double iSL = + // !isBullish + // ? selectedResistance.Upper() + // : selectedResistance.Lower(); + // double iSLDiff = MathAbs(iSL - pivot); + // has = + // iSLDiff > 0 && + // iSLDiff <= maxAllowedSLDistanceInPoint * points; + // if (has) + // { + // // + // Add( + // iSL, + // sls // + // ); + // } + // } + + // // + // Clean(tmpZones); + // ZeroMemory(selectedResistance); + // } + + // + // Cleanp Resources ... + + // + cBar.Clean(); + // passedBar.Clean(); + result = HasChild(sls); + + // + return result; +} + +///////////////////////////////////////////////////////////////////////// + + + // + // Support Zones ... + // has = HasSupportZones(); + // if (has) + // { + // // + // int removeIDXs[]; + // count = CountSupportZones(); + // for (int i = 0; i < count; i++) + // { + // // + // XCSupportZone *iZone = supportZones[i]; + // ENUM_X_DIRECTION iDir = X_DIRECTION_BULLISH; + + // // + // XBoxZone iBox; + // bool hasBox = ToBox( + // iBox, + // iZone // + // ); + // if (!hasBox) + // { + // // + // iBox.Clean(); + // continue; + // } + + // // + // XOHCL passedBar; + // bool isBodyIn = false; + // bool isBodyOut = false; + + // // + // // Check Activation ... + // bool isActivated = iZone.IsActivated( + // iDir, + // passedBar, + // isBodyIn, + // true, + // period // + // ); + // if (isActivated) + // { + // // + // // AddRef( + // // iBox, + // // insideBoxes // + // // ); + + // // + // Add( + // i, + // removeIDXs // + // ); + + // // + // iBox.Clean(); + // passedBar.Clean(); + // continue; + // } + + // // + // // Checking Breaked ... + // bool isBreaked = iZone.IsBreaked( + // iDir, + // passedBar, + // isBodyOut, + // false, + // true, + // period // + // ); + // if (isBreaked) + // { + // // // + // // AddRef( + // // iBox, + // // breakedBoxes // + // // ); + + // // + // Add( + // i, + // removeIDXs // + // ); + + // // + // iBox.Clean(); + // passedBar.Clean(); + // continue; + // } + + // // + // passedBar.Clean(); + // } + + // // + // count = ArraySize(removeIDXs); + // has = IsValidSize(count); + // if (has) + // { + // // + // CleanupArray( + // removeIDXs, + // supportZones // + // ); + // } + + // // + // Clean(removeIDXs); + // } + + // + // Resistance Zones ... + // has = HasResistanceZones(); + // if (has) + // { + // // + // int removeIDXs[]; + // count = CountResistanceZones(); + // for (int i = 0; i < count; i++) + // { + // // + // XCResistanceZone *iZone = resistanceZones[i]; + // ENUM_X_DIRECTION iDir = X_DIRECTION_BEARISH; + + // // + // XBoxZone iBox; + // bool hasBox = ToBox( + // iBox, + // iZone // + // ); + // if (!hasBox) + // { + // // + // iBox.Clean(); + // continue; + // } + + // // + // XOHCL passedBar; + // bool isBodyIn = false; + // bool isBodyOut = false; + + // // + // // Check Activation ... + // bool isActivated = iZone.IsActivated( + // iDir, + // passedBar, + // isBodyIn, + // true, + // period // + // ); + // if (isActivated) + // { + // // + // // AddRef( + // // iBox, + // // insideBoxes // + // // ); + + // // + // Add( + // i, + // removeIDXs // + // ); + + // // + // iBox.Clean(); + // passedBar.Clean(); + // continue; + // } + + // // + // // Checking Breaked ... + // bool isBreaked = iZone.IsBreaked( + // iDir, + // passedBar, + // isBodyOut, + // false, + // true, + // period // + // ); + // if (isBreaked) + // { + // // // + // // AddRef( + // // iBox, + // // breakedBoxes // + // // ); + + // // + // Add( + // i, + // removeIDXs // + // ); + + // // + // iBox.Clean(); + // passedBar.Clean(); + // continue; + // } + + // // + // passedBar.Clean(); + // } + + // // + // count = ArraySize(removeIDXs); + // has = IsValidSize(count); + // if (has) + // { + // // + // CleanupArray( + // removeIDXs, + // resistanceZones // + // ); + // } + + // // + // Clean(removeIDXs); + // } + + //////////////////////////////////////////////////////// + + \ No newline at end of file diff --git a/Experts/Test.mq5 b/Documents/BKP/Test.mq5 similarity index 100% rename from Experts/Test.mq5 rename to Documents/BKP/Test.mq5 diff --git a/Documents/BKP/x-121.smc.xwz.signal.class copy.mq5 b/Documents/BKP/x-121.smc.xwz.signal.class copy.mq5 new file mode 100644 index 00000000..c1e8cc27 --- /dev/null +++ b/Documents/BKP/x-121.smc.xwz.signal.class copy.mq5 @@ -0,0 +1,2124 @@ +/////////////////////////////////////////////////////// +// +// 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 ... + X121SMCStrategyXWZWorkingZone workingZone; + X121SMCStrategyXWZSignalConditions mConditions; + X121SMCStrategyXWZSignalConditions mConditionsCollection[]; + + // + // Constructor(s) ... + XCX121SMCXWZSignalDetector( + string _symbol, + ENUM_TIMEFRAMES _period // + ) + { + // + symbol = _symbol; + period = _period; + Init(); + } + + // + // Deconstructor ... + ~XCX121SMCXWZSignalDetector() + { + DeInit(); + } + + // + // + // + + // + // Detect Setup Conditions ... + bool DetectSignalSetup( + // + XC121SMCCycleHelper *decisionCycleHelper, + XC121SMCCycleHelper *analyseCycleHelper, + XC121SMCCycleHelper *consolidationCycleHelper, + XC121SMCCycleHelper *visionCycleHelper, + // + double maxAllowedSLDistanceInPoint = 300 + // + ) + { + // + bool result = false; + + // + // Validate Cycle Helpers ... + result = + // + visionCycleHelper != NULL && + analyseCycleHelper != NULL && + decisionCycleHelper != NULL && + consolidationCycleHelper != NULL + // + ; + if (!result) + { + // + mConditions.Clean(); + + // + 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; + + // + mConditions.symbol = symbol; + mConditions.period = period; + + // + double ask = GetAsk(symbol); + double bid = GetBid(symbol); + datetime cTime = TimeCurrent(); + double points = GetPoints(symbol); + + // + // Cycles Conditions ... + + // + XOHCL consolidationZBar; + result = consolidationCycleHelper.GetBar( + consolidationZBar, + zIndex // + ); + if (!result) + { + // + consolidationZBar.Clean(); + return result; + } + + // + bool drawBar = false; + if (drawBar) + { + // + DrawBar( + consolidationZBar, + decisionCycleHelper.mPOIDrawer // + ); + } + + // + // 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; + + // + // Setup Conditions ... + double sls[]; + double pivot = 0; + double point = 0; + double targets[]; + double reward = 0; + XBoxZone signalBox; + XOBFVG selectedZone; + double amountPercent = 0; + bool hasPriority = false; + bool hasSignalBox = false; + bool hasRewardAmount = false; + bool hasSelectedZone = false; + bool isSignalBoxReversal = false; + bool isSelectedZoneReversal = false; + bool hasSelectedConsolidationZone = false; + XConsolidationZone selectedConsolidationZone; + ENUM_X_DIRECTION selectedZoneDir = X_DIRECTION_NONE; + ENUM_X121SMC_XWZ_PRIORITY priority = X121SMC_XWZ_PRIORITY_NONE; + ENUM_X121SMC_XWZ_PROVIDERS provider = X121SMC_XWZ_PROVIDER_NONE; + + // + // First We Have to Has Working Zone ... + bool hasWorkingZone = workingZone.IsValid(); + if (!hasWorkingZone) + { + // + hasWorkingZone = workingZone.Init( + symbol, + period, + zIndex, + visionState, + consolidationState, + analyseState, + decisionState // + ); + } + + // + if (hasWorkingZone) + { + // + visionCycleHelper.mPOIDetector.MaxRequiredPOIs(50); + analyseCycleHelper.mPOIDetector.MaxRequiredPOIs(50); + decisionCycleHelper.mPOIDetector.MaxRequiredPOIs(50); + consolidationCycleHelper.mPOIDetector.MaxRequiredPOIs(50); + + // + visionCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(578); + analyseCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(578); + decisionCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(578); + consolidationCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(578); + + // + workingZone.Update( + zIndex, + visionState, + consolidationState, + analyseState, + decisionState // + ); + } + + // + bool hasWaitingZones = hasWorkingZone && + workingZone.HasWaitingZones(); + + // + // + // + + // + // Check Conditions if Has Inside Zones ... + bool hasInsideZones = hasWorkingZone && + workingZone.HasInsideZones(); + if (hasInsideZones) + { + // + int selectedIDX = -1; + int count = workingZone.CountInsideZones(); + for (int i = 0; i < count; i++) + { + // + bool has = DetectSelectedZoneConditions( + isSelectedZoneReversal, + workingZone.insideZones[i], + decisionState, + decisionXConditions // + ); + + // + if (has) + { + // + selectedIDX = i; + selectedZone = workingZone.insideZones[i]; + + // + break; + } + } + + // + if (IsValidIndex(selectedIDX)) + { + // + ArrayRemove( + workingZone.insideZones, + selectedIDX, + 1 // + ); + + // + hasSelectedZone = selectedZone.IsValid(); + provider = X121SMC_XWZ_PROVIDER_PRICE_INSIDE_ZONE; + } + } + + // + // Check Conditions if Has Breaked Zones ... + // bool hasBreakedZones = hasWorkingZone && + // workingZone.HasBreakedZones(); + // if (hasBreakedZones) + // { + // // + // if (!hasSelectedZone) + // { + // // + // int selectedIDX = -1; + // int count = workingZone.CountBreakedZones(); + // for (int i = 0; i < count; i++) + // { + // // + // bool has = DetectSelectedZoneConditions( + // isSelectedZoneReversal, + // workingZone.breakedZones[i], + // decisionState, + // decisionXConditions // + // ); + + // // + // if (has) + // { + // // + // selectedIDX = i; + // selectedZone = workingZone.breakedZones[i]; + + // // + // break; + // } + // } + + // // + // if (IsValidIndex(selectedIDX)) + // { + // // + // ArrayRemove( + // workingZone.breakedZones, + // selectedIDX, + // 1 // + // ); + + // // + // hasSelectedZone = selectedZone.IsValid(); + // provider = X121SMC_XWZ_PROVIDER_ACTIVATED_ZONE; + // } + // } + // } + + // + // + // + + // + bool hasInsideBoxes = hasWorkingZone && + workingZone.HasInsideBoxes(); + if (hasInsideBoxes) + { + // + XOHCL zBar; + XOHCL cBar; + int count = 0; + bool has = false; + XBoxZone tmpSelectedBox; + int tmpSelectedBoxIDX = -1; + + // + has = zBar.Init( + symbol, + period, + zIndex // + ); + has = has && + zBar.GetPreviousBar(cBar); + if (has) + { + // + count = workingZone.CountInsideBoxes(); + for (int i = 0; i < count; i++) + { + // + tmpSelectedBox = workingZone.insideBoxes[i]; + + // + bool isBullish = tmpSelectedBox.IsBullish(); + bool isBearish = tmpSelectedBox.IsBearish(); + + // + bool hasFiboPressure = + visionCycleHelper + .mBarAnalyser + .HasFiboPressure( + cBar, + tmpSelectedBox.dir, + X_FIBO_LEVEL_382 // + ); + + // + bool isBullishRejectedUpper = + cBar.low < tmpSelectedBox.upper && + cBar.GetDown() > tmpSelectedBox.upper; + + // + bool isBullishRejectedLower = + cBar.low < tmpSelectedBox.lower && + cBar.GetDown() > tmpSelectedBox.lower; + + // + bool isBearishRejectedUpper = + cBar.high > tmpSelectedBox.upper && + cBar.GetUp() < tmpSelectedBox.upper; + + // + bool isBearishRejectedLower = + cBar.high > tmpSelectedBox.lower && + cBar.GetUp() < tmpSelectedBox.lower; + + // + bool isBullishRejected = + // isBullishRejectedUpper || + isBullishRejectedLower; + + // + bool isBearishRejected = + isBearishRejectedUpper + // || isBearishRejectedLower + ; + + // + bool isMaWapBullish = + // + (decisionXConditions.isX3MaBullishState && + decisionXConditions.isX3MaBullishOrdered) + // + && + // + (decisionXConditions.isVWapBullishState && + decisionXConditions.isVWapBullishOrdered) + // + ; + + // + bool isMaWapBearish = + // + (decisionXConditions.isX3MaBearishState && + decisionXConditions.isX3MaBearishOrdered) + // + && + // + (decisionXConditions.isVWapBearishState && + decisionXConditions.isVWapBearishOrdered) + // + ; + + // + bool isX2MaWapInside = + // + (decisionXConditions.x3maFastBuffer[cIndex] < tmpSelectedBox.upper && + decisionXConditions.x3maMidBuffer[cIndex] < tmpSelectedBox.upper && + decisionXConditions.x3maFastBuffer[cIndex] > tmpSelectedBox.lower && + decisionXConditions.x3maMidBuffer[cIndex] > tmpSelectedBox.lower) + // + && + // + (decisionXConditions.vwapFastBuffer[cIndex] < tmpSelectedBox.upper && + decisionXConditions.vwapMidBuffer[cIndex] < tmpSelectedBox.upper && + decisionXConditions.vwapFastBuffer[cIndex] > tmpSelectedBox.lower && + decisionXConditions.vwapMidBuffer[cIndex] > tmpSelectedBox.lower) + // + ; + + // + bool isBullishConditions = + // + isBullish && + isMaWapBearish && + isX2MaWapInside && + hasFiboPressure && + isBullishRejected && + cBar.low < cBar.GetDown() + // + ; + + // + bool isBearishConditions = + // + isBearish && + isMaWapBullish && + isX2MaWapInside && + hasFiboPressure && + isBearishRejected && + cBar.high > cBar.GetUp() + // + ; + + // + has = isBullishConditions || + isBearishConditions; + if (!has) + { + // + tmpSelectedBox.Clean(); + continue; + } + + // + tmpSelectedBoxIDX = i; + signalBox = tmpSelectedBox; + + // + tmpSelectedBox.Clean(); + break; + } + } + + // + isSignalBoxReversal = false; + hasSignalBox = signalBox.IsValid(); + if (hasSignalBox) + { + // + ArrayRemove( + workingZone.insideBoxes, + tmpSelectedBoxIDX, + 1 // + ); + } + + // + zBar.Clean(); + cBar.Clean(); + tmpSelectedBox.Clean(); + } + + // + bool hasBreakedBoxes = hasWorkingZone && + workingZone.HasBreakedBoxes(); + if (hasBreakedBoxes) + { + } + + // + if (!hasSignalBox) + { + } + + // + // + // + + // + // Double Check and Prepare Signal Conditions ... + // including Targets and SLs ... + + // + if (hasSelectedZone) + { + // + int idx = -1; + bool has = false; + + // + // Check Consolidation Zones for SL Handling ... + selectedZoneDir = + !isSelectedZoneReversal + ? selectedZone.GetDirection() + : Opposit(selectedZone.GetDirection()); + bool isSelectedZonDirBullish = IsBullish(selectedZoneDir); + + // + if (isSelectedZoneReversal) + { + provider = X121SMC_XWZ_PROVIDER_ACTIVATED_CHOCH; + } + + // + // Calculate Priority ... + hasPriority = + hasWorkingZone && + workingZone + .DetectPriority( + priority, + selectedZoneDir, + zIndex, + period // + ); + + // + // Calculate Risk Reward Ration based on Priority ... + hasRewardAmount = CalculateRiskReward( + priority, + reward, + amountPercent // + ); + + // + // Calculate Pivot and Point ... + + // + pivot = + isSelectedZonDirBullish + ? selectedZone.ob.Lower() + : selectedZone.ob.Upper(); + + // + point = + isSelectedZonDirBullish + ? selectedZone.ob.Upper() + : selectedZone.ob.Lower(); + + // + // Detect Targets ... + DetectSelectedZonesTargets( + targets, + selectedZone, + selectedZoneDir, + priority, + workingZone, + zIndex // + ); + + // + // Detect SLs ... + double iAtr = decisionXConditions.atrBuffer[0]; + iAtr *= 1.5; + + // + // Default SL is Pivot ... + if (pivot > 0) + { + // + Add( + pivot, + sls // + ); + + // + double iSL = iAtr * pivot; + Add( + iSL, + sls // + ); + } + + // + DetectSelectedZoneSLCandidates( + sls, + selectedZone, + selectedZoneDir, + workingZone, + decisionXConditions, + zIndex, + maxAllowedSLDistanceInPoint // + ); + + // + // Summaries Conditions ... + result = + pivot > 0 && + point > 0 && + hasPriority && + hasRewardAmount && + HasDirection(selectedZoneDir); + if (result) + { + // + isBullish = IsBullish(selectedZoneDir); + isBearish = IsBearish(selectedZoneDir); + + // + Copy( + sls, + mConditions.sls // + ); + Copy( + targets, + mConditions.targets // + ); + + // + mConditions.pivot = pivot; + mConditions.point = point; + mConditions.reward = reward; + mConditions.setupTime = cTime; + mConditions.priority = priority; + mConditions.provider = provider; + mConditions.dir = selectedZoneDir; + mConditions.signalBox = signalBox; + mConditions.amountPercent = amountPercent; + } + + // + // Cleanup Resources ... + + // + Clean(sls); + Clean(targets); + selectedZone.Clean(); + selectedConsolidationZone.Clean(); + } + + // + if (hasSignalBox) + { + // // + // workingZone.mInsideZoneObjects.Clear(); + // workingZone.mBreakedZoneObjects.Clear(); + // workingZone.mWaitingZoneObjects.Clear(); + // workingZone.mWorkingZoneObjects.Clear(); + + // // + // XCBoxObject *iObj; + // signalBox.to = cTime; + // bool isCreated = drawer.CreateBox( + // signalBox, + // iObj // + // ); + + // // + // if (isCreated) + // { + // // + // iObj.BoxWidth(2); + // iObj.BoxColor(clrYellow); + // iObj.BoxStyle(STYLE_SOLID); + // } + + // // + // bool isSignalBoxBullishDir = signalBox.IsBullish(); + + // // + // // Calculate Priority ... + // hasPriority = + // hasWorkingZone && + // workingZone + // .DetectPriority( + // priority, + // signalBox.dir, + // zIndex, + // period // + // ); + + // // + // // Calculate Risk Reward Ration based on Priority ... + // hasRewardAmount = CalculateRiskReward( + // priority, + // reward, + // amountPercent // + // ); + + // // + // // Calculate Pivot and Point ... + + // // + // pivot = + // isSignalBoxBullishDir + // ? signalBox.lower + // : signalBox.upper; + + // // + // point = + // isSignalBoxBullishDir + // ? signalBox.upper + // : signalBox.lower; + + // // + // double defaultTarget = + // isSignalBoxBullishDir + // ? signalBox.upper + // : signalBox.lower; + // Add( + // defaultTarget, + // targets // + // ); + + // // + // // Detect SLs ... + // double iAtr = decisionXConditions.atrBuffer[0]; + // iAtr *= 1.5; + + // // + // double defaultSL = + // isSignalBoxBullishDir + // ? decisionXConditions.valesBuffer[0] - iAtr + // : decisionXConditions.peaksBuffer[0] + iAtr; + + // // + // Add( + // defaultSL, + // sls // + // ); + + // // + // // Summaries Conditions ... + // result = + // pivot > 0 && + // point > 0 && + // hasPriority && + // hasRewardAmount; + // if (result) + // { + // // + // isBullish = signalBox.IsBullish(); + // isBearish = signalBox.IsBearish(); + + // // + // Copy( + // sls, + // mConditions.sls // + // ); + // Copy( + // targets, + // mConditions.targets // + // ); + + // // + // mConditions.pivot = pivot; + // mConditions.point = point; + // mConditions.reward = reward; + // mConditions.setupTime = cTime; + // mConditions.priority = priority; + // mConditions.provider = provider; + // mConditions.dir = signalBox.dir; + // mConditions.signalBox = signalBox; + // mConditions.amountPercent = amountPercent; + // } + + // // + // signalBox.Clean(); + // hasSignalBox = false; + } + + // + UpdateTo(cTime); + + // + // Draw Working Zone ... + if (hasWorkingZone) + { + // + workingZone.Draw( + drawer, + true, // Draw Waiting Zones ... + true, // Draw Inside Zones ... + true, // Draw Breaked Zones ... + true, // Draw Supply Zone ... + true, // Draw Demand Zone ... + false, // Draw Supply Zones ... + false, // Draw Demand Zones ... + false, // Draw Support Zones ... + false // Draw Resistance Zones ... + ); + + // + // XCBaseObject *objects[]; + // drawer.DrawState( + // decisionState, + // objects, + // false, // DrawT icksZone ... + // true, // Ignore SwingHighs ... + // true, // Ignore SwingLows ... + // true, // Ignore SupportZones ... + // true, // Ignore ResistanceZones ... + // true, // Ignore SupplyZones ... + // true, // Ignore DemandZones ... + // true, // Ignore BullishOrderBlocks ... + // true, // Ignore BearishOrderBlocks ... + // true, // Ignore BullishFairValueGaps ... + // true, // Ignore BearishFairValueGaps ... + // true, // Ignore BullishRejectionBars ... + // true, // Ignore BearishRejectionBars ... + // true, // Ignore BullishMomentumBars ... + // true, // Ignore BearishMomentumBars ... + // true, // Ignore BullishConsolidationZones ... + // true // Ignore BearishConsolidationZones ... + // ); + + // // + // int count = 0; + // bool has = false; + + // // + // has = workingZone.HasSupplyZones(); + // if (has) + // { + // } + + // // + // has = workingZone.HasDemandZones(); + // if (has) + // { + // // + // count = workingZone.CountDemandZones(); + // for (int i = 0; i < count; i++) + // { + // // + // XCDemandZone *iZone = workingZone.demandZones[i]; + + // // + // XCDemandZoneObject *iObj; + // bool isCreated = drawer.CreateDemandZone( + // iZone, + // iObj // + // ); + // } + // } + + // // + // Print(""); + } + + // + // 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(); + + // + consolidationZBar.Clean(); + + // + return result; + } + + // + // Detect Trigger Conditions ... + bool DetectSignalTrigger( + // + X121SMCStrategyXWZSignalConditions &conditions, + // + 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; + + // + 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) + { + // + // 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]; + iAtr *= 1.5; + + // + // Check Signal Validation ... + // IMPORTANT: since all Validations done in SetUp Process ... + // here we only Execute Signal ... + + // + result = isBullish || + isBearish; + + // + if (result) + { + // + // Retrieve Entry Price ... + double entry = GetEntry( + conditions.symbol, + setupDir // + ); + + // + // Select and Apply SL ... + + // + double slsMin = GetMin(conditions.sls); + double slsMax = GetMax(conditions.sls); + + // + double longSL = slsMin; + double shortSL = slsMax; + + // + double sl = isBullish + ? longSL + : shortSL; + + // + conditions.sl = sl; + conditions.triggerTime = cTime; + conditions.type = isBullish + ? X_POSITION_TYPE_LONG + : X_POSITION_TYPE_SHORT; + + // + } + + // + // Cleanup ... + + // + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + + // + decisionState.Clean(); + decisionConditions.Clean(); + decisionXConditions.Clean(); + + // + Clean(analysePoiEvents); + Clean(analyseCycleEvents); + + // + analyseState.Clean(); + analyseConditions.Clean(); + analyseXConditions.Clean(); + + // + return result; + } + + // + // Detect Guards ... + bool DetectGuards( + // + X121SMCGuard &guards[], + const XPosition &positions[], + // + XC121SMCCycleHelper *decisionCycleHelper, + XC121SMCCycleHelper *analyseCycleHelper, + XC121SMCCycleHelper *consolidationCycleHelper, + XC121SMCCycleHelper *visionCycleHelper + // + ) + { + // + bool result = false; + return false; + + // + Clean(guards); + + // + bool isCycleHelpersValid = + // + visionCycleHelper != NULL && + analyseCycleHelper != NULL && + decisionCycleHelper != NULL && + consolidationCycleHelper != NULL + // + ; + + // + // Set Provider for Common Guards ... + string provider = ToString(X_121_SMC_PROVIDER_XWZ); + + // + // Check Cycle Helpers Validation ... + result = isCycleHelpersValid; + if (!result) + { + return result; + } + + // + // Select Own Positions ... + int count = ArraySize(positions); + result = IsValidSize(count); + if (!result) + { + return result; + } + + // + 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 // + ); + } + } + } + + // + // Check Extracted Positions ... + + // + count = ArraySize(ownPositions); + + // + int longsCount = ArraySize(ownLongPositions); + bool hasLongs = IsValidSize(longsCount); + + // + int shortsCount = ArraySize(ownShortPositions); + bool hasShorts = IsValidSize(shortsCount); + + // + // Validate Own Positions ... + 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 + // + ); + + // + // + // + + // + // Implement 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; + + // + 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 ... + + // + int idx = -1; + bool has = false; + + // + bool hasBullishConsolidationZone = false; + XConsolidationZone bullishConsolidationZone; + has = decisionState.HasBullishConsolidationZones(); + if (has) + { + // + idx = GetYoungest(decisionState.bullishConsolidationZones); + hasBullishConsolidationZone = IsValidIndex(idx); + if (hasBullishConsolidationZone) + { + bullishConsolidationZone = decisionState.bullishConsolidationZones[idx]; + } + } + + // + bool hasBearishConsolidationZone = false; + XConsolidationZone bearishConsolidationZone; + has = decisionState.HasBearishConsolidationZones(); + if (has) + { + // + idx = GetYoungest(decisionState.bearishConsolidationZones); + hasBearishConsolidationZone = IsValidIndex(idx); + if (hasBearishConsolidationZone) + { + bearishConsolidationZone = decisionState.bearishConsolidationZones[idx]; + } + } + + // + // 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 ... + bool handleStoptrailingBasedOnConsolidationZones = true; + for (int i = 0; i < count; i++) + { + // + XPosition iPosition = ownPositions[i]; + + // + bool isLong = IsLong(iPosition.type); + bool isInProfit = iPosition.profit > 0; + + // + double sl = iPosition.sl; + double tp = iPosition.tp; + + // + // Trail Stops Using Consolidation Zones ... + + // + bool canTraiLonglUsingCZone = + // + handleStoptrailingBasedOnConsolidationZones && + // + (isLong && + isInProfit && + hasBullishConsolidationZone && + bullishConsolidationZone.lower > iPosition.sl && + bullishConsolidationZone.lower > iPosition.entry) + // + ; + if (canTraiLonglUsingCZone) + { + sl = bullishConsolidationZone.lower; + } + + // + bool canTraiShortlUsingCZone = + // + handleStoptrailingBasedOnConsolidationZones && + // + (!isLong && + isInProfit && + hasBearishConsolidationZone && + bearishConsolidationZone.upper < iPosition.sl && + bearishConsolidationZone.upper < iPosition.entry) + // + ; + if (canTraiShortlUsingCZone) + { + sl = bearishConsolidationZone.upper; + } + + // + bool canTrailUsingCZone = + canTraiLonglUsingCZone || + canTraiShortlUsingCZone; + + // + bool isSLPassed = + sl > 0 && + (isLong + ? iPosition.price - sl >= points * 15 + : sl - iPosition.price >= points * 15); + + // + bool canTrail = + isSLPassed && + canTrailUsingCZone; + if (canTrail) + { + // + 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 = sl; + + // + AddGuard( + iGuard, + guards // + ); + } + } + + // + // 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); + + // + 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); + + // + 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 DrawBar( + XOHCL &bar, + XCPOIDrawer *drawer, + bool forceClean = true // + ) + { + // + if (forceClean) + { + mBarObjects.Clear(); + } + + // + if (drawer == NULL || + !bar.IsValid()) + { + return; + } + + // + bool isBullish = bar.IsBullish(); + + // + int widthBar = 2; + bool fillShadowsBar = true; + ENUM_LINE_STYLE styleBar = STYLE_SOLID; + color clrBar = + isBullish + ? clrAqua + : clrMagenta; + + // + datetime to = bar.NextAt(); + + // + XCOHCLObject *iObj; + bool isCreated = drawer + .CreateBar( + bar, + iObj, + to // + ); + if (isCreated) + { + // + iObj.BarSpes( + widthBar, + clrBar, + styleBar // + ); + + // + iObj.LowShadowFill(fillShadowsBar); + iObj.HighShadowFill(fillShadowsBar); + + // + mBarObjects.Add(iObj); + } + } + + // + protected: + // + + // + private: + // + // Props ... + string symbol; + ENUM_TIMEFRAMES period; + CArrayObj mObjects; + CArrayObj mBarObjects; + CArrayObj mWorkingZoneObjects; + + /** + * Initialize ... + */ + void Init() + { + } + + /** + * DeInitialize ... + */ + void DeInit() + { + // + mConditions.Clean(); + workingZone.Clean(); + Clean(mConditionsCollection); + + // + mBarObjects.Clear(); + } + + /** + * Update To Time of Exists Components ... + * + * @param value: updated time ... + */ + void UpdateTo( + datetime value = NULL // + ) + { + // + value = NormalizeTime(value); + + // + workingZone.UpdateTo(value); + } + + // + // Helpers ... + + // + 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_STRONG_HIGH: + // + reward = 6; + amountPercent = 2; + break; + + // + case X121SMC_XWZ_PRIORITY_HIGH: + // + reward = 4; + amountPercent = 2; + break; + + // + case X121SMC_XWZ_PRIORITY_REGULAR: + // + reward = 3; + amountPercent = 1.5; + break; + + // + case X121SMC_XWZ_PRIORITY_LOW: + // + reward = 2; + amountPercent = 1; + break; + + // + case X121SMC_XWZ_PRIORITY_WEAK: + // + reward = 1; + amountPercent = 0.5; + break; + } + + // + result = + // + reward > 0 && + amountPercent > 0 + // + ; + + // + return result; + } + + // +}; + +// \ No newline at end of file diff --git a/Documents/BKP/x-121.smc.xwz.signal.lib copy.mq5 b/Documents/BKP/x-121.smc.xwz.signal.lib copy.mq5 new file mode 100644 index 00000000..fd0c9ab4 --- /dev/null +++ b/Documents/BKP/x-121.smc.xwz.signal.lib copy.mq5 @@ -0,0 +1,4871 @@ +/////////////////////////////////////////////////////// +// +// 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_PROVIDERS +{ + X121SMC_XWZ_PROVIDER_NONE, + X121SMC_XWZ_PROVIDER_ACTIVATED_ZONE, + X121SMC_XWZ_PROVIDER_ACTIVATED_CHOCH, + X121SMC_XWZ_PROVIDER_PRICE_INSIDE_ZONE, +}; + +// +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, + X121SMC_XWZ_PRIORITY_STRONG_HIGH, +}; + +// +struct X121SMCStrategyXWZWorkingZone +{ + // + // Props ... + + // + string symbol; + ENUM_TIMEFRAMES period; + + // + double quarter1; + double quarter2; + double quarter3; + + // + XCSupplyZone *supplyZone; + XCDemandZone *demandZone; + + // + XCSupplyZone *supplyZones[]; + XCDemandZone *demandZones[]; + + // + XCSupportZone *supportZones[]; + XCResistanceZone *resistanceZones[]; + + // + XOBFVG insideZones[]; + XOBFVG breakedZones[]; + XOBFVG waitingZones[]; + + // + XBoxZone insideBoxes[]; + XBoxZone breakedBoxes[]; + XConsolidationZone consolidationZones[]; + + // + CArrayObj mInsideZoneObjects; + CArrayObj mBreakedZoneObjects; + CArrayObj mWaitingZoneObjects; + CArrayObj mWorkingZoneObjects; + + // + // Constructor ... + X121SMCStrategyXWZWorkingZone() + { + Clean(); + } + + // + // Tools ... + + // + void Clean() + { + // + quarter1 = 0; + quarter2 = 0; + quarter3 = 0; + + // + symbol = NULL; + period = NULL; + + // + Clean(supplyZones); + Clean(demandZones); + + // + Clean(insideZones); + Clean(waitingZones); + Clean(breakedZones); + + // + Clean(insideBoxes); + Clean(breakedBoxes); + + // + Clean(supportZones); + Clean(resistanceZones); + + // + ZeroMemory(supplyZone); + ZeroMemory(demandZone); + + // + mInsideZoneObjects.Clear(); + mBreakedZoneObjects.Clear(); + mWaitingZoneObjects.Clear(); + mWorkingZoneObjects.Clear(); + } + + // + bool IsValid() + { + // + bool result = false; + + // + result = + // + quarter1 > 0 && + quarter2 > 0 && + quarter3 > 0 && + HasSupplyZone() && + HasDemandZone() && + quarter1 > quarter2 && + quarter2 > quarter3 + // + ; + + // + return result; + } + + // + bool Init( + string _symbol, + ENUM_TIMEFRAMES _period, + int barIndex, + XPOIState &htfState, + XPOIState &mtfState, + XPOIState &stfState, // + XPOIState &ttfState // + ) + { + // + bool result = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + result = + // + IsValid(_symbol) && + IsValid(_period) && + // + htfState.IsValid() && + mtfState.IsValid() && + stfState.IsValid() && + ttfState.IsValid() && + // + htfState.HasChild() && + mtfState.HasChild() && + stfState.HasChild() && + ttfState.HasChild() + // + ; + if (!result) + { + return result; + } + + // + symbol = _symbol; + period = _period; + + // + int idx = -1; + int count = 0; + bool has = false; + + // + XOHCL zBar; + has = zBar.Init( + symbol, + period, + barIndex // + ); + result = has; + if (!result) + { + zBar.Clean(); + return result; + } + double ll5 = zBar.FindLowest(5, MODE_LOW); + double hh5 = zBar.FindHighest(5, MODE_HIGH); + zBar.Clean(); + + // + // Supply Zone ... + has = HasSupplyZone(); + if (!has) + { + // + idx = GetHighest(htfState.supplyZones); + has = IsValidIndex(idx); + if (has) + { + // + supplyZone = htfState.supplyZones[idx]; + has = hh5 < supplyZone.Lower(); + if (!has) + { + supplyZone = NULL; + } + } + } + + // + // Demand Zone ... + has = HasDemandZone(); + if (!has) + { + // + idx = GetLowest(htfState.demandZones); + has = IsValidIndex(idx); + if (has) + { + // + demandZone = htfState.demandZones[idx]; + has = ll5 > demandZone.Upper(); + if (!has) + { + demandZone = NULL; + } + } + } + + // + // Supply Zones ... + has = HasSupplyZones(); + if (!has) + { + // + count = mtfState.FilterSupplyZones( + supplyZones, + period, + XZONE_STATE_PASSED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_IGNORED, + false // + ); + } + + // + // Demand Zones ... + has = HasDemandZones(); + if (!has) + { + // + count = mtfState.FilterDemandZones( + demandZones, + period, + XZONE_STATE_PASSED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_IGNORED, + false // + ); + } + + // // + // // Support Zones ... + // has = HasSupportZones(); + // if (!has) + // { + // // + // count = stfState.FilterSupportZones( + // supportZones, + // period, + // XZONE_STATE_PASSED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_IGNORED, + // false // + // ); + // } + + // // + // // Resistance Zones ... + // has = HasResistanceZones(); + // if (!has) + // { + // // + // count = stfState.FilterResistanceZones( + // resistanceZones, + // period, + // XZONE_STATE_PASSED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_IGNORED, + // false // + // ); + // } + + // + has = ttfState.HasConsolidationZones(); + if (has) + { + // + Copy( + ttfState.consolidationZones, + consolidationZones // + ); + CleanupArray( + consolidationZones, + 50 // + ); + } + + // + if (supplyZone != NULL && + demandZone != NULL && + supplyZone.IsValid() && + demandZone.IsValid()) + { + // + double upper = supplyZone.Lower(); + double lower = demandZone.Upper(); + + // + double delta = ((upper - lower) / 100) * 25; + + // + quarter1 = upper - (1 * delta); + quarter2 = upper - (2 * delta); + quarter3 = upper - (3 * delta); + } + + // + // Detect OBFVG(s) ... + ExtractOBFVGs( + waitingZones, + mtfState, + stfState + // , + // X_OBFVG_FVG_FILTER_ABOVE_BELOW, + // X_OBFVG_FVG_SELECT_HIGHEST_LOWEST // + ); + + // // + // // Detect Waiting Zones based on STF and TTF ... + // XOBFVG tmpWaitingZones[]; + // count = ExtractOBFVGs( + // tmpWaitingZones, + // stfState, + // stfState // + // ); + // has = IsValidSize(count); + // if (has) + // { + // // + // for (int i = 0; i < count; i++) + // { + // // + // XOBFVG iOBFVG = tmpWaitingZones[i]; + + // // + // idx = FindIndex( + // iOBFVG, + // waitingZones // + // ); + // has = IsValidIndex(idx); + // if (has) + // { + // // + // iOBFVG.Clean(); + // continue; + // } + + // // + // AddRef( + // iOBFVG, + // waitingZones // + // ); + + // // + // iOBFVG.Clean(); + // } + // } + + // + result = IsValid(); + if (!result) + { + Clean(); + } + + // + return result; + } + + // + void Update( + int barIndex, + XPOIState &htfState, + XPOIState &mtfState, + XPOIState &stfState, + XPOIState &ttfState // + ) + { + // + int idx = -1; + int count = 0; + bool has = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + has = + // + IsValid() && + // + htfState.IsValid() && + mtfState.IsValid() && + stfState.IsValid() && + // + htfState.HasChild() && + mtfState.HasChild() && + stfState.HasChild() + // + ; + if (!has) + { + return; + } + + // + XOHCL zBar; + has = zBar.Init( + symbol, + period, + barIndex // + ); + if (!has) + { + // + zBar.Clean(); + return; + } + + // + XOHCL cBar; + has = zBar.GetPreviousBar(cBar); + if (!has) + { + // + zBar.Clean(); + cBar.Clean(); + + // + return; + } + + // + // Adding New OBFVG to Waiting Zones if not Exists ... + XOBFVG tmpWaitingZones[]; + count = ExtractOBFVGs( + tmpWaitingZones, + mtfState, + stfState + // , + // X_OBFVG_FVG_FILTER_ABOVE_BELOW, + // X_OBFVG_FVG_SELECT_HIGHEST_LOWEST // + ); + has = IsValidSize(count); + if (has) + { + // + AddIfNotExists( + tmpWaitingZones, + waitingZones // + ); + } + + // + // Detect Waiting Zones based on STF and TTF ... + // Clean(tmpWaitingZones); + // count = ExtractOBFVGs( + // tmpWaitingZones, + // stfState, + // ttfState // + // ); + // has = IsValidSize(count); + // if (has) + // { + // // + // AddIfNotExists( + // tmpWaitingZones, + // waitingZones // + // ); + // } + + // + // Detect Waiting Zones based on TTF and TTF ... + // Clean(tmpWaitingZones); + // count = ExtractOBFVGs( + // tmpWaitingZones, + // stfState, + // stfState // + // ); + // has = IsValidSize(count); + // if (has) + // { + // // + // AddIfNotExists( + // tmpWaitingZones, + // waitingZones // + // ); + // } + + // + // Since Usig States for Extracting Supply/Demand or + // Support/Resistance Zones and State's has Max Alllowed Restrication ... + // we have to Manage new Zones and also Hold's Breaked Zones ... + + // + // MTF STF ... + + // + // Supply Zones ... + XCSupplyZone *tmpSupplies[]; + count = mtfState.FilterSupplyZones( + tmpSupplies, + NULL, + XZONE_STATE_PASSED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_IGNORED, + false // + ); + has = IsValidSize(count); + if (has) + { + // + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox; + has = ToBox( + iBox, + tmpSupplies[i] // + ); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + // Find Index ... + + // + idx = FindIndex( + iBox, + insideBoxes // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + idx = FindIndex( + iBox, + breakedBoxes // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + idx = FindIndex( + tmpSupplies[i], + supplyZones // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + // Checking Price Validation ... + has = cBar.high < tmpSupplies[i].Lower(); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + Add( + tmpSupplies[i], + supplyZones // + ); + + // + iBox.Clean(); + } + } + Clean(tmpSupplies); + + // + // Demand Zones ... + XCDemandZone *tmpDemands[]; + count = mtfState.FilterDemandZones( + tmpDemands, + NULL, + XZONE_STATE_PASSED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_IGNORED, + false // + ); + has = IsValidSize(count); + if (has) + { + // + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox; + has = ToBox( + iBox, + tmpDemands[i] // + ); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + // Find Index ... + + // + idx = FindIndex( + iBox, + insideBoxes // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + idx = FindIndex( + iBox, + breakedBoxes // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + idx = FindIndex( + tmpDemands[i], + demandZones // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + // Checking Price Validation ... + has = cBar.low > tmpDemands[i].Upper(); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + Add( + tmpDemands[i], + demandZones // + ); + + // + iBox.Clean(); + } + } + Clean(tmpDemands); + + // // + // // Support Zones ... + // XCSupportZone *tmpSupports[]; + // count = stfState.FilterSupportZones( + // tmpSupports, + // period, + // XZONE_STATE_PASSED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_IGNORED, + // false // + // ); + // has = IsValidSize(count); + // if (has) + // { + // // + // for (int i = 0; i < count; i++) + // { + // // + // XBoxZone iBox; + // has = ToBox( + // iBox, + // tmpSupports[i] // + // ); + // if (!has) + // { + // // + // iBox.Clean(); + // continue; + // } + + // // + // // Find Index ... + + // // + // idx = FindIndex( + // iBox, + // insideBoxes // + // ); + // has = !IsValidIndex(idx); + // if (!has) + // { + // // + // iBox.Clean(); + // continue; + // } + + // // + // idx = FindIndex( + // iBox, + // breakedBoxes // + // ); + // has = !IsValidIndex(idx); + // if (!has) + // { + // // + // iBox.Clean(); + // continue; + // } + + // // + // idx = FindIndex( + // tmpSupports[i], + // supportZones // + // ); + // has = !IsValidIndex(idx); + // if (!has) + // { + // // + // iBox.Clean(); + // continue; + // } + + // // + // // Checking Price Validation ... + // has = cBar.low > tmpSupports[i].Upper(); + // if (!has) + // { + // // + // iBox.Clean(); + // continue; + // } + + // // + // Add( + // tmpSupports[i], + // supportZones // + // ); + + // // + // iBox.Clean(); + // } + // } + // Clean(tmpSupports); + + // // + // // Resistance Zones .. + // XCResistanceZone *tmpResistances[]; + // count = stfState.FilterResistanceZones( + // tmpResistances, + // period, + // XZONE_STATE_PASSED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_IGNORED, + // false // + // ); + // has = IsValidSize(count); + // if (has) + // { + // // + // for (int i = 0; i < count; i++) + // { + // // + // XBoxZone iBox; + // has = ToBox( + // iBox, + // tmpResistances[i] // + // ); + // if (!has) + // { + // // + // iBox.Clean(); + // continue; + // } + + // // + // // Find Index ... + + // // + // idx = FindIndex( + // iBox, + // insideBoxes // + // ); + // has = !IsValidIndex(idx); + // if (!has) + // { + // // + // iBox.Clean(); + // continue; + // } + + // // + // idx = FindIndex( + // iBox, + // breakedBoxes // + // ); + // has = !IsValidIndex(idx); + // if (!has) + // { + // // + // iBox.Clean(); + // continue; + // } + + // // + // idx = FindIndex( + // tmpResistances[i], + // resistanceZones // + // ); + // has = !IsValidIndex(idx); + // if (!has) + // { + // // + // iBox.Clean(); + // continue; + // } + + // // + // // Checking Price Validation ... + // has = cBar.high < tmpResistances[i].Lower(); + // if (!has) + // { + // // + // iBox.Clean(); + // continue; + // } + + // // + // Add( + // tmpResistances[i], + // resistanceZones // + // ); + + // // + // iBox.Clean(); + // } + // } + // Clean(tmpResistances); + + // + // STF TTF ... + + // // + // // Supply Zones ... + // count = stfState.FilterSupplyZones( + // tmpSupplies, + // NULL, + // XZONE_STATE_PASSED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_IGNORED, + // false // + // ); + // has = IsValidSize(count); + // if (has) + // { + // // + // for (int i = 0; i < count; i++) + // { + // // + // XBoxZone iBox; + // has = ToBox( + // iBox, + // tmpSupplies[i] // + // ); + // if (!has) + // { + // // + // iBox.Clean(); + // continue; + // } + + // // + // // Find Index ... + + // // + // idx = FindIndex( + // iBox, + // insideBoxes // + // ); + // has = !IsValidIndex(idx); + // if (!has) + // { + // // + // iBox.Clean(); + // continue; + // } + + // // + // idx = FindIndex( + // iBox, + // breakedBoxes // + // ); + // has = !IsValidIndex(idx); + // if (!has) + // { + // // + // iBox.Clean(); + // continue; + // } + + // // + // idx = FindIndex( + // tmpSupplies[i], + // supplyZones // + // ); + // has = !IsValidIndex(idx); + // if (!has) + // { + // // + // iBox.Clean(); + // continue; + // } + + // // + // // Checking Price Validation ... + // has = cBar.high < tmpSupplies[i].Lower(); + // if (!has) + // { + // // + // iBox.Clean(); + // continue; + // } + + // // + // Add( + // tmpSupplies[i], + // supplyZones // + // ); + + // // + // iBox.Clean(); + // } + // } + // Clean(tmpSupplies); + + // // + // // Demand Zones ... + // count = stfState.FilterDemandZones( + // tmpDemands, + // NULL, + // XZONE_STATE_PASSED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_IGNORED, + // false // + // ); + // has = IsValidSize(count); + // if (has) + // { + // // + // for (int i = 0; i < count; i++) + // { + // // + // XBoxZone iBox; + // has = ToBox( + // iBox, + // tmpDemands[i] // + // ); + // if (!has) + // { + // // + // iBox.Clean(); + // continue; + // } + + // // + // // Find Index ... + + // // + // idx = FindIndex( + // iBox, + // insideBoxes // + // ); + // has = !IsValidIndex(idx); + // if (!has) + // { + // // + // iBox.Clean(); + // continue; + // } + + // // + // idx = FindIndex( + // iBox, + // breakedBoxes // + // ); + // has = !IsValidIndex(idx); + // if (!has) + // { + // // + // iBox.Clean(); + // continue; + // } + + // // + // idx = FindIndex( + // tmpDemands[i], + // demandZones // + // ); + // has = !IsValidIndex(idx); + // if (!has) + // { + // // + // iBox.Clean(); + // continue; + // } + + // // + // // Checking Price Validation ... + // has = cBar.low > tmpDemands[i].Upper(); + // if (!has) + // { + // // + // iBox.Clean(); + // continue; + // } + + // // + // Add( + // tmpDemands[i], + // demandZones // + // ); + + // // + // iBox.Clean(); + // } + // } + // Clean(tmpDemands); + + // // + // // Support Zones ... + // count = ttfState.FilterSupportZones( + // tmpSupports, + // period, + // XZONE_STATE_PASSED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_IGNORED, + // false // + // ); + // has = IsValidSize(count); + // if (has) + // { + // // + // for (int i = 0; i < count; i++) + // { + // // + // XBoxZone iBox; + // has = ToBox( + // iBox, + // tmpSupports[i] // + // ); + // if (!has) + // { + // // + // iBox.Clean(); + // continue; + // } + + // // + // // Find Index ... + + // // + // idx = FindIndex( + // iBox, + // insideBoxes // + // ); + // has = !IsValidIndex(idx); + // if (!has) + // { + // // + // iBox.Clean(); + // continue; + // } + + // // + // idx = FindIndex( + // iBox, + // breakedBoxes // + // ); + // has = !IsValidIndex(idx); + // if (!has) + // { + // // + // iBox.Clean(); + // continue; + // } + + // // + // idx = FindIndex( + // tmpSupports[i], + // supportZones // + // ); + // has = !IsValidIndex(idx); + // if (!has) + // { + // // + // iBox.Clean(); + // continue; + // } + + // // + // // Checking Price Validation ... + // has = cBar.low > tmpSupports[i].Upper(); + // if (!has) + // { + // // + // iBox.Clean(); + // continue; + // } + + // // + // Add( + // tmpSupports[i], + // supportZones // + // ); + + // // + // iBox.Clean(); + // } + // } + // Clean(tmpSupports); + + // // + // // Resistance Zones .. + // count = ttfState.FilterResistanceZones( + // tmpResistances, + // period, + // XZONE_STATE_PASSED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_IGNORED, + // false // + // ); + // has = IsValidSize(count); + // if (has) + // { + // // + // for (int i = 0; i < count; i++) + // { + // // + // XBoxZone iBox; + // has = ToBox( + // iBox, + // tmpResistances[i] // + // ); + // if (!has) + // { + // // + // iBox.Clean(); + // continue; + // } + + // // + // // Find Index ... + + // // + // idx = FindIndex( + // iBox, + // insideBoxes // + // ); + // has = !IsValidIndex(idx); + // if (!has) + // { + // // + // iBox.Clean(); + // continue; + // } + + // // + // idx = FindIndex( + // iBox, + // breakedBoxes // + // ); + // has = !IsValidIndex(idx); + // if (!has) + // { + // // + // iBox.Clean(); + // continue; + // } + + // // + // idx = FindIndex( + // tmpResistances[i], + // resistanceZones // + // ); + // has = !IsValidIndex(idx); + // if (!has) + // { + // // + // iBox.Clean(); + // continue; + // } + + // // + // // Checking Price Validation ... + // has = cBar.high < tmpResistances[i].Lower(); + // if (!has) + // { + // // + // iBox.Clean(); + // continue; + // } + + // // + // Add( + // tmpResistances[i], + // resistanceZones // + // ); + + // // + // iBox.Clean(); + // } + // } + // Clean(tmpResistances); + + // + // + // + + // + // Consolidation Zones ... + has = ttfState.HasConsolidationZones(); + if (has) + { + // + Copy( + ttfState.consolidationZones, + consolidationZones // + ); + CleanupArray( + consolidationZones, + 50 // + ); + } + + // + // + // + + // + // Detect Price Inside Zones ... + has = HasWaitingZones(); + if (has) + { + // + int mustRemove[]; + count = CountWaitingZones(); + for (int i = 0; i < count; i++) + { + // + XOBFVG iOBFVG = waitingZones[i]; + + // + bool isInside = + // + zBar.high < iOBFVG.ob.Upper() && + zBar.low > iOBFVG.ob.Lower() && + // + cBar.high < iOBFVG.ob.Upper() && + cBar.low > iOBFVG.ob.Lower() + // + ; + if (isInside) + { + // + idx = FindIndex( + iOBFVG, + insideZones // + ); + has = IsValidSize(idx); + if (!has) + { + // + Add( + i, + mustRemove // + ); + + // + AddRef( + iOBFVG, + insideZones // + ); + } + } + } + + // + has = HasChild(mustRemove); + if (has) + { + // + count = ArraySize(mustRemove); + for (int i = 0; i < count; i++) + { + // + ArrayRemove( + waitingZones, + mustRemove[i], + 1 // + ); + } + } + + // + Clean(mustRemove); + } + + // + // Here we Looking for Price Inside Supply or Demand Zones ... + + // + // Supply Zones ... + has = HasSupplyZones(); + if (has) + { + // + int mustRemove[]; + count = CountSupplyZones(); + for (int i = 0; i < count; i++) + { + // + XCSupplyZone *iZone = supplyZones[i]; + + // + bool isInside = + // + zBar.high < iZone.Upper() && + zBar.low > iZone.Lower() && + // + cBar.high < iZone.Upper() && + cBar.low > iZone.Lower() + // + ; + if (isInside) + { + // + XBoxZone iBox; + has = ToBox( + iBox, + iZone // + ); + if (has) + { + // + idx = FindIndex( + iBox, + insideBoxes // + ); + has = IsValidSize(idx); + if (!has) + { + // + Add( + i, + mustRemove // + ); + + // + AddRef( + iBox, + insideBoxes // + ); + } + } + + // + iBox.Clean(); + } + } + + // + has = HasChild(mustRemove); + if (has) + { + // + count = ArraySize(mustRemove); + for (int i = 0; i < count; i++) + { + // + ArrayRemove( + supplyZones, + mustRemove[i], + 1 // + ); + } + } + + // + Clean(mustRemove); + } + + // + // Demand Zones ... + has = HasDemandZones(); + if (has) + { + // + int mustRemove[]; + count = CountDemandZones(); + for (int i = 0; i < count; i++) + { + // + XCDemandZone *iZone = demandZones[i]; + + // + bool isInside = + // + zBar.high < iZone.Upper() && + zBar.low > iZone.Lower() && + // + cBar.high < iZone.Upper() && + cBar.low > iZone.Lower() + // + ; + if (isInside) + { + // + XBoxZone iBox; + has = ToBox( + iBox, + iZone // + ); + if (has) + { + // + idx = FindIndex( + iBox, + insideBoxes // + ); + has = IsValidSize(idx); + if (!has) + { + // + Add( + i, + mustRemove // + ); + + // + AddRef( + iBox, + insideBoxes // + ); + } + } + + // + iBox.Clean(); + } + } + + // + has = HasChild(mustRemove); + if (has) + { + // + count = ArraySize(mustRemove); + for (int i = 0; i < count; i++) + { + // + ArrayRemove( + demandZones, + mustRemove[i], + 1 // + ); + } + } + + // + Clean(mustRemove); + } + + // + // Here we Detect Breaked Zone/Box (s) ... + + // + // Detect Breaked Zones ... + has = HasInsideZones(); + if (has) + { + // + int mustRemove[]; + count = CountInsideZones(); + for (int i = 0; i < count; i++) + { + // + XOBFVG iOBFVG = insideZones[i]; + ENUM_X_DIRECTION iDir = iOBFVG.GetDirection(); + bool isBullish = IsBullish(iDir); + + // + bool isBullishBreaked = + // + zBar.high < iOBFVG.ob.Lower() && + cBar.high < iOBFVG.ob.Lower() + // + ; + + // + bool isBearishBreaked = + // + zBar.low > iOBFVG.ob.Upper() && + cBar.low > iOBFVG.ob.Upper() + // + ; + + // + bool isBreaked = + isBullish + ? isBullishBreaked + : isBearishBreaked; + + // + if (isBreaked) + { + // + idx = FindIndex( + iOBFVG, + breakedZones // + ); + has = IsValidIndex(idx); + if (!has) + { + // + Add( + i, + mustRemove // + ); + + // + AddRef( + iOBFVG, + breakedZones // + ); + } + } + } + + // + has = HasChild(mustRemove); + if (has) + { + // + count = ArraySize(mustRemove); + for (int i = 0; i < count; i++) + { + // + ArrayRemove( + insideZones, + mustRemove[i], + 1 // + ); + } + } + + // + Clean(mustRemove); + } + + // + // Detect Breaked Boxes ... + has = HasInsideBoxes(); + if (has) + { + // + int mustRemove[]; + count = CountInsideBoxes(); + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox = insideBoxes[i]; + ENUM_X_DIRECTION iDir = iBox.dir; + bool isBullish = iBox.IsBullish(); + + // + bool isBullishBreaked = + // + zBar.high < iBox.lower && + cBar.high < iBox.lower + // + ; + + // + bool isBearishBreaked = + // + zBar.low > iBox.upper && + cBar.low > iBox.upper + // + ; + + // + bool isBreaked = + isBullish + ? isBullishBreaked + : isBearishBreaked; + + // + if (isBreaked) + { + // + idx = FindIndex( + iBox, + breakedBoxes // + ); + has = IsValidIndex(idx); + if (!has) + { + // + Add( + i, + mustRemove // + ); + + // + AddRef( + iBox, + breakedBoxes // + ); + } + } + } + + // + has = HasChild(mustRemove); + if (has) + { + // + count = ArraySize(mustRemove); + for (int i = 0; i < count; i++) + { + // + ArrayRemove( + insideBoxes, + mustRemove[i], + 1 // + ); + } + } + + // + Clean(mustRemove); + } + + // + // Cleanup Resource ... + + // + zBar.Clean(); + cBar.Clean(); + } + + // + bool HasSupplyZone() + { + return supplyZone != NULL && + supplyZone.IsValid(); + } + + // + bool HasDemandZone() + { + return demandZone != NULL && + demandZone.IsValid(); + } + + // + bool HasSupplyZones() + { + return HasChild(supplyZones); + } + + // + int CountSupplyZones() + { + return ArraySize(supplyZones); + } + + // + bool HasDemandZones() + { + return HasChild(demandZones); + } + + // + int CountDemandZones() + { + return ArraySize(demandZones); + } + + // + bool HasSupportZones() + { + return HasChild(supportZones); + } + + // + int CountSupportZones() + { + return ArraySize(supportZones); + } + + // + bool HasResistanceZones() + { + return HasChild(resistanceZones); + } + + // + int CountResistanceZones() + { + return ArraySize(resistanceZones); + } + + // + bool HasWaitingZones() + { + return HasChild(waitingZones); + } + + // + int CountWaitingZones() + { + return ArraySize(waitingZones); + } + + // + bool HasInsideZones() + { + return HasChild(insideZones); + } + + // + int CountInsideZones() + { + return ArraySize(insideZones); + } + + // + bool HasBreakedZones() + { + return HasChild(breakedZones); + } + + // + int CountBreakedZones() + { + return ArraySize(breakedZones); + } + + // + bool HasConsolidationZones() + { + return HasChild(consolidationZones); + } + + // + int CountConsolidationZones() + { + return ArraySize(consolidationZones); + } + + // + bool HasInsideBoxes() + { + return HasChild(insideBoxes); + } + + // + int CountInsideBoxes() + { + return ArraySize(insideBoxes); + } + + // + bool HasBreakedBoxes() + { + return HasChild(breakedBoxes); + } + + // + int CountBreakedBoxes() + { + return ArraySize(breakedBoxes); + } + + // + // + // + + // + bool IsDestroyed( + int barIndex = 0, + ENUM_TIMEFRAMES forPeriod = NULL // + ) + { + // + bool result = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (!IsValid(forPeriod)) + { + forPeriod = period; + } + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + XOHCL bar; + result = bar.Init( + symbol, + period, + barIndex // + ); + if (!result) + { + // + bar.Clean(); + return result; + } + + // + XOHCL cBar; + result = bar.GetPreviousBar(cBar); + if (!result) + { + // + bar.Clean(); + cBar.Clean(); + + // + return result; + } + + // + bool isSupplyZoneBreaked = + // + bar.low > supplyZone.Upper() && + cBar.low > supplyZone.Upper() + // + ; + + // + bool isDemandZoneBreaked = + // + bar.high < demandZone.Lower() && + cBar.high < demandZone.Lower() + // + ; + + // + bar.Clean(); + cBar.Clean(); + + // + result = isSupplyZoneBreaked || + isDemandZoneBreaked; + + // + return result; + } + + // + bool DetectPriority( + ENUM_X121SMC_XWZ_PRIORITY &priority, + ENUM_X_DIRECTION forDir, + int barIndex = 0, + ENUM_TIMEFRAMES forPeriod = NULL // + ) + { + // + bool result = false; + + // + priority = X121SMC_XWZ_PRIORITY_NONE; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (!IsValid(forPeriod)) + { + forPeriod = period; + } + + // + result = IsValid() && + HasDirection(forDir); + if (!result) + { + return result; + } + + // + bool isBullish = IsBullish(forDir); + + // + XOHCL bar; + result = bar.Init( + symbol, + forPeriod, + barIndex // + ); + if (!result) + { + // + bar.Clean(); + return result; + } + + // + if (bar.high < supplyZone.Upper() && + bar.low > supplyZone.Lower()) + { + // + priority = + isBullish + ? X121SMC_XWZ_PRIORITY_NONE + : X121SMC_XWZ_PRIORITY_STRONG_HIGH; + } + else if (bar.high < supplyZone.Lower() && + bar.low > quarter1) + { + // + priority = + isBullish + ? X121SMC_XWZ_PRIORITY_WEAK + : X121SMC_XWZ_PRIORITY_HIGH; + } + else if (bar.high < quarter1 && + bar.low > quarter2) + { + // + priority = + isBullish + ? X121SMC_XWZ_PRIORITY_LOW + : X121SMC_XWZ_PRIORITY_REGULAR; + } + else if (bar.high < quarter2 && + bar.low > quarter3) + { + // + priority = + isBullish + ? X121SMC_XWZ_PRIORITY_REGULAR + : X121SMC_XWZ_PRIORITY_LOW; + } + else if (bar.high < quarter3 && + bar.low > demandZone.Upper()) + { + // + priority = + isBullish + ? X121SMC_XWZ_PRIORITY_HIGH + : X121SMC_XWZ_PRIORITY_WEAK; + } + else if (bar.high < demandZone.Upper() && + bar.low > demandZone.Lower()) + { + // + priority = + isBullish + ? X121SMC_XWZ_PRIORITY_STRONG_HIGH + : X121SMC_XWZ_PRIORITY_NONE; + } + + // + result = priority != X121SMC_XWZ_PRIORITY_NONE && + priority != X121SMC_XWZ_PRIORITY_WEAK; + + // + bar.Clean(); + + // + return result; + } + + // + // + // + + // + void UpdateTo(datetime value = NULL) + { + // + value = NormalizeTime(value); + + // + int count = 0; + bool has = false; + + // + has = HasSupplyZone(); + if (has) + { + supplyZone.To(value); + } + + // + has = HasDemandZone(); + if (has) + { + demandZone.To(value); + } + + // + has = HasSupplyZones(); + if (has) + { + // + count = CountSupplyZones(); + for (int i = 0; i < count; i++) + { + supplyZones[i].To(value); + } + } + + // + has = HasDemandZones(); + if (has) + { + // + count = CountDemandZones(); + for (int i = 0; i < count; i++) + { + demandZones[i].To(value); + } + } + + // + has = HasSupportZones(); + if (has) + { + // + count = CountSupportZones(); + for (int i = 0; i < count; i++) + { + supportZones[i].To(value); + } + } + + // + has = HasResistanceZones(); + if (has) + { + // + count = CountResistanceZones(); + for (int i = 0; i < count; i++) + { + resistanceZones[i].To(value); + } + } + + // + has = HasWaitingZones(); + if (has) + { + // + count = CountWaitingZones(); + for (int i = 0; i < count; i++) + { + waitingZones[i].UpdateTo(value); + } + } + + // + has = HasInsideZones(); + if (has) + { + // + count = CountInsideZones(); + for (int i = 0; i < count; i++) + { + insideZones[i].UpdateTo(value); + } + } + + // + // has = HasBreakedZones(); + // if (has) + // { + // // + // count = CountBreakedZones(); + // for (int i = 0; i < count; i++) + // { + // breakedZones[i].UpdateTo(value); + // } + // } + + // + has = HasInsideBoxes(); + if (has) + { + // + count = CountInsideBoxes(); + for (int i = 0; i < count; i++) + { + insideBoxes[i].to = value; + } + } + + // + // has = HasBreakedBoxes(); + // if (has) + // { + // // + // count = CountBreakedBoxes(); + // for (int i = 0; i < count; i++) + // { + // insideBoxes[i].to = value; + // } + // } + + // + } + + // + void Draw( + XCPOIDrawer *drawer, + bool drawWaitingZones = true, + bool drawInsideZones = false, + bool drawBreakedZones = false, + bool drawSupplyZone = false, + bool drawDemandZone = false, + bool drawSupplyZones = false, + bool drawDemandZones = false, + bool drawSupportZones = false, + bool drawResistanceZones = false // + ) + { + // + if (drawer == NULL) + { + return; + } + + // + int count = 0; + bool has = false; + bool isCreated = false; + + // + ulong chartID = drawer.ChartIdentification(); + int subWindow = drawer.SubWindowIdentification(); + color bullishColor = drawer.BarBullishColor(); + color bearishColor = drawer.BarBearishColor(); + + // + // Supply Zone ... + if (drawSupplyZone) + { + // + has = HasSupplyZone(); + if (has) + { + // + XCSupplyZoneObject *iObj; + isCreated = drawer.CreateSupplyZone( + supplyZone, + iObj // + ); + + // + if (isCreated) + { + mWorkingZoneObjects.Add(iObj); + } + } + } + + // + // Demand Zone ... + if (drawDemandZone) + { + // + has = HasDemandZone(); + if (has) + { + // + XCDemandZoneObject *iObj; + isCreated = drawer.CreateDemandZone( + demandZone, + iObj // + ); + + // + if (isCreated) + { + mWorkingZoneObjects.Add(iObj); + } + } + } + + // + // + // + + // + // Supply Zones ... + if (drawSupplyZones) + { + // + has = HasSupplyZones(); + if (has) + { + // + count = CountSupplyZones(); + for (int i = 0; i < count; i++) + { + // + XCSupplyZoneObject *iObj; + isCreated = drawer.CreateSupplyZone( + supplyZones[i], + iObj // + ); + + // + if (isCreated) + { + mWorkingZoneObjects.Add(iObj); + } + } + } + } + + // + // Demand Zones ... + if (drawDemandZones) + { + // + has = HasDemandZones(); + if (has) + { + // + count = CountDemandZones(); + for (int i = 0; i < count; i++) + { + // + XCDemandZoneObject *iObj; + isCreated = drawer.CreateDemandZone( + demandZones[i], + iObj // + ); + + // + if (isCreated) + { + mWorkingZoneObjects.Add(iObj); + } + } + } + } + + // + // Support Zones ... + if (drawSupportZones) + { + // + has = HasSupportZones(); + if (has) + { + // + count = CountSupportZones(); + for (int i = 0; i < count; i++) + { + // + XCSupportZoneObject *iObj; + isCreated = drawer.CreateSupportZone( + supportZones[i], + iObj // + ); + + // + if (isCreated) + { + mWorkingZoneObjects.Add(iObj); + } + } + } + } + + // + // Resistance Zones ... + if (drawResistanceZones) + { + // + has = HasResistanceZones(); + if (has) + { + // + count = CountResistanceZones(); + for (int i = 0; i < count; i++) + { + // + XCResistanceZoneObject *iObj; + isCreated = drawer.CreateResistanceZone( + resistanceZones[i], + iObj // + ); + + // + if (isCreated) + { + mWorkingZoneObjects.Add(iObj); + } + } + } + } + + // + // + // + + // + // Waiting Zones ... + if (drawWaitingZones) + { + // + has = HasWaitingZones(); + if (has) + { + // + count = CountWaitingZones(); + for (int i = 0; i < count; i++) + { + // + XCBaseObject *objects[]; + int objectsCount = drawer.DrawOBFVG( + waitingZones[i], + objects // + ); + has = IsValidSize(objectsCount); + if (has) + { + // + for (int j = 0; j < objectsCount; j++) + { + mWaitingZoneObjects.Add(objects[j]); + } + } + } + } + } + + // + // Inside Zones ... + if (drawInsideZones) + { + // + // Zones ... + has = HasInsideZones(); + if (has) + { + // + count = CountInsideZones(); + for (int i = 0; i < count; i++) + { + // + XCBaseObject *objects[]; + int objectsCount = drawer.DrawOBFVG( + insideZones[i], + objects // + ); + + // + has = IsValidSize(objectsCount); + if (has) + { + // + for (int i = 0; i < objectsCount; i++) + { + mInsideZoneObjects.Add(objects[i]); + } + } + } + } + + // // + // // Boxes ... + // has = HasInsideBoxes(); + // if (has) + // { + // // + // count = CountInsideBoxes(); + // for (int i = 0; i < count; i++) + // { + // // + // XCBoxObject *object; + // bool isCreated = drawer.DrawBox( + // insideBoxes[i], + // object // + // ); + + // // + // if (isCreated) + // { + // mInsideZoneObjects.Add(object); + // } + // } + // } + } + + // + // Breaked Zones ... + if (drawBreakedZones) + { + // + has = HasBreakedZones(); + if (has) + { + // + count = CountBreakedZones(); + for (int i = 0; i < count; i++) + { + // + XCBaseObject *objects[]; + int objectsCount = drawer.DrawOBFVG( + breakedZones[i], + objects // + ); + + // + has = IsValidSize(objectsCount); + if (has) + { + // + for (int i = 0; i < objectsCount; i++) + { + mBreakedZoneObjects.Add(objects[i]); + } + } + } + } + + // // + // // Boxes ... + // has = HasBreakedBoxes(); + // if (has) + // { + // // + // count = CountBreakedBoxes(); + // for (int i = 0; i < count; i++) + // { + // // + // XCBoxObject *object; + // bool isCreated = drawer.DrawBox( + // breakedBoxes[i], + // object // + // ); + + // // + // if (isCreated) + // { + // mInsideZoneObjects.Add(object); + // } + // } + // } + } + + // + // + // + + // + // Quarters ... + has = IsValid(); + if (has) + { + // + double zoneUpper = supplyZone.Upper(); + double upper = supplyZone.Lower(); + + // + double lower = demandZone.Upper(); + double zoneLower = demandZone.Lower(); + + // + string prefix = "X121WZone_" + symbol + "_" + ToString(period); + + // + // Zone Upper ... + CChartObjectHLine *zoneUpperLine; + zoneUpperLine = new CChartObjectHLine(); + isCreated = zoneUpperLine.Create( + chartID, + prefix + "_ZoneTop", + subWindow, + zoneUpper // + ); + if (isCreated) + { + // + zoneUpperLine.Color(clrRed); + + // + mWaitingZoneObjects.Add(zoneUpperLine); + } + + // + // Zone Lower ... + CChartObjectHLine *zoneLowerLine; + zoneLowerLine = new CChartObjectHLine(); + isCreated = zoneLowerLine.Create( + chartID, + prefix + "_ZoneDown", + subWindow, + zoneLower // + ); + if (isCreated) + { + // + zoneLowerLine.Color(clrRed); + + // + mWaitingZoneObjects.Add(zoneLowerLine); + } + + // + // Upper ... + CChartObjectHLine *upperLine; + upperLine = new CChartObjectHLine(); + isCreated = upperLine.Create( + chartID, + prefix + "_Upper", + subWindow, + upper // + ); + if (isCreated) + { + // + upperLine.Color(clrLime); + + // + mWaitingZoneObjects.Add(upperLine); + } + + // + // Lower ... + CChartObjectHLine *lowerLine; + lowerLine = new CChartObjectHLine(); + isCreated = lowerLine.Create( + chartID, + prefix + "_Lower", + subWindow, + lower // + ); + if (isCreated) + { + // + lowerLine.Color(clrLime); + + // + mWaitingZoneObjects.Add(lowerLine); + } + + // + // Quarters ... + + // + // Quarter 1 ... + CChartObjectHLine *q1Line; + q1Line = new CChartObjectHLine(); + isCreated = q1Line.Create( + chartID, + prefix + "_Q1", + subWindow, + quarter1 // + ); + if (isCreated) + { + // + q1Line.Color(clrYellow); + + // + mWaitingZoneObjects.Add(q1Line); + } + + // + // Quarter 2 ... + CChartObjectHLine *q2Line; + q2Line = new CChartObjectHLine(); + isCreated = q2Line.Create( + chartID, + prefix + "_Q2", + subWindow, + quarter2 // + ); + if (isCreated) + { + // + q2Line.Color(clrYellow); + + // + mWaitingZoneObjects.Add(q2Line); + } + + // + // Quarter 3 ... + CChartObjectHLine *q3Line; + q3Line = new CChartObjectHLine(); + isCreated = q3Line.Create( + chartID, + prefix + "_Q3", + subWindow, + quarter3 // + ); + if (isCreated) + { + // + q3Line.Color(clrYellow); + + // + mWaitingZoneObjects.Add(q3Line); + } + } + } + + // +}; + +// +// Definitions ... +struct X121SMCStrategyXWZSignalConditions +{ + // + // Props ... + + // + string symbol; + ENUM_TIMEFRAMES period; + + // + double sl; + double reward; + double amountPercent; + ENUM_X_DIRECTION dir; + ENUM_X_POSITION_TYPES type; + + // + // Setup Props ... + + // + datetime setupTime; + datetime triggerTime; + + // + double pivot; + double point; + double sls[]; + double targets[]; + + // + XBoxZone signalBox; + + // + ENUM_X121SMC_XWZ_PRIORITY priority; + ENUM_X121SMC_XWZ_PROVIDERS provider; + + // + // Constructor ... + X121SMCStrategyXWZSignalConditions() + { + Clean(); + } + + // + // Tools ... + + /** + * Cleaning Up ... + */ + void Clean() + { + // + sl = 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; + + // + reward = 0; + amountPercent = 0; + + // + Clean(sls); + Clean(targets); + signalBox.Clean(); + + // + provider = X121SMC_XWZ_PROVIDER_NONE; + } + + // + // + // + + // + void UpdateTo(datetime value = NULL) + { + // + value = NormalizeTime(value); + + // + int count = 0; + bool has = false; + } + + // +}; + +// +// Extension Functions ... + +/** + * Check an XOBFVG instance has Required Conditions ... + * + * @param zone: XOBFVG instance ... + * @param state: XPOIState instance ... + * @param conditions: X121Conditions instance ... + * + * @return ( bool ) + */ +bool DetectSelectedZoneConditions( + bool &isReversal, + XOBFVG &zone, + XPOIState &state, + X121Conditions &conditions // +) +{ + // + bool result = false; + + // + isReversal = false; + + // + result = + zone.IsValid() && + state.IsValid() && + state.HasChild(); + if (!result) + { + return result; + } + + // + bool isBullish = zone.IsBullish(); + bool isBearish = zone.IsBearish(); + + // + bool isBullishTrend = conditions.isTrendBullish || + conditions.isTrendSwitchedToBullish; + bool isBearishTrend = conditions.isTrendBearish || + conditions.isTrendSwitchedToBearish; + + // + double bullishScore = 0; + double bearishScore = 0; + double scoreMultiplier = 1.5; + conditions.GenerateScore( + bullishScore, + bearishScore // + ); + + // + bool isBullishScorePassed = bullishScore > 0 && + bearishScore >= 0 && + bullishScore > bearishScore * scoreMultiplier; + + // + bool isBearishScorePassed = bearishScore > 0 && + bullishScore >= 0 && + bearishScore > bullishScore * scoreMultiplier; + + // + // VWap ... + + // + double vwapFast = conditions.vwapFastBuffer[0]; + double vwapMid = conditions.vwapMidBuffer[0]; + double vwapSlow = conditions.vwapSlowBuffer[0]; + + // + bool isVWapInside = + // + vwapFast > zone.ob.Lower() && + vwapFast < zone.ob.Upper() + // + && + vwapMid > zone.ob.Lower() && + vwapMid < zone.ob.Upper() + // + ; + + // + bool isVWapBullish = + // + (conditions.isVWapBullishState && + conditions.isVWapSwitchedToBullishOrdered) + // + || + // + (conditions.isVWapBullishOrdered && + conditions.isVWapSwitchedToBullishState) + // + ; + + // + bool isVWapBearish = + // + (conditions.isVWapBearishState && + conditions.isVWapSwitchedToBearishOrdered) + // + || + // + (conditions.isVWapBearishOrdered && + conditions.isVWapSwitchedToBearishState) + // + ; + + // + // X3Ma ... + + // + double x3maFast = conditions.x3maFastBuffer[0]; + double x3maMid = conditions.x3maMidBuffer[0]; + double x3maSlow = conditions.x3maSlowBuffer[0]; + + // + bool isX3MaInside = + // + x3maFast > zone.ob.Lower() && + x3maFast < zone.ob.Upper() + // + && + x3maMid > zone.ob.Lower() && + x3maMid < zone.ob.Upper() + // + ; + + // + bool isX3MaBullish = + // + (conditions.isX3MaBullishState && + conditions.isX3MaSwitchedToBullishOrdered) + // + || + // + (conditions.isX3MaBullishOrdered && + conditions.isX3MaSwitchedToBullishState) + // + ; + + // + bool isX3MaBearish = + // + (conditions.isX3MaBearishState && + conditions.isX3MaSwitchedToBearishOrdered) + // + || + // + (conditions.isX3MaBearishOrdered && + conditions.isX3MaSwitchedToBearishState) + // + ; + + // + // + // + + // + bool isInside = + // + isVWapInside || + isX3MaInside + // + ; + + // + bool isVWap3MaBullish = + isVWapBullish || + isX3MaBullish; + + // + bool isVWap3MaBearish = + isVWapBearish || + isX3MaBearish; + + // + // + // + + // + bool isDirectionalBullishPassed = + // + isInside && + isBullish && + isBullishTrend && + isVWap3MaBullish && + isBullishScorePassed + // + ; + + // + bool isDirectionalBearishPassed = + // + isInside && + isBearish && + isBearishTrend && + isVWap3MaBearish && + isBearishScorePassed + // + ; + + // + bool isDirectionalPassed = + isDirectionalBullishPassed || + isDirectionalBearishPassed; + + // + bool isReversalBullishPassed = + // + isInside && + isBullish && + isBearishTrend && + isVWap3MaBearish && + isBearishScorePassed + // + ; + + // + bool isReversalBearishPassed = + // + isInside && + isBearish && + isBullishTrend && + isVWap3MaBullish && + isBullishScorePassed + // + ; + + // + bool isReversalPassed = isReversalBullishPassed || + isReversalBearishPassed; + + // + result = isReversalPassed || + isDirectionalPassed; + + // + if (result) + { + isReversal = isReversalPassed; + } + + // + return result; +} + +/** + * Detect Targets Based on Selected Zone for Specified type of Directions ... + * + * @param targets: double Collection ... + * @param selectedZone: XOBFVG instance, selected Zone ... + * @param forDir: ENUM_X_DIRECTION specified Position Direction ... + * @param workingone: X121SMCStrategyXWZWorkingZone instance, Specified Working Zone ... + * @param barIndex: int Specified Bar Index ... + * + * @return ( bool ) + */ +bool DetectSelectedZonesTargets( + double &targets[], + XOBFVG &selectedZone, + ENUM_X_DIRECTION forDir, + ENUM_X121SMC_XWZ_PRIORITY forPriority, + X121SMCStrategyXWZWorkingZone &workingZone, + int barIndex = 0 // +) +{ + // + bool result = false; + + // + Clean(targets); + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (barIndex == 0) + { + barIndex++; + } + + // + result = + // + selectedZone.IsValid() && + HasDirection(forDir) && + workingZone.IsValid() && + forPriority != X121SMC_XWZ_PRIORITY_NONE + // + ; + if (!result) + { + return result; + } + + // + bool isBullish = IsBullish(forDir); + + // + XOHCL cBar; + result = cBar.Init( + workingZone.symbol, + workingZone.period, + barIndex // + ); + if (!result) + { + // + cBar.Clean(); + return result; + } + + // + int idx = -1; + bool has = false; + XOBFVG tmpZones[]; + + // + // Based On Waiting Zones ... + has = workingZone.HasWaitingZones(); + if (has) + { + // + Copy( + workingZone.waitingZones, + tmpZones // + ); + + // + while (HasChild(tmpZones)) + { + // + XOBFVG iOBFVG; + + // + idx = GetYoungest(tmpZones); + if (!IsValidIndex(idx)) + { + // + iOBFVG.Clean(); + break; + } + + // + iOBFVG = tmpZones[idx]; + ArrayRemove( + tmpZones, + idx, + 1 // + ); + + // + double iTarget = + isBullish + ? iOBFVG.ob.Lower() + : iOBFVG.ob.Upper(); + + // + has = + isBullish + ? cBar.high < iTarget + : cBar.low > iTarget; + + // + if (has) + { + // + Add( + iTarget, + targets // + ); + } + + // + iOBFVG.Clean(); + } + + // + Clean(tmpZones); + } + + // + // Based On Breaked Zones ... + has = workingZone.HasBreakedZones(); + if (has) + { + Copy( + workingZone.breakedZones, + tmpZones // + ); + + // + while (HasChild(tmpZones)) + { + // + XOBFVG iOBFVG; + + // + idx = GetYoungest(tmpZones); + if (!IsValidIndex(idx)) + { + // + iOBFVG.Clean(); + break; + } + + // + iOBFVG = tmpZones[idx]; + ArrayRemove( + tmpZones, + idx, + 1 // + ); + + // + double iTarget = + isBullish + ? iOBFVG.ob.Lower() + : iOBFVG.ob.Upper(); + + // + has = + isBullish + ? cBar.high < iTarget + : cBar.low > iTarget; + + // + if (has) + { + // + Add( + iTarget, + targets // + ); + } + + // + iOBFVG.Clean(); + } + + // + Clean(tmpZones); + } + + // + // Based On Priority ... + has = forPriority != X121SMC_XWZ_PRIORITY_NONE; + if (has) + { + // + switch (forPriority) + { + // + case X121SMC_XWZ_PRIORITY_WEAK: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + } + break; + + // + case X121SMC_XWZ_PRIORITY_LOW: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + } + break; + + // + case X121SMC_XWZ_PRIORITY_REGULAR: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + } + break; + + // + case X121SMC_XWZ_PRIORITY_HIGH: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter3, + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter1, + targets // + ); + } + break; + + // + case X121SMC_XWZ_PRIORITY_STRONG_HIGH: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Strong High ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Strong High ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + } + break; + } + } + + // + result = HasChild(targets); + + // + // Cleanup ... + cBar.Clean(); + Clean(tmpZones); + + // + return result; +} + +/** + * Detect Targets Based on Selected Zone for Specified type of Directions ... + * + * @param targets: double Collection ... + * @param selectedZone: XBoxZone instance, selected Zone ... + * @param forDir: ENUM_X_DIRECTION specified Position Direction ... + * @param workingone: X121SMCStrategyXWZWorkingZone instance, Specified Working Zone ... + * @param barIndex: int Specified Bar Index ... + * + * @return ( bool ) + */ +bool DetectSelectedZonesTargets( + double &targets[], + XBoxZone &selectedZone, + ENUM_X_DIRECTION forDir, + ENUM_X121SMC_XWZ_PRIORITY forPriority, + X121SMCStrategyXWZWorkingZone &workingZone, + int barIndex = 0 // +) +{ + // + bool result = false; + + // + Clean(targets); + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (barIndex == 0) + { + barIndex++; + } + + // + result = + // + selectedZone.IsValid() && + HasDirection(forDir) && + workingZone.IsValid() && + forPriority != X121SMC_XWZ_PRIORITY_NONE + // + ; + if (!result) + { + return result; + } + + // + bool isBullish = IsBullish(forDir); + + // + XOHCL cBar; + result = cBar.Init( + workingZone.symbol, + workingZone.period, + barIndex // + ); + if (!result) + { + // + cBar.Clean(); + return result; + } + + // + int idx = -1; + bool has = false; + XOBFVG tmpZones[]; + + // + // Based On Waiting Zones ... + has = workingZone.HasWaitingZones(); + if (has) + { + // + Copy( + workingZone.waitingZones, + tmpZones // + ); + + // + while (HasChild(tmpZones)) + { + // + XOBFVG iOBFVG; + + // + idx = GetYoungest(tmpZones); + if (!IsValidIndex(idx)) + { + // + iOBFVG.Clean(); + break; + } + + // + iOBFVG = tmpZones[idx]; + ArrayRemove( + tmpZones, + idx, + 1 // + ); + + // + double iTarget = + isBullish + ? iOBFVG.ob.Lower() + : iOBFVG.ob.Upper(); + + // + has = + isBullish + ? cBar.high < iTarget + : cBar.low > iTarget; + + // + if (has) + { + // + Add( + iTarget, + targets // + ); + } + + // + iOBFVG.Clean(); + } + + // + Clean(tmpZones); + } + + // + // Based On Breaked Zones ... + has = workingZone.HasBreakedZones(); + if (has) + { + Copy( + workingZone.breakedZones, + tmpZones // + ); + + // + while (HasChild(tmpZones)) + { + // + XOBFVG iOBFVG; + + // + idx = GetYoungest(tmpZones); + if (!IsValidIndex(idx)) + { + // + iOBFVG.Clean(); + break; + } + + // + iOBFVG = tmpZones[idx]; + ArrayRemove( + tmpZones, + idx, + 1 // + ); + + // + double iTarget = + isBullish + ? iOBFVG.ob.Lower() + : iOBFVG.ob.Upper(); + + // + has = + isBullish + ? cBar.high < iTarget + : cBar.low > iTarget; + + // + if (has) + { + // + Add( + iTarget, + targets // + ); + } + + // + iOBFVG.Clean(); + } + + // + Clean(tmpZones); + } + + // + // Based On Priority ... + has = forPriority != X121SMC_XWZ_PRIORITY_NONE; + if (has) + { + // + switch (forPriority) + { + // + case X121SMC_XWZ_PRIORITY_WEAK: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + } + break; + + // + case X121SMC_XWZ_PRIORITY_LOW: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + } + break; + + // + case X121SMC_XWZ_PRIORITY_REGULAR: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + } + break; + + // + case X121SMC_XWZ_PRIORITY_HIGH: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter3, + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter1, + targets // + ); + } + break; + + // + case X121SMC_XWZ_PRIORITY_STRONG_HIGH: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Strong High ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Strong High ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + } + break; + } + } + + // + result = HasChild(targets); + + // + // Cleanup ... + cBar.Clean(); + Clean(tmpZones); + + // + return result; +} + +/** + * Detect SL Candidates Based on Selected Zone for Specified type of Directions ... + * + * @param sls: double Collection ... + * @param selectedZone: XOBFVG instance, selected Zone ... + * @param forDir: ENUM_X_DIRECTION specified Position Direction ... + * @param workingZone: X121SMCStrategyXWZWorkingZone instance, Specified Working Zone ... + * @param barIndex: int Specified Bar Index ... + * @param maxAllowedSLDistanceInPoint: doube max Allowe SL distance ... + * + * @return ( bool ) + */ +bool DetectSelectedZoneSLCandidates( + double &sls[], + XOBFVG &selectedZone, + ENUM_X_DIRECTION forDir, + X121SMCStrategyXWZWorkingZone &workingZone, + X121Conditions &conditions, + int barIndex = 0, + double maxAllowedSLDistanceInPoint = 300 // +) +{ + // + bool result = false; + + // + Clean(sls); + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (barIndex == 0) + { + barIndex++; + } + + // + result = + // + selectedZone.IsValid() && + HasDirection(forDir) && + workingZone.IsValid() + // + ; + if (!result) + { + return result; + } + + // + bool isBullish = IsBullish(forDir); + + // + double pivot = + isBullish + ? selectedZone.ob.Lower() + : selectedZone.ob.Upper(); + double points = GetPoints(workingZone.symbol); + + // + XOHCL cBar; + result = cBar.Init( + workingZone.symbol, + workingZone.period, + barIndex // + ); + if (!result) + { + // + cBar.Clean(); + return result; + } + + // + int idx = -1; + bool has = false; + + // + double pvSL = isBullish + ? conditions.valesBuffer[0] + : conditions.peaksBuffer[1]; + + // + Add( + pvSL, + sls // + ); + + // + // Based On Passed Bars ... + // XOHCL passedBar; + // bool isPassed = false; + // bool isBodyState = false; + // ENUM_X_DIRECTION passedDir = selectedZone.GetDirection(); + + // // + // // Started Bar ... + // isPassed = selectedZone.ob.IsStarted( + // passedDir, + // passedBar, + // isBodyState // + // ); + // if (isPassed) + // { + // // + // double iSL = + // isBullish + // ? passedBar.low + // : passedBar.high; + // double iSLDiff = MathAbs(iSL - pivot); + // has = + // iSLDiff > 0 && + // iSLDiff <= maxAllowedSLDistanceInPoint * points; + // if (has) + // { + // // + // Add( + // iSL, + // sls // + // ); + // } + // } + + // // + // // Activation Bar ... + // passedBar.Clean(); + // isPassed = selectedZone.ob.IsActivated( + // passedDir, + // passedBar, + // isBodyState // + // ); + // if (isPassed) + // { + // // + // double iSL = + // isBullish + // ? passedBar.low + // : passedBar.high; + // double iSLDiff = MathAbs(iSL - pivot); + // has = + // iSLDiff > 0 && + // iSLDiff <= maxAllowedSLDistanceInPoint * points; + // if (has) + // { + // // + // Add( + // iSL, + // sls // + // ); + // } + // } + + // // + // // Worked Bar ... + // passedBar.Clean(); + // isPassed = selectedZone.ob.IsActivated( + // passedDir, + // passedBar, + // isBodyState // + // ); + // if (isPassed) + // { + // // + // double iSL = + // isBullish + // ? passedBar.low + // : passedBar.high; + // double iSLDiff = MathAbs(iSL - pivot); + // has = + // iSLDiff > 0 && + // iSLDiff <= maxAllowedSLDistanceInPoint * points; + // if (has) + // { + // // + // Add( + // iSL, + // sls // + // ); + // } + // } + + // // + // // Breaked Bar ... + // passedBar.Clean(); + // isPassed = selectedZone.ob.IsActivated( + // passedDir, + // passedBar, + // isBodyState // + // ); + // if (isPassed) + // { + // // + // double iSL = + // isBullish + // ? passedBar.low + // : passedBar.high; + // double iSLDiff = MathAbs(iSL - pivot); + // has = + // iSLDiff > 0 && + // iSLDiff <= maxAllowedSLDistanceInPoint * points; + // if (has) + // { + // // + // Add( + // iSL, + // sls // + // ); + // } + // } + + // + // Based On Consolidation Zones ... + has = workingZone.HasConsolidationZones(); + if (has) + { + // + XConsolidationZone tmpZones[]; + Copy( + workingZone.consolidationZones, + tmpZones // + ); + XConsolidationZone selectedConsolidationZone; + + // + while (HasChild(tmpZones)) + { + // + idx = GetYoungest(tmpZones); + if (!IsValidIndex(idx)) + { + break; + } + + // + XConsolidationZone iZone = tmpZones[idx]; + + // + ArrayRemove( + tmpZones, + idx, + 1 // + ); + + // + has = + !selectedConsolidationZone.IsValid() + ? isBullish + ? cBar.low < iZone.upper + : cBar.high < iZone.lower + : isBullish + ? selectedConsolidationZone.lower < iZone.lower + : selectedConsolidationZone.upper > iZone.upper; + if (has) + { + // + selectedConsolidationZone = iZone; + iZone.Clean(); + break; + } + + // + iZone.Clean(); + } + + // + Clean(tmpZones); + has = selectedConsolidationZone.IsValid(); + if (has) + { + // + double iSL = + isBullish + ? selectedConsolidationZone.lower + : selectedConsolidationZone.upper; + double iSLDiff = MathAbs(iSL - pivot); + has = + iSLDiff > 0 && + iSLDiff <= maxAllowedSLDistanceInPoint * points; + if (has) + { + // + Add( + iSL, + sls // + ); + } + } + } + + // + // Based On Supply and Demand Zones ... + + // + // Demand Zones ... + has = workingZone.HasDemandZones(); + if (has) + { + // + XCDemandZone *tmpZones[]; + Copy( + workingZone.demandZones, + tmpZones // + ); + XCDemandZone *selectedDemand = NULL; + + // + while (HasChild(tmpZones)) + { + // + idx = GetLowest(tmpZones); + has = IsValidIndex(idx); + if (!has) + { + break; + } + + // + XCDemandZone *iZone = tmpZones[idx]; + ArrayRemove( + tmpZones, + idx, + 1 // + ); + + // + // Validate Zone ... + has = + isBullish + ? IsBelowDiff( + iZone, + selectedZone.ob, + true // Ignore Inside ... + ) + : IsAboveDiff( + iZone, + selectedZone.ob, + true // Ignore Inside ... + ); + if (!has) + { + continue; + } + + // + has = + selectedDemand == NULL + ? true + : isBullish + ? selectedDemand.Lower() < iZone.Lower() + : selectedDemand.Upper() > iZone.Upper(); + if (!has) + { + continue; + } + + // + selectedDemand = iZone; + } + + // + has = selectedDemand != NULL; + if (has) + { + // + double iSL = + isBullish + ? selectedDemand.Lower() + : selectedDemand.Upper(); + double iSLDiff = MathAbs(iSL - pivot); + has = + iSLDiff > 0 && + iSLDiff <= maxAllowedSLDistanceInPoint * points; + if (has) + { + // + Add( + iSL, + sls // + ); + } + } + + // + Clean(tmpZones); + ZeroMemory(selectedDemand); + } + + // + // Support Zones ... + // has = workingZone.HasSupportZones(); + // if (has) + // { + // // + // XCSupportZone *tmpZones[]; + // Copy( + // workingZone.supportZones, + // tmpZones // + // ); + // XCSupportZone *selectedSupport = NULL; + + // // + // while (HasChild(tmpZones)) + // { + // // + // idx = GetLowest(tmpZones); + // has = IsValidIndex(idx); + // if (!has) + // { + // break; + // } + + // // + // XCSupportZone *iZone = tmpZones[idx]; + // ArrayRemove( + // tmpZones, + // idx, + // 1 // + // ); + + // // + // // Validate Zone ... + // has = + // isBullish + // ? IsBelowDiff( + // iZone, + // selectedZone.ob, + // true // Ignore Inside ... + // ) + // : IsAboveDiff( + // iZone, + // selectedZone.ob, + // true // Ignore Inside ... + // ); + // if (!has) + // { + // continue; + // } + + // // + // has = + // selectedSupport == NULL + // ? true + // : isBullish + // ? selectedSupport.Lower() < iZone.Lower() + // : selectedSupport.Upper() > iZone.Upper(); + // if (!has) + // { + // continue; + // } + + // // + // selectedSupport = iZone; + + // // + // } + + // // + // has = selectedSupport != NULL; + // if (has) + // { + // // + // double iSL = isBullish + // ? selectedSupport.Lower() + // : selectedSupport.Upper(); + // double iSLDiff = MathAbs(iSL - pivot); + // has = + // iSLDiff > 0 && + // iSLDiff <= maxAllowedSLDistanceInPoint * points; + // if (has) + // { + // // + // Add( + // iSL, + // sls // + // ); + // } + // } + + // // + // Clean(tmpZones); + // ZeroMemory(selectedSupport); + // } + + // + // Supply Zones ... + has = workingZone.HasSupplyZones(); + if (has) + { + // + XCSupplyZone *tmpZones[]; + Copy( + workingZone.supplyZones, + tmpZones // + ); + XCSupplyZone *selectedSupply = NULL; + + // + while (HasChild(tmpZones)) + { + // + idx = GetHighest(tmpZones); + has = IsValidIndex(idx); + if (!has) + { + break; + } + + // + XCSupplyZone *iZone = tmpZones[idx]; + ArrayRemove( + tmpZones, + idx, + 1 // + ); + + // + // Validate Zone ... + has = + !isBullish + ? IsAboveDiff( + iZone, + selectedZone.ob, + true // Ignore Inside ... + ) + : IsBelowDiff( + iZone, + selectedZone.ob, + true // Ignore Inside ... + ); + if (!has) + { + continue; + } + + // + has = + selectedSupply == NULL + ? true + : !isBullish + ? selectedSupply.Upper() > iZone.Upper() + : selectedSupply.Lower() < iZone.Lower(); + if (!has) + { + continue; + } + + // + selectedSupply = iZone; + + // + } + + // + has = selectedSupply != NULL; + if (has) + { + // + double iSL = + !isBullish + ? selectedSupply.Upper() + : selectedSupply.Lower(); + double iSLDiff = MathAbs(iSL - pivot); + has = + iSLDiff > 0 && + iSLDiff <= maxAllowedSLDistanceInPoint * points; + if (has) + { + // + Add( + iSL, + sls // + ); + } + } + + // + Clean(tmpZones); + ZeroMemory(selectedSupply); + } + + // + // Resistance Zones ... + // has = workingZone.HasDemandZones(); + // if (has) + // { + // // + // XCResistanceZone *tmpZones[]; + // Copy( + // workingZone.resistanceZones, + // tmpZones // + // ); + // XCResistanceZone *selectedResistance = NULL; + + // // + // while (HasChild(tmpZones)) + // { + // // + // idx = GetHighest(tmpZones); + // has = IsValidIndex(idx); + // if (!has) + // { + // break; + // } + + // // + // XCResistanceZone *iZone = tmpZones[idx]; + // ArrayRemove( + // tmpZones, + // idx, + // 1 // + // ); + + // // + // // Validate Zone ... + // has = + // !isBullish + // ? IsAboveDiff( + // iZone, + // selectedZone.ob, + // true // Ignore Inside ... + // ) + // : IsBelowDiff( + // iZone, + // selectedZone.ob, + // true // Ignore Inside ... + // ); + // if (!has) + // { + // continue; + // } + + // // + // has = + // selectedResistance == NULL + // ? true + // : !isBullish + // ? selectedResistance.Upper() < iZone.Upper() + // : selectedResistance.Lower() > iZone.Lower(); + // if (!has) + // { + // continue; + // } + + // // + // selectedResistance = iZone; + + // // + // } + + // // + // has = selectedResistance != NULL; + // if (has) + // { + // // + // double iSL = + // !isBullish + // ? selectedResistance.Upper() + // : selectedResistance.Lower(); + // double iSLDiff = MathAbs(iSL - pivot); + // has = + // iSLDiff > 0 && + // iSLDiff <= maxAllowedSLDistanceInPoint * points; + // if (has) + // { + // // + // Add( + // iSL, + // sls // + // ); + // } + // } + + // // + // Clean(tmpZones); + // ZeroMemory(selectedResistance); + // } + + // + // Cleanp Resources ... + + // + cBar.Clean(); + // passedBar.Clean(); + result = HasChild(sls); + + // + return result; +} + + +// \ No newline at end of file diff --git a/Indicators/x-saherelm.x121.xwz.mq5 b/Indicators/x-saherelm.x121.xwz.mq5 index 44bec6c9..626ee8e9 100644 --- a/Indicators/x-saherelm.x121.xwz.mq5 +++ b/Indicators/x-saherelm.x121.xwz.mq5 @@ -60,6 +60,12 @@ input group "ADX Detection"; input int adxLength = 14; // ADX Length input double adxThreshold = 25; // ADX Threshold for Strong Trends +// +input group "POI Detection"; +input ENUM_TIMEFRAMES orderBlockTF = PERIOD_H1; // Order Block Detection Time Frame +input ENUM_TIMEFRAMES fairValueGapTF = PERIOD_M15; // Fair Value Gap Detection Time Frame +input ENUM_TIMEFRAMES supDemTF = PERIOD_H4; // Supply and Demand Detection Time Frame + // input group "Alert"; input bool mXWZEnableAlerts = true; // Enable Alerts @@ -1880,11 +1886,26 @@ void DetectOrderBlock(XOHCL &bar) return; } + // + int iBarIndex = bar.Index(orderBlockTF); + + // + XOHCL iBar; + bool isInited = iBar.Init( + bar.symbol, + orderBlockTF, + iBarIndex // + ); + if (!isInited) + { + return; + } + // XOHCL zoneBar; ENUM_X_DIRECTION zoneDir; has = mXWZBarAnalyser.HasOrderBlock( - bar, + iBar, zoneBar, zoneDir, mXWZOBFVGSameBars // @@ -1928,7 +1949,7 @@ void DetectOrderBlock(XOHCL &bar) zoneDir, startedBar, isBodyOut, - bar.period // + iBar.period // ); // @@ -1960,7 +1981,7 @@ void DetectOrderBlock(XOHCL &bar) activationBar, isActivationBarBodyIn, false, - bar.period // + iBar.period // ); // @@ -2005,7 +2026,7 @@ void DetectOrderBlock(XOHCL &bar) breakedBar, isBodyOut, false, - bar.period // + iBar.period // ); // @@ -2078,6 +2099,7 @@ void DetectOrderBlock(XOHCL &bar) } // + iBar.Clean(); zoneBar.Clean(); } @@ -2096,12 +2118,27 @@ void DetectFairValueGap(XOHCL &bar) return; } + // + int iBarIndex = bar.Index(fairValueGapTF); + + // + XOHCL iBar; + bool isInited = iBar.Init( + bar.symbol, + fairValueGapTF, + iBarIndex // + ); + if (!isInited) + { + return; + } + // XOHCL zoneEndBar; XOHCL zoneStartBar; ENUM_X_DIRECTION zoneDir; has = mXWZBarAnalyser.HasFairValueGap( - bar, + iBar, zoneStartBar, zoneEndBar, zoneDir, @@ -2149,7 +2186,7 @@ void DetectFairValueGap(XOHCL &bar) zoneDir, startedBar, isBodyOut, - bar.period // + iBar.period // ); // @@ -2182,7 +2219,7 @@ void DetectFairValueGap(XOHCL &bar) activationBar, isActivationBarBodyIn, false, - bar.period // + iBar.period // ); // @@ -2215,7 +2252,7 @@ void DetectFairValueGap(XOHCL &bar) breakedBar, isBodyOut, false, - bar.period // + iBar.period // ); // @@ -2291,6 +2328,7 @@ void DetectFairValueGap(XOHCL &bar) } // + iBar.Clean(); zoneEndBar.Clean(); zoneStartBar.Clean(); } @@ -2310,6 +2348,21 @@ void DetectSupplyZone(XOHCL &bar) return; } + // + int iBarIndex = bar.Index(supDemTF); + + // + XOHCL iBar; + bool isInited = iBar.Init( + bar.symbol, + supDemTF, + iBarIndex // + ); + if (!isInited) + { + return; + } + // int range = mXWZSuResRange * 2; @@ -2317,7 +2370,7 @@ void DetectSupplyZone(XOHCL &bar) XOHCL zoneBar; ENUM_X_DIRECTION zoneDir = X_DIRECTION_BEARISH; has = mXWZBarAnalyser.HasResistance( - bar, + iBar, zoneBar, range // ); @@ -2361,7 +2414,7 @@ void DetectSupplyZone(XOHCL &bar) zoneDir, startedBar, isBodyOut, - bar.period // + iBar.period // ); // @@ -2393,7 +2446,7 @@ void DetectSupplyZone(XOHCL &bar) activationBar, isActivationBarBodyIn, false, - bar.period // + iBar.period // ); // @@ -2425,7 +2478,7 @@ void DetectSupplyZone(XOHCL &bar) breakedBar, isBodyOut, false, - bar.period // + iBar.period // ); // @@ -2498,6 +2551,7 @@ void DetectSupplyZone(XOHCL &bar) } // + iBar.Clean(); zoneBar.Clean(); } @@ -2516,6 +2570,21 @@ void DetectDemandZone(XOHCL &bar) return; } + // + int iBarIndex = bar.Index(supDemTF); + + // + XOHCL iBar; + bool isInited = iBar.Init( + bar.symbol, + supDemTF, + iBarIndex // + ); + if (!isInited) + { + return; + } + // int range = mXWZSuResRange * 2; @@ -2523,7 +2592,7 @@ void DetectDemandZone(XOHCL &bar) XOHCL zoneBar; ENUM_X_DIRECTION zoneDir = X_DIRECTION_BULLISH; has = mXWZBarAnalyser.HasSupport( - bar, + iBar, zoneBar, range // ); @@ -2567,7 +2636,7 @@ void DetectDemandZone(XOHCL &bar) zoneDir, startedBar, isBodyOut, - bar.period // + iBar.period // ); // @@ -2599,7 +2668,7 @@ void DetectDemandZone(XOHCL &bar) activationBar, isActivationBarBodyIn, false, - bar.period // + iBar.period // ); // @@ -2631,7 +2700,7 @@ void DetectDemandZone(XOHCL &bar) breakedBar, isBodyOut, false, - bar.period // + iBar.period // ); // @@ -2704,6 +2773,7 @@ void DetectDemandZone(XOHCL &bar) } // + iBar.Clean(); zoneBar.Clean(); } diff --git a/Libraries/x-saherelm.common.lib.mq5 b/Libraries/x-saherelm.common.lib.mq5 index 900e34f9..423a96b2 100644 --- a/Libraries/x-saherelm.common.lib.mq5 +++ b/Libraries/x-saherelm.common.lib.mq5 @@ -7757,6 +7757,40 @@ void CleanupArray( ); } +template +void CleanupArray( + int &removedIndexes[], + T &buffer[] // Buffer to Cleanup ... +) +{ + // + bool isValid = HasChild(buffer) && + HasChild(removedIndexes); + if (!isValid) + { + return; + } + + // + for (int i = 0; i < ArraySize(removedIndexes); i++) + { + // + int idx = removedIndexes[i]; + if (IsValidIndex(idx) && ArraySize(buffer) > idx) + { + // + ArrayRemove( + buffer, + idx, + 1 // + ); + } + } + + // + Clean(removedIndexes); +} + // // Search Array For Specific Item ... template diff --git a/Libraries/x-saherelm.x-poi.extensions.lib.mq5 b/Libraries/x-saherelm.x-poi.extensions.lib.mq5 index bbcf0fd1..053de36d 100644 --- a/Libraries/x-saherelm.x-poi.extensions.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.extensions.lib.mq5 @@ -1265,6 +1265,65 @@ bool IsBoxUsed( return result; } +/** + * Find an Inside Box of source in a Collection ... + * + * @param index: int, Founded Index ... + * @param source: XBoxZone instance ... + * @param dest: XBoxZone instance Collection ... + * + * @return ( bool ) + */ +bool HasInsideBox( + int &index, + XBoxZone &source, + XBoxZone &dest[] // +) +{ + // + bool result = false; + + // + index = -1; + + // + result = source.IsValid() && + HasChild(dest); + + // + int count = ArraySize(dest); + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox = dest[i]; + + // + bool isInside = !iBox.IsSameAs(source) && + IsBoxInside( + iBox, + source // + ); + if (isInside) + { + // + index = i; + iBox.Clean(); + + // + break; + } + + // + iBox.Clean(); + } + + // + result = IsValidIndex(index); + + // + return result; +} + /** * Converts to XBoxZone ... * diff --git a/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 b/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 index ce13d876..29230fe0 100644 --- a/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 @@ -301,6 +301,27 @@ class XCX121SMCXWZSignalDetector : public XCBase X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; X121Conditions visionXConditions = visionConditions.x121Conditions; + // + // Scores ... + + // + // Decision ... + double decisionBullishScore = 0; + double decisionBearishScore = 0; + decisionXConditions.GenerateScore( + decisionBullishScore, + decisionBearishScore // + ); + + // + // Analyse ... + double analyseBullishScore = 0; + double analyseBearishScore = 0; + analyseXConditions.GenerateScore( + analyseBullishScore, + analyseBearishScore // + ); + // // Select Drawer Class ... XCPOIDrawer *drawer = visionCycleHelper.mPOIDrawer; @@ -313,17 +334,12 @@ class XCX121SMCXWZSignalDetector : public XCBase double targets[]; double reward = 0; XBoxZone signalBox; - XOBFVG selectedZone; double amountPercent = 0; bool hasPriority = false; bool hasSignalBox = false; bool hasRewardAmount = false; - bool hasSelectedZone = false; bool isSignalBoxReversal = false; - bool isSelectedZoneReversal = false; - bool hasSelectedConsolidationZone = false; - XConsolidationZone selectedConsolidationZone; - ENUM_X_DIRECTION selectedZoneDir = 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; @@ -367,300 +383,165 @@ class XCX121SMCXWZSignalDetector : public XCBase analyseState, decisionState // ); - } - - // - bool hasWaitingZones = hasWorkingZone && - workingZone.HasWaitingZones(); - - // - // - // - - // - // Check Conditions if Has Inside Zones ... - bool hasInsideZones = hasWorkingZone && - workingZone.HasInsideZones(); - if (hasInsideZones) - { - // - int selectedIDX = -1; - int count = workingZone.CountInsideZones(); - for (int i = 0; i < count; i++) - { - // - bool has = DetectSelectedZoneConditions( - isSelectedZoneReversal, - workingZone.insideZones[i], - decisionState, - decisionXConditions // - ); - - // - if (has) - { - // - selectedIDX = i; - selectedZone = workingZone.insideZones[i]; - - // - break; - } - } // - if (IsValidIndex(selectedIDX)) + bool isDestroyed = workingZone.IsDestroyed( + zIndex, + period // + ); + if (isDestroyed) { // - ArrayRemove( - workingZone.insideZones, - selectedIDX, - 1 // - ); - - // - hasSelectedZone = selectedZone.IsValid(); - provider = X121SMC_XWZ_PROVIDER_PRICE_INSIDE_ZONE; + result = false; + workingZone.Clean(); + hasWorkingZone = false; } } - // - // Check Conditions if Has Breaked Zones ... - bool hasBreakedZones = hasWorkingZone && - workingZone.HasBreakedZones(); - if (hasBreakedZones) - { - // // - // if (!hasSelectedZone) - // { - // // - // int selectedIDX = -1; - // int count = workingZone.CountBreakedZones(); - // for (int i = 0; i < count; i++) - // { - // // - // bool has = DetectSelectedZoneConditions( - // isSelectedZoneReversal, - // workingZone.breakedZones[i], - // decisionState, - // decisionXConditions // - // ); - - // // - // if (has) - // { - // // - // selectedIDX = i; - // selectedZone = workingZone.breakedZones[i]; - - // // - // break; - // } - // } - - // // - // if (IsValidIndex(selectedIDX)) - // { - // // - // ArrayRemove( - // workingZone.breakedZones, - // selectedIDX, - // 1 // - // ); - - // // - // hasSelectedZone = selectedZone.IsValid(); - // provider = X121SMC_XWZ_PROVIDER_ACTIVATED_ZONE; - // } - // } - } - // // // // - bool hasInsideBoxes = hasWorkingZone && - workingZone.HasInsideBoxes(); - if (hasInsideBoxes) + // Waiting Box Detected ... + bool hasWaitingBoxes = hasWorkingZone && + workingZone.HasWaitingBoxes(); + if (hasWaitingBoxes) { // XOHCL zBar; XOHCL cBar; + XOHCL pBar; int count = 0; + int idx = -1; bool has = false; - XBoxZone tmpSelectedBox; - int tmpSelectedBoxIDX = -1; // - has = zBar.Init( + bool isInited = zBar.Init( symbol, period, zIndex // ); - has = has && - zBar.GetPreviousBar(cBar); - if (has) + isInited = + isInited && + zBar.GetPreviousBar(cBar); + isInited = + isInited && + cBar.GetPreviousBar(pBar); + + // + count = workingZone.CountWaitingBoxes(); + for (int i = 0; i < count; i++) { // - count = workingZone.CountInsideBoxes(); - for (int i = 0; i < count; i++) + XBoxZone iBox = workingZone.waitingBoxes[i]; + ENUM_X_DIRECTION iDir = iBox.dir; + bool isBullish = IsBullish(iDir); + + // + // Check Price Rejection ... + + // + bool hasBullishFiboPressure = + decisionCycleHelper + .mBarAnalyser + .HasFiboPressure( + cBar, + X_DIRECTION_BULLISH, + X_FIBO_LEVEL_382 // + ); + + // + bool hasBearishFiboPressure = + decisionCycleHelper + .mBarAnalyser + .HasFiboPressure( + cBar, + X_DIRECTION_BEARISH, + X_FIBO_LEVEL_382 // + ); + + // + // Bullish Rejection ... + bool isBullishRejected = + // + isInited && + isBullish && + cBar.low < pBar.low && + zBar.low > iBox.upper && + cBar.low <= iBox.upper && + zBar.open > iBox.upper && + hasBullishFiboPressure && + cBar.GetLowShadow() > pBar.GetLowShadow() + // + ; + + // + // Bearish Rejection ... + bool isBearishhRejected = + // + isInited && + !isBullish && + cBar.high > pBar.high && + zBar.open < iBox.lower && + zBar.high < iBox.lower && + hasBearishFiboPressure && + cBar.high >= iBox.lower && + cBar.GetHighShadow() > pBar.GetHighShadow() + // + ; + + // + has = isBullishRejected || + isBearishhRejected; + if (has) { // - tmpSelectedBox = workingZone.insideBoxes[i]; - - // - bool isBullish = tmpSelectedBox.IsBullish(); - bool isBearish = tmpSelectedBox.IsBearish(); - - // - bool hasFiboPressure = - visionCycleHelper - .mBarAnalyser - .HasFiboPressure( - cBar, - tmpSelectedBox.dir, - X_FIBO_LEVEL_382 // - ); - - // - bool isBullishRejectedUpper = - cBar.low < tmpSelectedBox.upper && - cBar.GetDown() > tmpSelectedBox.upper; - - // - bool isBullishRejectedLower = - cBar.low < tmpSelectedBox.lower && - cBar.GetDown() > tmpSelectedBox.lower; - - // - bool isBearishRejectedUpper = - cBar.high > tmpSelectedBox.upper && - cBar.GetUp() < tmpSelectedBox.upper; - - // - bool isBearishRejectedLower = - cBar.high > tmpSelectedBox.lower && - cBar.GetUp() < tmpSelectedBox.lower; - - // - bool isBullishRejected = - // isBullishRejectedUpper || - isBullishRejectedLower; - - // - bool isBearishRejected = - isBearishRejectedUpper - // || isBearishRejectedLower - ; - - // - bool isMaWapBullish = - // - (decisionXConditions.isX3MaBullishState && - decisionXConditions.isX3MaBullishOrdered) - // - && - // - (decisionXConditions.isVWapBullishState && - decisionXConditions.isVWapBullishOrdered) - // - ; - - // - bool isMaWapBearish = - // - (decisionXConditions.isX3MaBearishState && - decisionXConditions.isX3MaBearishOrdered) - // - && - // - (decisionXConditions.isVWapBearishState && - decisionXConditions.isVWapBearishOrdered) - // - ; - - // - bool isX2MaWapInside = - // - (decisionXConditions.x3maFastBuffer[cIndex] < tmpSelectedBox.upper && - decisionXConditions.x3maMidBuffer[cIndex] < tmpSelectedBox.upper && - decisionXConditions.x3maFastBuffer[cIndex] > tmpSelectedBox.lower && - decisionXConditions.x3maMidBuffer[cIndex] > tmpSelectedBox.lower) - // - && - // - (decisionXConditions.vwapFastBuffer[cIndex] < tmpSelectedBox.upper && - decisionXConditions.vwapMidBuffer[cIndex] < tmpSelectedBox.upper && - decisionXConditions.vwapFastBuffer[cIndex] > tmpSelectedBox.lower && - decisionXConditions.vwapMidBuffer[cIndex] > tmpSelectedBox.lower) - // - ; - - // - bool isBullishConditions = - // - isBullish && - isMaWapBearish && - isX2MaWapInside && - hasFiboPressure && - isBullishRejected && - cBar.low < cBar.GetDown() - // - ; - - // - bool isBearishConditions = - // - isBearish && - isMaWapBullish && - isX2MaWapInside && - hasFiboPressure && - isBearishRejected && - cBar.high > cBar.GetUp() - // - ; - - // - has = isBullishConditions || - isBearishConditions; - if (!has) - { - // - tmpSelectedBox.Clean(); - continue; - } - - // - tmpSelectedBoxIDX = i; - signalBox = tmpSelectedBox; - - // - tmpSelectedBox.Clean(); - break; + idx = i; + signalBox = iBox; + hasSignalBox = has; + signalBoxDir = iBox.dir; + isSignalBoxReversal = false; + provider = X121SMC_XWZ_PROVIDER_ACTIVATED_ZONE; } + + // + iBox.Clean(); } // - isSignalBoxReversal = false; - hasSignalBox = signalBox.IsValid(); - if (hasSignalBox) + // Remove Signal Box from Waiting Boxes of + // Working Zone ... + if (hasSignalBox && + IsValidIndex(idx)) { // ArrayRemove( - workingZone.insideBoxes, - tmpSelectedBoxIDX, + workingZone.waitingBoxes, + idx, 1 // ); } + // + // Cleanup Resources ... + // zBar.Clean(); cBar.Clean(); - tmpSelectedBox.Clean(); + pBar.Clean(); } // + // Check Conditions if Has Inside Boxes ... + bool hasInsideBoxes = hasWorkingZone && + workingZone.HasInsideBoxes(); + if (hasInsideBoxes) + { + } + + // + // Check Conditions if has Breaked Boxes ... bool hasBreakedBoxes = hasWorkingZone && workingZone.HasBreakedBoxes(); if (hasBreakedBoxes) @@ -668,8 +549,124 @@ class XCX121SMCXWZSignalDetector : public XCBase } // + // Checking Other Conditions ... if (!hasSignalBox) { + // + // Score Conditions ... + double scoreMultiplier = 3; + bool isBullishScorePassed = + // + analyseBullishScore > (analyseBearishScore * scoreMultiplier) && + decisionBullishScore > (decisionBearishScore * scoreMultiplier) + // + ; + bool isBearishScorePassed = + // + analyseBearishScore > (analyseBullishScore * scoreMultiplier) && + decisionBearishScore > (decisionBullishScore * scoreMultiplier) + // + ; + + // + // X3Ma ... + + // + // X3Ma Bullish ... + bool isX3MaBullish = + // + decisionXConditions.isX3MaBullishState && + decisionXConditions.isX3MaSwitchedToBullishOrdered && + decisionXConditions.x3maMidBuffer[1] > decisionXConditions.x3maSlowBuffer[1] + // + ; + + // + // X3Ma Bearish ... + bool isX3MaBearish = + // + decisionXConditions.isX3MaBearishState && + decisionXConditions.isX3MaSwitchedToBearishOrdered && + decisionXConditions.x3maMidBuffer[1] < decisionXConditions.x3maSlowBuffer[1] + // + ; + + // + bool isX3MaHasCondition = + (isX3MaBullish && + isBullishScorePassed) || + (isX3MaBearish && + isBearishScorePassed); + + // + // VWap ... + + // + // VWap Bullish ... + bool isVWapBullish = + // + decisionXConditions.isVWapBullishState && + decisionXConditions.isVWapSwitchedToBullishOrdered && + decisionXConditions.vwapMidBuffer[1] > decisionXConditions.vwapSlowBuffer[1] + // + ; + + // + // VWap Bearish ... + bool isVWapBearish = + // + decisionXConditions.isVWapBearishState && + decisionXConditions.isVWapSwitchedToBearishOrdered && + decisionXConditions.vwapMidBuffer[1] < decisionXConditions.vwapSlowBuffer[1] + // + ; + + // + bool isVWapHasCondition = + (isVWapBullish && + isBullishScorePassed) || + (isVWapBearish && + isBearishScorePassed); + + // + // Checking Other Conditions XWZ Reject on EMA 20 ... + + // + // Check Has Conditions ... + bool hasXConditions = + (isX3MaHasCondition || + isVWapHasCondition); + + // + if (hasXConditions) + { + // + if (isX3MaHasCondition) + { + // + signalBoxDir = + isX3MaBullish + ? X_DIRECTION_BULLISH + : isX3MaBearish + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + } + + // + if (isVWapHasCondition) + { + // + signalBoxDir = + isVWapBullish + ? X_DIRECTION_BULLISH + : isVWapBearish + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + } + + // + Print("X Conditions ..."); + } } // @@ -677,285 +674,47 @@ class XCX121SMCXWZSignalDetector : public XCBase // // - // Double Check and Prepare Signal Conditions ... - // including Targets and SLs ... + // Check Priority Exists ... + hasPriority = workingZone + .DetectPriority( + priority, + signalBoxDir, + zIndex, + period // + ); // - if (hasSelectedZone) + // Check Price Reward and Amount Exists ... + hasRewardAmount = CalculateRiskReward( + priority, + reward, + amountPercent // + ); + + // + // Check Signal Conditions ... + if (hasSignalBox) { // int idx = -1; bool has = false; // - // Check Consolidation Zones for SL Handling ... - selectedZoneDir = - !isSelectedZoneReversal - ? selectedZone.GetDirection() - : Opposit(selectedZone.GetDirection()); - bool isSelectedZonDirBullish = IsBullish(selectedZoneDir); - - // - if (isSelectedZoneReversal) - { - provider = X121SMC_XWZ_PROVIDER_ACTIVATED_CHOCH; - } - - // - // Calculate Priority ... - hasPriority = - hasWorkingZone && - workingZone - .DetectPriority( - priority, - selectedZoneDir, - zIndex, - period // - ); - - // - // Calculate Risk Reward Ration based on Priority ... - hasRewardAmount = CalculateRiskReward( - priority, - reward, - amountPercent // + XCBoxObject *iObj; + has = drawer.DrawBox( + signalBox, + iObj // ); - - // - // Calculate Pivot and Point ... - - // - pivot = - isSelectedZonDirBullish - ? selectedZone.ob.Lower() - : selectedZone.ob.Upper(); - - // - point = - isSelectedZonDirBullish - ? selectedZone.ob.Upper() - : selectedZone.ob.Lower(); - - // - // Detect Targets ... - DetectSelectedZonesTargets( - targets, - selectedZone, - selectedZoneDir, - priority, - workingZone, - zIndex // - ); - - // - // Detect SLs ... - double iAtr = decisionXConditions.atrBuffer[0]; - iAtr *= 1.5; - - // - // Default SL is Pivot ... - if (pivot > 0) + if (has) { // - Add( - pivot, - sls // - ); + iObj.BoxWidth(1); + iObj.BoxColor(clrYellow); + iObj.BoxStyle(STYLE_SOLID); // - double iSL = iAtr * pivot; - Add( - iSL, - sls // - ); + Print("Signal Box Exists ..."); } - - // - DetectSelectedZoneSLCandidates( - sls, - selectedZone, - selectedZoneDir, - workingZone, - decisionXConditions, - zIndex, - maxAllowedSLDistanceInPoint // - ); - - // - // Summaries Conditions ... - result = - pivot > 0 && - point > 0 && - hasPriority && - hasRewardAmount && - HasDirection(selectedZoneDir); - if (result) - { - // - isBullish = IsBullish(selectedZoneDir); - isBearish = IsBearish(selectedZoneDir); - - // - Copy( - sls, - mConditions.sls // - ); - Copy( - targets, - mConditions.targets // - ); - - // - mConditions.pivot = pivot; - mConditions.point = point; - mConditions.reward = reward; - mConditions.setupTime = cTime; - mConditions.priority = priority; - mConditions.provider = provider; - mConditions.dir = selectedZoneDir; - mConditions.signalBox = signalBox; - mConditions.amountPercent = amountPercent; - } - - // - // Cleanup Resources ... - - // - Clean(sls); - Clean(targets); - selectedZone.Clean(); - selectedConsolidationZone.Clean(); - } - - // - if (hasSignalBox) - { - // // - // workingZone.mInsideZoneObjects.Clear(); - // workingZone.mBreakedZoneObjects.Clear(); - // workingZone.mWaitingZoneObjects.Clear(); - // workingZone.mWorkingZoneObjects.Clear(); - - // // - // XCBoxObject *iObj; - // signalBox.to = cTime; - // bool isCreated = drawer.CreateBox( - // signalBox, - // iObj // - // ); - - // // - // if (isCreated) - // { - // // - // iObj.BoxWidth(2); - // iObj.BoxColor(clrYellow); - // iObj.BoxStyle(STYLE_SOLID); - // } - - // // - // bool isSignalBoxBullishDir = signalBox.IsBullish(); - - // // - // // Calculate Priority ... - // hasPriority = - // hasWorkingZone && - // workingZone - // .DetectPriority( - // priority, - // signalBox.dir, - // zIndex, - // period // - // ); - - // // - // // Calculate Risk Reward Ration based on Priority ... - // hasRewardAmount = CalculateRiskReward( - // priority, - // reward, - // amountPercent // - // ); - - // // - // // Calculate Pivot and Point ... - - // // - // pivot = - // isSignalBoxBullishDir - // ? signalBox.lower - // : signalBox.upper; - - // // - // point = - // isSignalBoxBullishDir - // ? signalBox.upper - // : signalBox.lower; - - // // - // double defaultTarget = - // isSignalBoxBullishDir - // ? signalBox.upper - // : signalBox.lower; - // Add( - // defaultTarget, - // targets // - // ); - - // // - // // Detect SLs ... - // double iAtr = decisionXConditions.atrBuffer[0]; - // iAtr *= 1.5; - - // // - // double defaultSL = - // isSignalBoxBullishDir - // ? decisionXConditions.valesBuffer[0] - iAtr - // : decisionXConditions.peaksBuffer[0] + iAtr; - - // // - // Add( - // defaultSL, - // sls // - // ); - - // // - // // Summaries Conditions ... - // result = - // pivot > 0 && - // point > 0 && - // hasPriority && - // hasRewardAmount; - // if (result) - // { - // // - // isBullish = signalBox.IsBullish(); - // isBearish = signalBox.IsBearish(); - - // // - // Copy( - // sls, - // mConditions.sls // - // ); - // Copy( - // targets, - // mConditions.targets // - // ); - - // // - // mConditions.pivot = pivot; - // mConditions.point = point; - // mConditions.reward = reward; - // mConditions.setupTime = cTime; - // mConditions.priority = priority; - // mConditions.provider = provider; - // mConditions.dir = signalBox.dir; - // mConditions.signalBox = signalBox; - // mConditions.amountPercent = amountPercent; - // } - - // // - // signalBox.Clean(); - // hasSignalBox = false; } // @@ -968,73 +727,18 @@ class XCX121SMCXWZSignalDetector : public XCBase // workingZone.Draw( drawer, - true, // Draw Waiting Zones ... - true, // Draw Inside Zones ... - true, // Draw Breaked Zones ... - true, // Draw Supply Zone ... - true, // Draw Demand Zone ... - false, // Draw Supply Zones ... - false, // Draw Demand Zones ... - false, // Draw Support Zones ... - false // Draw Resistance Zones ... + // + true, // Draw Waiting Boxes ... + true, // Draw Inside Boxes ... + true, // Draw Breaked Boxes ... + // + true, // Draw Supply Zone ... + true, // Draw Demand Zone ... + true, // Draw Supply Zones ... + true, // Draw Demand Zones ... + true, // Draw Support Zones ... + true // Draw Resistance Zones ... ); - - // - // XCBaseObject *objects[]; - // drawer.DrawState( - // decisionState, - // objects, - // false, // DrawT icksZone ... - // true, // Ignore SwingHighs ... - // true, // Ignore SwingLows ... - // true, // Ignore SupportZones ... - // true, // Ignore ResistanceZones ... - // true, // Ignore SupplyZones ... - // true, // Ignore DemandZones ... - // true, // Ignore BullishOrderBlocks ... - // true, // Ignore BearishOrderBlocks ... - // true, // Ignore BullishFairValueGaps ... - // true, // Ignore BearishFairValueGaps ... - // true, // Ignore BullishRejectionBars ... - // true, // Ignore BearishRejectionBars ... - // true, // Ignore BullishMomentumBars ... - // true, // Ignore BearishMomentumBars ... - // true, // Ignore BullishConsolidationZones ... - // true // Ignore BearishConsolidationZones ... - // ); - - // // - // int count = 0; - // bool has = false; - - // // - // has = workingZone.HasSupplyZones(); - // if (has) - // { - // } - - // // - // has = workingZone.HasDemandZones(); - // if (has) - // { - // // - // count = workingZone.CountDemandZones(); - // for (int i = 0; i < count; i++) - // { - // // - // XCDemandZone *iZone = workingZone.demandZones[i]; - - // // - // XCDemandZoneObject *iObj; - // bool isCreated = drawer.CreateDemandZone( - // iZone, - // iObj // - // ); - // } - // } - - // // - // Print(""); } // diff --git a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 index 81d7f8e2..cb16b1fd 100644 --- a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 @@ -73,14 +73,10 @@ struct X121SMCStrategyXWZWorkingZone XCSupportZone *supportZones[]; XCResistanceZone *resistanceZones[]; - // - XOBFVG insideZones[]; - XOBFVG breakedZones[]; - XOBFVG waitingZones[]; - // XBoxZone insideBoxes[]; XBoxZone breakedBoxes[]; + XBoxZone waitingBoxes[]; XConsolidationZone consolidationZones[]; // @@ -115,14 +111,10 @@ struct X121SMCStrategyXWZWorkingZone Clean(supplyZones); Clean(demandZones); - // - Clean(insideZones); - Clean(waitingZones); - Clean(breakedZones); - // Clean(insideBoxes); Clean(breakedBoxes); + Clean(waitingBoxes); // Clean(supportZones); @@ -236,12 +228,12 @@ struct X121SMCStrategyXWZWorkingZone if (!has) { // - idx = GetHighest(htfState.supplyZones); + idx = GetHighest(mtfState.supplyZones); has = IsValidIndex(idx); if (has) { // - supplyZone = htfState.supplyZones[idx]; + supplyZone = mtfState.supplyZones[idx]; has = hh5 < supplyZone.Lower(); if (!has) { @@ -256,12 +248,12 @@ struct X121SMCStrategyXWZWorkingZone if (!has) { // - idx = GetLowest(htfState.demandZones); + idx = GetLowest(mtfState.demandZones); has = IsValidIndex(idx); if (has) { // - demandZone = htfState.demandZones[idx]; + demandZone = mtfState.demandZones[idx]; has = ll5 > demandZone.Upper(); if (!has) { @@ -310,13 +302,13 @@ struct X121SMCStrategyXWZWorkingZone ); } - // // - // // Support Zones ... + // + // Support Zones ... // has = HasSupportZones(); // if (!has) // { // // - // count = stfState.FilterSupportZones( + // count = mtfState.FilterSupportZones( // supportZones, // period, // XZONE_STATE_PASSED, @@ -330,13 +322,13 @@ struct X121SMCStrategyXWZWorkingZone // ); // } - // // - // // Resistance Zones ... + // + // Resistance Zones ... // has = HasResistanceZones(); // if (!has) // { // // - // count = stfState.FilterResistanceZones( + // count = mtfState.FilterResistanceZones( // resistanceZones, // period, // XZONE_STATE_PASSED, @@ -385,54 +377,113 @@ struct X121SMCStrategyXWZWorkingZone } // - // Detect OBFVG(s) ... - ExtractOBFVGs( - waitingZones, - mtfState, - stfState // - ); + // Waiting Zone Detection ... + XPOIState iState = mtfState; // - // Detect Waiting Zones based on STF and TTF ... - XOBFVG tmpWaitingZones[]; - count = ExtractOBFVGs( - tmpWaitingZones, - stfState, - ttfState // - ); - has = IsValidSize(count); + // Detect Waiting Zones ... + + // + // Using Order Blocks ... + has = iState.HasOrderBlocks(); if (has) { // - for (int i = 0; i < count; i++) + XCOrderBlock *obs[]; + count = iState.FilterOrderBlocks( + obs, + period, + XZONE_STATE_PASSED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_IGNORED, + false // + ); + + // + has = IsValidSize(count); + if (has) { // - XOBFVG iOBFVG = tmpWaitingZones[i]; + ToBox( + obs, + waitingBoxes // + ); + } + + // + Clean(obs); + } + + // + // Using Fair Value Gaps ... + has = iState.HasFairValueGaps(); + if (has) + { + // + XBoxZone boxes[]; + XCFVG *fvgs[]; + count = iState.FilterFairValueGaps( + fvgs, + period, + XZONE_STATE_PASSED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_IGNORED, + false // + ); + + // + has = IsValidSize(count); + if (has) + { + // + count = ToBox( + fvgs, + boxes // + ); // - idx = FindIndex( - iOBFVG, - waitingZones // - ); - has = IsValidIndex(idx); - if (has) + for (int i = 0; i < count; i++) { // - iOBFVG.Clean(); - continue; + XBoxZone iBox = boxes[i]; + + // + int idx = FindIndex( + iBox, + waitingBoxes // + ); + has = !IsValidIndex(idx); + if (has) + { + // + AddRef( + iBox, + waitingBoxes // + ); + } + + // + iBox.Clean(); } - - // - AddRef( - iOBFVG, - waitingZones // - ); - - // - iOBFVG.Clean(); } + + // + Clean(fvgs); + Clean(boxes); } + // + // Cleaning State ... + iState.Clean(); + // result = IsValid(); if (!result) @@ -511,945 +562,7 @@ struct X121SMCStrategyXWZWorkingZone } // - // Adding New OBFVG to Waiting Zones if not Exists ... - XOBFVG tmpWaitingZones[]; - count = ExtractOBFVGs( - tmpWaitingZones, - mtfState, - stfState // - ); - has = IsValidSize(count); - if (has) - { - // - AddIfNotExists( - tmpWaitingZones, - waitingZones // - ); - } - - // - // Detect Waiting Zones based on STF and TTF ... - Clean(tmpWaitingZones); - count = ExtractOBFVGs( - tmpWaitingZones, - stfState, - ttfState // - ); - has = IsValidSize(count); - if (has) - { - // - AddIfNotExists( - tmpWaitingZones, - waitingZones // - ); - } - - // - // Detect Waiting Zones based on TTF and TTF ... - Clean(tmpWaitingZones); - count = ExtractOBFVGs( - tmpWaitingZones, - stfState, - stfState // - ); - has = IsValidSize(count); - if (has) - { - // - AddIfNotExists( - tmpWaitingZones, - waitingZones // - ); - } - - // - // Since Usig States for Extracting Supply/Demand or - // Support/Resistance Zones and State's has Max Alllowed Restrication ... - // we have to Manage new Zones and also Hold's Breaked Zones ... - - // - // MTF STF ... - - // - // Supply Zones ... - XCSupplyZone *tmpSupplies[]; - count = mtfState.FilterSupplyZones( - tmpSupplies, - NULL, - XZONE_STATE_PASSED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_IGNORED, - false // - ); - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = ToBox( - iBox, - tmpSupplies[i] // - ); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - // Find Index ... - - // - idx = FindIndex( - iBox, - insideBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - idx = FindIndex( - iBox, - breakedBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - idx = FindIndex( - tmpSupplies[i], - supplyZones // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - // Checking Price Validation ... - has = cBar.high < tmpSupplies[i].Lower(); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - Add( - tmpSupplies[i], - supplyZones // - ); - - // - iBox.Clean(); - } - } - Clean(tmpSupplies); - - // - // Demand Zones ... - XCDemandZone *tmpDemands[]; - count = mtfState.FilterDemandZones( - tmpDemands, - NULL, - XZONE_STATE_PASSED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_IGNORED, - false // - ); - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = ToBox( - iBox, - tmpDemands[i] // - ); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - // Find Index ... - - // - idx = FindIndex( - iBox, - insideBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - idx = FindIndex( - iBox, - breakedBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - idx = FindIndex( - tmpDemands[i], - demandZones // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - // Checking Price Validation ... - has = cBar.low > tmpDemands[i].Upper(); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - Add( - tmpDemands[i], - demandZones // - ); - - // - iBox.Clean(); - } - } - Clean(tmpDemands); - - // // - // // Support Zones ... - // XCSupportZone *tmpSupports[]; - // count = stfState.FilterSupportZones( - // tmpSupports, - // period, - // XZONE_STATE_PASSED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_IGNORED, - // false // - // ); - // has = IsValidSize(count); - // if (has) - // { - // // - // for (int i = 0; i < count; i++) - // { - // // - // XBoxZone iBox; - // has = ToBox( - // iBox, - // tmpSupports[i] // - // ); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // // Find Index ... - - // // - // idx = FindIndex( - // iBox, - // insideBoxes // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // idx = FindIndex( - // iBox, - // breakedBoxes // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // idx = FindIndex( - // tmpSupports[i], - // supportZones // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // // Checking Price Validation ... - // has = cBar.low > tmpSupports[i].Upper(); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // Add( - // tmpSupports[i], - // supportZones // - // ); - - // // - // iBox.Clean(); - // } - // } - // Clean(tmpSupports); - - // // - // // Resistance Zones .. - // XCResistanceZone *tmpResistances[]; - // count = stfState.FilterResistanceZones( - // tmpResistances, - // period, - // XZONE_STATE_PASSED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_IGNORED, - // false // - // ); - // has = IsValidSize(count); - // if (has) - // { - // // - // for (int i = 0; i < count; i++) - // { - // // - // XBoxZone iBox; - // has = ToBox( - // iBox, - // tmpResistances[i] // - // ); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // // Find Index ... - - // // - // idx = FindIndex( - // iBox, - // insideBoxes // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // idx = FindIndex( - // iBox, - // breakedBoxes // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // idx = FindIndex( - // tmpResistances[i], - // resistanceZones // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // // Checking Price Validation ... - // has = cBar.high < tmpResistances[i].Lower(); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // Add( - // tmpResistances[i], - // resistanceZones // - // ); - - // // - // iBox.Clean(); - // } - // } - // Clean(tmpResistances); - - // - // STF TTF ... - - // // - // // Supply Zones ... - // count = stfState.FilterSupplyZones( - // tmpSupplies, - // NULL, - // XZONE_STATE_PASSED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_IGNORED, - // false // - // ); - // has = IsValidSize(count); - // if (has) - // { - // // - // for (int i = 0; i < count; i++) - // { - // // - // XBoxZone iBox; - // has = ToBox( - // iBox, - // tmpSupplies[i] // - // ); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // // Find Index ... - - // // - // idx = FindIndex( - // iBox, - // insideBoxes // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // idx = FindIndex( - // iBox, - // breakedBoxes // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // idx = FindIndex( - // tmpSupplies[i], - // supplyZones // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // // Checking Price Validation ... - // has = cBar.high < tmpSupplies[i].Lower(); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // Add( - // tmpSupplies[i], - // supplyZones // - // ); - - // // - // iBox.Clean(); - // } - // } - // Clean(tmpSupplies); - - // // - // // Demand Zones ... - // count = stfState.FilterDemandZones( - // tmpDemands, - // NULL, - // XZONE_STATE_PASSED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_IGNORED, - // false // - // ); - // has = IsValidSize(count); - // if (has) - // { - // // - // for (int i = 0; i < count; i++) - // { - // // - // XBoxZone iBox; - // has = ToBox( - // iBox, - // tmpDemands[i] // - // ); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // // Find Index ... - - // // - // idx = FindIndex( - // iBox, - // insideBoxes // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // idx = FindIndex( - // iBox, - // breakedBoxes // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // idx = FindIndex( - // tmpDemands[i], - // demandZones // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // // Checking Price Validation ... - // has = cBar.low > tmpDemands[i].Upper(); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // Add( - // tmpDemands[i], - // demandZones // - // ); - - // // - // iBox.Clean(); - // } - // } - // Clean(tmpDemands); - - // // - // // Support Zones ... - // count = ttfState.FilterSupportZones( - // tmpSupports, - // period, - // XZONE_STATE_PASSED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_IGNORED, - // false // - // ); - // has = IsValidSize(count); - // if (has) - // { - // // - // for (int i = 0; i < count; i++) - // { - // // - // XBoxZone iBox; - // has = ToBox( - // iBox, - // tmpSupports[i] // - // ); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // // Find Index ... - - // // - // idx = FindIndex( - // iBox, - // insideBoxes // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // idx = FindIndex( - // iBox, - // breakedBoxes // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // idx = FindIndex( - // tmpSupports[i], - // supportZones // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // // Checking Price Validation ... - // has = cBar.low > tmpSupports[i].Upper(); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // Add( - // tmpSupports[i], - // supportZones // - // ); - - // // - // iBox.Clean(); - // } - // } - // Clean(tmpSupports); - - // // - // // Resistance Zones .. - // count = ttfState.FilterResistanceZones( - // tmpResistances, - // period, - // XZONE_STATE_PASSED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_IGNORED, - // false // - // ); - // has = IsValidSize(count); - // if (has) - // { - // // - // for (int i = 0; i < count; i++) - // { - // // - // XBoxZone iBox; - // has = ToBox( - // iBox, - // tmpResistances[i] // - // ); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // // Find Index ... - - // // - // idx = FindIndex( - // iBox, - // insideBoxes // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // idx = FindIndex( - // iBox, - // breakedBoxes // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // idx = FindIndex( - // tmpResistances[i], - // resistanceZones // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // // Checking Price Validation ... - // has = cBar.high < tmpResistances[i].Lower(); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // Add( - // tmpResistances[i], - // resistanceZones // - // ); - - // // - // iBox.Clean(); - // } - // } - // Clean(tmpResistances); - - // - // - // - - // - // Consolidation Zones ... - has = ttfState.HasConsolidationZones(); - if (has) - { - // - Copy( - ttfState.consolidationZones, - consolidationZones // - ); - CleanupArray( - consolidationZones, - 50 // - ); - } - - // - // - // - - // - // Detect Price Inside Zones ... - has = HasWaitingZones(); - if (has) - { - // - int mustRemove[]; - count = CountWaitingZones(); - for (int i = 0; i < count; i++) - { - // - XOBFVG iOBFVG = waitingZones[i]; - - // - bool isInside = - // - zBar.high < iOBFVG.ob.Upper() && - zBar.low > iOBFVG.ob.Lower() && - // - cBar.high < iOBFVG.ob.Upper() && - cBar.low > iOBFVG.ob.Lower() - // - ; - if (isInside) - { - // - idx = FindIndex( - iOBFVG, - insideZones // - ); - has = IsValidSize(idx); - if (!has) - { - // - Add( - i, - mustRemove // - ); - - // - AddRef( - iOBFVG, - insideZones // - ); - } - } - } - - // - has = HasChild(mustRemove); - if (has) - { - // - count = ArraySize(mustRemove); - for (int i = 0; i < count; i++) - { - // - ArrayRemove( - waitingZones, - mustRemove[i], - 1 // - ); - } - } - - // - Clean(mustRemove); - } - - // - // Here we Looking for Price Inside Supply or Demand Zones ... + // Update Exists Zones ... // // Supply Zones ... @@ -1457,79 +570,109 @@ struct X121SMCStrategyXWZWorkingZone if (has) { // - int mustRemove[]; + int removeIDXs[]; count = CountSupplyZones(); for (int i = 0; i < count; i++) { // XCSupplyZone *iZone = supplyZones[i]; + ENUM_X_DIRECTION iDir = X_DIRECTION_BEARISH; // - bool isInside = - // - zBar.high < iZone.Upper() && - zBar.low > iZone.Lower() && - // - cBar.high < iZone.Upper() && - cBar.low > iZone.Lower() - // - ; - if (isInside) + XBoxZone iBox; + bool hasBox = ToBox( + iBox, + iZone // + ); + if (!hasBox) { // - XBoxZone iBox; - has = ToBox( - iBox, - iZone // - ); - if (has) - { - // - idx = FindIndex( - iBox, - insideBoxes // - ); - has = IsValidSize(idx); - if (!has) - { - // - Add( - i, - mustRemove // - ); + iBox.Clean(); + continue; + } - // - AddRef( - iBox, - insideBoxes // - ); - } - } + // + XOHCL passedBar; + bool isBodyIn = false; + bool isBodyOut = false; + + // + // Check Activation ... + bool isActivated = iZone.IsActivated( + iDir, + passedBar, + isBodyIn, + true, + period // + ); + if (isActivated) + { + // + // AddRef( + // iBox, + // insideBoxes // + // ); + + // + Add( + i, + removeIDXs // + ); // iBox.Clean(); + passedBar.Clean(); + continue; } + + // + // Checking Breaked ... + bool isBreaked = iZone.IsBreaked( + iDir, + passedBar, + isBodyOut, + false, + true, + period // + ); + if (isBreaked) + { + // // + // AddRef( + // iBox, + // breakedBoxes // + // ); + + // + Add( + i, + removeIDXs // + ); + + // + iBox.Clean(); + passedBar.Clean(); + continue; + } + + // + passedBar.Clean(); } // - has = HasChild(mustRemove); + count = ArraySize(removeIDXs); + has = IsValidSize(count); if (has) { // - count = ArraySize(mustRemove); - for (int i = 0; i < count; i++) - { - // - ArrayRemove( - supplyZones, - mustRemove[i], - 1 // - ); - } + CleanupArray( + removeIDXs, + supplyZones // + ); } // - Clean(mustRemove); + Clean(removeIDXs); } // @@ -1538,251 +681,495 @@ struct X121SMCStrategyXWZWorkingZone if (has) { // - int mustRemove[]; + int removeIDXs[]; count = CountDemandZones(); for (int i = 0; i < count; i++) { // XCDemandZone *iZone = demandZones[i]; + ENUM_X_DIRECTION iDir = X_DIRECTION_BULLISH; + + // + XBoxZone iBox; + bool hasBox = ToBox( + iBox, + iZone // + ); + if (!hasBox) + { + // + iBox.Clean(); + continue; + } + + // + XOHCL passedBar; + bool isBodyIn = false; + bool isBodyOut = false; + + // + // Check Activation ... + bool isActivated = iZone.IsActivated( + iDir, + passedBar, + isBodyIn, + true, + period // + ); + if (isActivated) + { + // + // AddRef( + // iBox, + // insideBoxes // + // ); + + // + Add( + i, + removeIDXs // + ); + + // + iBox.Clean(); + passedBar.Clean(); + continue; + } + + // + // Checking Breaked ... + bool isBreaked = iZone.IsBreaked( + iDir, + passedBar, + isBodyOut, + false, + true, + period // + ); + if (isBreaked) + { + // // + // AddRef( + // iBox, + // breakedBoxes // + // ); + + // + Add( + i, + removeIDXs // + ); + + // + iBox.Clean(); + passedBar.Clean(); + continue; + } + + // + passedBar.Clean(); + } + + // + count = ArraySize(removeIDXs); + has = IsValidSize(count); + if (has) + { + // + CleanupArray( + removeIDXs, + demandZones // + ); + } + + // + Clean(removeIDXs); + } + + // + // Update Boxes ... + + // + // Waiting Boxes ... + has = HasWaitingBoxes(); + if (has) + { + // + int removeIDXs[]; + count = CountWaitingBoxes(); + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox = waitingBoxes[i]; + ENUM_X_DIRECTION iDir = iBox.dir; + bool isBullish = IsBullish(iDir); // bool isInside = // - zBar.high < iZone.Upper() && - zBar.low > iZone.Lower() && - // - cBar.high < iZone.Upper() && - cBar.low > iZone.Lower() + zBar.low < iBox.upper && + zBar.low > iBox.lower // ; if (isInside) { // - XBoxZone iBox; - has = ToBox( + AddRef( iBox, - iZone // + insideBoxes // ); - if (has) + + // + Add( + i, + removeIDXs // + ); + + // + iBox.Clean(); + break; + } + + // + bool isBreakedUpper = + // + cBar.low < iBox.upper && + cBar.low > iBox.lower && + zBar.low > iBox.upper + // + ; + + // + bool isBreakedLower = + // + cBar.high > iBox.lower && + cBar.high < iBox.upper && + zBar.high < iBox.lower + // + ; + + // + bool isBreaked = + (isBullish && + isBreakedLower) || + (!isBullish && + isBreakedUpper); + + // + if (isBreaked) + { + // + AddRef( + iBox, + breakedBoxes // + ); + + // + Add( + i, + removeIDXs // + ); + + // + iBox.Clean(); + break; + } + } + + // + count = ArraySize(removeIDXs); + has = IsValidSize(count); + if (has) + { + // + CleanupArray( + removeIDXs, + waitingBoxes // + ); + } + + // + Clean(removeIDXs); + } + + // + // Inside Boxes ... + has = HasInsideBoxes(); + if (has) + { + // + int removeIDXs[]; + count = CountInsideBoxes(); + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox = insideBoxes[i]; + ENUM_X_DIRECTION iDir = iBox.dir; + bool isBullish = IsBullish(iDir); + + // + bool isBreakedUpper = + // + cBar.low < iBox.upper && + cBar.low > iBox.lower && + zBar.low > iBox.upper + // + ; + + // + bool isBreakedLower = + // + cBar.high > iBox.lower && + cBar.high < iBox.upper && + zBar.high < iBox.lower + // + ; + + // + bool isBreaked = + (isBullish && + isBreakedLower) || + (!isBullish && + isBreakedUpper); + + // + if (isBreaked) + { + // + AddRef( + iBox, + breakedBoxes // + ); + + // + Add( + i, + removeIDXs // + ); + + // + iBox.Clean(); + break; + } + } + + // + count = ArraySize(removeIDXs); + has = IsValidSize(count); + if (has) + { + // + CleanupArray( + removeIDXs, + insideBoxes // + ); + } + + // + Clean(removeIDXs); + } + + // + // Update Waiting Boxes ... + + // + XPOIState iState = mtfState; + + // + // Detect Waiting Zones ... + has = iState.HasOrderBlocks(); + if (has) + { + // + XCOrderBlock *obs[]; + count = iState.FilterOrderBlocks( + obs, + period, + XZONE_STATE_PASSED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_IGNORED, + false // + ); + + // + has = IsValidSize(count); + if (has) + { + // + // Try to Add new OBs into Waiting Zones ... + // if it's not exists ... + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox; + bool hasBox = ToBox( + iBox, + obs[i] // + ); + if (!hasBox) { // - idx = FindIndex( - iBox, - insideBoxes // - ); - has = IsValidSize(idx); - if (!has) - { - // - Add( - i, - mustRemove // - ); - - // - AddRef( - iBox, - insideBoxes // - ); - } + iBox.Clean(); + continue; } + // + // Check Index in Waiting Boxes ... + idx = FindIndex( + iBox, + waitingBoxes // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + // Check Index in Inside Boxes ... + idx = FindIndex( + iBox, + insideBoxes // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + // Check Index in Breaked Boxes ... + idx = FindIndex( + iBox, + breakedBoxes // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + AddRef( + iBox, + waitingBoxes // + ); + } + } + + // + Clean(obs); + } + + // + // Using Fair Value Gaps ... + has = iState.HasFairValueGaps(); + if (has) + { + // + XCFVG *fvgs[]; + count = iState.FilterFairValueGaps( + fvgs, + period, + XZONE_STATE_PASSED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_IGNORED, + false // + ); + + // + has = IsValidSize(count); + if (has) + { + // + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox; + bool hasBox = ToBox( + iBox, + fvgs[i] // + ); + if (!hasBox) + { + // + iBox.Clean(); + continue; + } + + // + // Check Index in Waiting Boxes ... + idx = FindIndex( + iBox, + waitingBoxes // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + // Check Index in Inside Boxes ... + idx = FindIndex( + iBox, + insideBoxes // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + // Check Index in Breaked Boxes ... + idx = FindIndex( + iBox, + breakedBoxes // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + AddRef( + iBox, + waitingBoxes // + ); + // iBox.Clean(); } } // - has = HasChild(mustRemove); - if (has) - { - // - count = ArraySize(mustRemove); - for (int i = 0; i < count; i++) - { - // - ArrayRemove( - demandZones, - mustRemove[i], - 1 // - ); - } - } - - // - Clean(mustRemove); + Clean(fvgs); } // - // Here we Detect Breaked Zone/Box (s) ... - - // - // Detect Breaked Zones ... - has = HasInsideZones(); - if (has) - { - // - int mustRemove[]; - count = CountInsideZones(); - for (int i = 0; i < count; i++) - { - // - XOBFVG iOBFVG = insideZones[i]; - ENUM_X_DIRECTION iDir = iOBFVG.GetDirection(); - bool isBullish = IsBullish(iDir); - - // - bool isBullishBreaked = - // - zBar.high < iOBFVG.ob.Lower() && - cBar.high < iOBFVG.ob.Lower() - // - ; - - // - bool isBearishBreaked = - // - zBar.low > iOBFVG.ob.Upper() && - cBar.low > iOBFVG.ob.Upper() - // - ; - - // - bool isBreaked = - isBullish - ? isBullishBreaked - : isBearishBreaked; - - // - if (isBreaked) - { - // - idx = FindIndex( - iOBFVG, - breakedZones // - ); - has = IsValidIndex(idx); - if (!has) - { - // - Add( - i, - mustRemove // - ); - - // - AddRef( - iOBFVG, - breakedZones // - ); - } - } - } - - // - has = HasChild(mustRemove); - if (has) - { - // - count = ArraySize(mustRemove); - for (int i = 0; i < count; i++) - { - // - ArrayRemove( - insideZones, - mustRemove[i], - 1 // - ); - } - } - - // - Clean(mustRemove); - } - - // - // Detect Breaked Boxes ... - has = HasInsideBoxes(); - if (has) - { - // - int mustRemove[]; - count = CountInsideBoxes(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = insideBoxes[i]; - ENUM_X_DIRECTION iDir = iBox.dir; - bool isBullish = iBox.IsBullish(); - - // - bool isBullishBreaked = - // - zBar.high < iBox.lower && - cBar.high < iBox.lower - // - ; - - // - bool isBearishBreaked = - // - zBar.low > iBox.upper && - cBar.low > iBox.upper - // - ; - - // - bool isBreaked = - isBullish - ? isBullishBreaked - : isBearishBreaked; - - // - if (isBreaked) - { - // - idx = FindIndex( - iBox, - breakedBoxes // - ); - has = IsValidIndex(idx); - if (!has) - { - // - Add( - i, - mustRemove // - ); - - // - AddRef( - iBox, - breakedBoxes // - ); - } - } - } - - // - has = HasChild(mustRemove); - if (has) - { - // - count = ArraySize(mustRemove); - for (int i = 0; i < count; i++) - { - // - ArrayRemove( - insideBoxes, - mustRemove[i], - 1 // - ); - } - } - - // - Clean(mustRemove); - } + iState.Clean(); // // Cleanup Resource ... @@ -1792,144 +1179,6 @@ struct X121SMCStrategyXWZWorkingZone cBar.Clean(); } - // - bool HasSupplyZone() - { - return supplyZone != NULL && - supplyZone.IsValid(); - } - - // - bool HasDemandZone() - { - return demandZone != NULL && - demandZone.IsValid(); - } - - // - bool HasSupplyZones() - { - return HasChild(supplyZones); - } - - // - int CountSupplyZones() - { - return ArraySize(supplyZones); - } - - // - bool HasDemandZones() - { - return HasChild(demandZones); - } - - // - int CountDemandZones() - { - return ArraySize(demandZones); - } - - // - bool HasSupportZones() - { - return HasChild(supportZones); - } - - // - int CountSupportZones() - { - return ArraySize(supportZones); - } - - // - bool HasResistanceZones() - { - return HasChild(resistanceZones); - } - - // - int CountResistanceZones() - { - return ArraySize(resistanceZones); - } - - // - bool HasWaitingZones() - { - return HasChild(waitingZones); - } - - // - int CountWaitingZones() - { - return ArraySize(waitingZones); - } - - // - bool HasInsideZones() - { - return HasChild(insideZones); - } - - // - int CountInsideZones() - { - return ArraySize(insideZones); - } - - // - bool HasBreakedZones() - { - return HasChild(breakedZones); - } - - // - int CountBreakedZones() - { - return ArraySize(breakedZones); - } - - // - bool HasConsolidationZones() - { - return HasChild(consolidationZones); - } - - // - int CountConsolidationZones() - { - return ArraySize(consolidationZones); - } - - // - bool HasInsideBoxes() - { - return HasChild(insideBoxes); - } - - // - int CountInsideBoxes() - { - return ArraySize(insideBoxes); - } - - // - bool HasBreakedBoxes() - { - return HasChild(breakedBoxes); - } - - // - int CountBreakedBoxes() - { - return ArraySize(breakedBoxes); - } - - // - // - // - // bool IsDestroyed( int barIndex = 0, @@ -2131,10 +1380,6 @@ struct X121SMCStrategyXWZWorkingZone return result; } - // - // - // - // void UpdateTo(datetime value = NULL) { @@ -2208,41 +1453,21 @@ struct X121SMCStrategyXWZWorkingZone } // - has = HasWaitingZones(); + // + // + + // + has = HasWaitingBoxes(); if (has) { // - count = CountWaitingZones(); + count = ArraySize(waitingBoxes); for (int i = 0; i < count; i++) { - waitingZones[i].UpdateTo(value); + waitingBoxes[i].to = value; } } - // - has = HasInsideZones(); - if (has) - { - // - count = CountInsideZones(); - for (int i = 0; i < count; i++) - { - insideZones[i].UpdateTo(value); - } - } - - // - // has = HasBreakedZones(); - // if (has) - // { - // // - // count = CountBreakedZones(); - // for (int i = 0; i < count; i++) - // { - // breakedZones[i].UpdateTo(value); - // } - // } - // has = HasInsideBoxes(); if (has) @@ -2255,27 +1480,15 @@ struct X121SMCStrategyXWZWorkingZone } } - // - // has = HasBreakedBoxes(); - // if (has) - // { - // // - // count = CountBreakedBoxes(); - // for (int i = 0; i < count; i++) - // { - // insideBoxes[i].to = value; - // } - // } - // } // void Draw( XCPOIDrawer *drawer, - bool drawWaitingZones = true, - bool drawInsideZones = false, - bool drawBreakedZones = false, + bool drawWaitingBoxes = true, + bool drawInsideBoxes = false, + bool drawBreakedBoxes = false, bool drawSupplyZone = false, bool drawDemandZone = false, bool drawSupplyZones = false, @@ -2468,149 +1681,49 @@ struct X121SMCStrategyXWZWorkingZone // // - // Waiting Zones ... - if (drawWaitingZones) + // Waiting Boxes ... + if (drawWaitingBoxes) { // - has = HasWaitingZones(); + has = HasWaitingBoxes(); if (has) { // - count = CountWaitingZones(); + count = CountWaitingBoxes(); for (int i = 0; i < count; i++) { // - XCBaseObject *objects[]; - int objectsCount = drawer.DrawOBFVG( - waitingZones[i], - objects // + XBoxZone iBox = waitingBoxes[i]; + + // + XCBoxObject *iObj; + bool isCreated = drawer.DrawBox( + iBox, + iObj // ); - has = IsValidSize(objectsCount); - if (has) + + // + if (isCreated) { - // - for (int j = 0; j < objectsCount; j++) - { - mWaitingZoneObjects.Add(objects[j]); - } + mWorkingZoneObjects.Add(iObj); } + + // + iBox.Clean(); } } } // - // Inside Zones ... - if (drawInsideZones) + // Inside Boxes ... + if (drawInsideBoxes) { - // - // Zones ... - has = HasInsideZones(); - if (has) - { - // - count = CountInsideZones(); - for (int i = 0; i < count; i++) - { - // - XCBaseObject *objects[]; - int objectsCount = drawer.DrawOBFVG( - insideZones[i], - objects // - ); - - // - has = IsValidSize(objectsCount); - if (has) - { - // - for (int i = 0; i < objectsCount; i++) - { - mInsideZoneObjects.Add(objects[i]); - } - } - } - } - - // // - // // Boxes ... - // has = HasInsideBoxes(); - // if (has) - // { - // // - // count = CountInsideBoxes(); - // for (int i = 0; i < count; i++) - // { - // // - // XCBoxObject *object; - // bool isCreated = drawer.DrawBox( - // insideBoxes[i], - // object // - // ); - - // // - // if (isCreated) - // { - // mInsideZoneObjects.Add(object); - // } - // } - // } } // - // Breaked Zones ... - if (drawBreakedZones) + // Breaked Boxes ... + if (drawBreakedBoxes) { - // - has = HasBreakedZones(); - if (has) - { - // - count = CountBreakedZones(); - for (int i = 0; i < count; i++) - { - // - XCBaseObject *objects[]; - int objectsCount = drawer.DrawOBFVG( - breakedZones[i], - objects // - ); - - // - has = IsValidSize(objectsCount); - if (has) - { - // - for (int i = 0; i < objectsCount; i++) - { - mBreakedZoneObjects.Add(objects[i]); - } - } - } - } - - // // - // // Boxes ... - // has = HasBreakedBoxes(); - // if (has) - // { - // // - // count = CountBreakedBoxes(); - // for (int i = 0; i < count; i++) - // { - // // - // XCBoxObject *object; - // bool isCreated = drawer.DrawBox( - // breakedBoxes[i], - // object // - // ); - - // // - // if (isCreated) - // { - // mInsideZoneObjects.Add(object); - // } - // } - // } } // @@ -2771,6 +1884,120 @@ struct X121SMCStrategyXWZWorkingZone } } + // + // + // + + // + bool HasSupplyZone() + { + return supplyZone != NULL && + supplyZone.IsValid(); + } + + // + bool HasDemandZone() + { + return demandZone != NULL && + demandZone.IsValid(); + } + + // + bool HasSupplyZones() + { + return HasChild(supplyZones); + } + + // + int CountSupplyZones() + { + return ArraySize(supplyZones); + } + + // + bool HasDemandZones() + { + return HasChild(demandZones); + } + + // + int CountDemandZones() + { + return ArraySize(demandZones); + } + + // + bool HasSupportZones() + { + return HasChild(supportZones); + } + + // + int CountSupportZones() + { + return ArraySize(supportZones); + } + + // + bool HasResistanceZones() + { + return HasChild(resistanceZones); + } + + // + int CountResistanceZones() + { + return ArraySize(resistanceZones); + } + + // + bool HasConsolidationZones() + { + return HasChild(consolidationZones); + } + + // + int CountConsolidationZones() + { + return ArraySize(consolidationZones); + } + + // + bool HasWaitingBoxes() + { + return HasChild(waitingBoxes); + } + + // + int CountWaitingBoxes() + { + return ArraySize(waitingBoxes); + } + + // + bool HasInsideBoxes() + { + return HasChild(insideBoxes); + } + + // + int CountInsideBoxes() + { + return ArraySize(insideBoxes); + } + + // + bool HasBreakedBoxes() + { + return HasChild(breakedBoxes); + } + + // + int CountBreakedBoxes() + { + return ArraySize(breakedBoxes); + } + // }; @@ -2966,2231 +2193,4 @@ struct X121SMCStrategyXWZSignalConditions // // Extension Functions ... -/** - * Check an XOBFVG instance has Required Conditions ... - * - * @param zone: XOBFVG instance ... - * @param state: XPOIState instance ... - * @param conditions: X121Conditions instance ... - * - * @return ( bool ) - */ -bool DetectSelectedZoneConditions( - bool &isReversal, - XOBFVG &zone, - XPOIState &state, - X121Conditions &conditions // -) -{ - // - bool result = false; - - // - isReversal = false; - - // - result = - zone.IsValid() && - state.IsValid() && - state.HasChild(); - if (!result) - { - return result; - } - - // - bool isBullish = zone.IsBullish(); - bool isBearish = zone.IsBearish(); - - // - bool isBullishTrend = conditions.isTrendBullish || - conditions.isTrendSwitchedToBullish; - bool isBearishTrend = conditions.isTrendBearish || - conditions.isTrendSwitchedToBearish; - - // - double bullishScore = 0; - double bearishScore = 0; - double scoreMultiplier = 1.5; - conditions.GenerateScore( - bullishScore, - bearishScore // - ); - - // - bool isBullishScorePassed = bullishScore > 0 && - bearishScore >= 0 && - bullishScore > bearishScore * scoreMultiplier; - - // - bool isBearishScorePassed = bearishScore > 0 && - bullishScore >= 0 && - bearishScore > bullishScore * scoreMultiplier; - - // - // VWap ... - - // - double vwapFast = conditions.vwapFastBuffer[0]; - double vwapMid = conditions.vwapMidBuffer[0]; - double vwapSlow = conditions.vwapSlowBuffer[0]; - - // - bool isVWapInside = - // - vwapFast > zone.ob.Lower() && - vwapFast < zone.ob.Upper() - // - && - vwapMid > zone.ob.Lower() && - vwapMid < zone.ob.Upper() - // - ; - - // - bool isVWapBullish = - // - (conditions.isVWapBullishState && - conditions.isVWapSwitchedToBullishOrdered) - // - || - // - (conditions.isVWapBullishOrdered && - conditions.isVWapSwitchedToBullishState) - // - ; - - // - bool isVWapBearish = - // - (conditions.isVWapBearishState && - conditions.isVWapSwitchedToBearishOrdered) - // - || - // - (conditions.isVWapBearishOrdered && - conditions.isVWapSwitchedToBearishState) - // - ; - - // - // X3Ma ... - - // - double x3maFast = conditions.x3maFastBuffer[0]; - double x3maMid = conditions.x3maMidBuffer[0]; - double x3maSlow = conditions.x3maSlowBuffer[0]; - - // - bool isX3MaInside = - // - x3maFast > zone.ob.Lower() && - x3maFast < zone.ob.Upper() - // - && - x3maMid > zone.ob.Lower() && - x3maMid < zone.ob.Upper() - // - ; - - // - bool isX3MaBullish = - // - (conditions.isX3MaBullishState && - conditions.isX3MaSwitchedToBullishOrdered) - // - || - // - (conditions.isX3MaBullishOrdered && - conditions.isX3MaSwitchedToBullishState) - // - ; - - // - bool isX3MaBearish = - // - (conditions.isX3MaBearishState && - conditions.isX3MaSwitchedToBearishOrdered) - // - || - // - (conditions.isX3MaBearishOrdered && - conditions.isX3MaSwitchedToBearishState) - // - ; - - // - // - // - - // - bool isInside = - // - isVWapInside || - isX3MaInside - // - ; - - // - bool isVWap3MaBullish = - isVWapBullish || - isX3MaBullish; - - // - bool isVWap3MaBearish = - isVWapBearish || - isX3MaBearish; - - // - // - // - - // - bool isDirectionalBullishPassed = - // - isInside && - isBullish && - isBullishTrend && - isVWap3MaBullish && - isBullishScorePassed - // - ; - - // - bool isDirectionalBearishPassed = - // - isInside && - isBearish && - isBearishTrend && - isVWap3MaBearish && - isBearishScorePassed - // - ; - - // - bool isDirectionalPassed = - isDirectionalBullishPassed || - isDirectionalBearishPassed; - - // - bool isReversalBullishPassed = - // - isInside && - isBullish && - isBearishTrend && - isVWap3MaBearish && - isBearishScorePassed - // - ; - - // - bool isReversalBearishPassed = - // - isInside && - isBearish && - isBullishTrend && - isVWap3MaBullish && - isBullishScorePassed - // - ; - - // - bool isReversalPassed = isReversalBullishPassed || - isReversalBearishPassed; - - // - result = isReversalPassed || - isDirectionalPassed; - - // - if (result) - { - isReversal = isReversalPassed; - } - - // - return result; -} - -/** - * Check an XOBFVG instance has Required Conditions ... - * - * @param zone: XBoxZone instance ... - * @param state: XPOIState instance ... - * @param conditions: X121Conditions instance ... - * - * @return ( bool ) - */ -bool DetectSelectedBoxConditions( - bool &isReversal, - XBoxZone &zone, - XPOIState &state, - X121Conditions &conditions // -) -{ - // - bool result = false; - - // - isReversal = false; - - // - result = - zone.IsValid() && - state.IsValid() && - state.HasChild(); - if (!result) - { - return result; - } - - // - bool isBullish = zone.IsBullish(); - bool isBearish = zone.IsBearish(); - - // - bool isBullishTrend = conditions.isTrendBullish || - conditions.isTrendSwitchedToBullish; - bool isBearishTrend = conditions.isTrendBearish || - conditions.isTrendSwitchedToBearish; - - // - double bullishScore = 0; - double bearishScore = 0; - double scoreMultiplier = 1.5; - conditions.GenerateScore( - bullishScore, - bearishScore // - ); - - // - bool isBullishScorePassed = bullishScore > 0 && - bearishScore >= 0 && - bullishScore > bearishScore * scoreMultiplier; - - // - bool isBearishScorePassed = bearishScore > 0 && - bullishScore >= 0 && - bearishScore > bullishScore * scoreMultiplier; - - // - // VWap ... - - // - double vwapFast = conditions.vwapFastBuffer[0]; - double vwapMid = conditions.vwapMidBuffer[0]; - double vwapSlow = conditions.vwapSlowBuffer[0]; - - // - bool isVWapInside = - // - vwapFast > zone.lower && - vwapFast < zone.upper - // - && - vwapMid > zone.lower && - vwapMid < zone.upper - // - ; - - // - bool isVWapBullish = - // - (conditions.isVWapBullishState && - conditions.isVWapSwitchedToBullishOrdered) - // - || - // - (conditions.isVWapBullishOrdered && - conditions.isVWapSwitchedToBullishState) - // - ; - - // - bool isVWapBearish = - // - (conditions.isVWapBearishState && - conditions.isVWapSwitchedToBearishOrdered) - // - || - // - (conditions.isVWapBearishOrdered && - conditions.isVWapSwitchedToBearishState) - // - ; - - // - // X3Ma ... - - // - double x3maFast = conditions.x3maFastBuffer[0]; - double x3maMid = conditions.x3maMidBuffer[0]; - double x3maSlow = conditions.x3maSlowBuffer[0]; - - // - bool isX3MaInside = - // - x3maFast > zone.lower && - x3maFast < zone.upper - // - && - x3maMid > zone.lower && - x3maMid < zone.upper - // - ; - - // - bool isX3MaBullish = - // - (conditions.isX3MaBullishState && - conditions.isX3MaSwitchedToBullishOrdered) - // - || - // - (conditions.isX3MaBullishOrdered && - conditions.isX3MaSwitchedToBullishState) - // - ; - - // - bool isX3MaBearish = - // - (conditions.isX3MaBearishState && - conditions.isX3MaSwitchedToBearishOrdered) - // - || - // - (conditions.isX3MaBearishOrdered && - conditions.isX3MaSwitchedToBearishState) - // - ; - - // - // - // - - // - bool isInside = - // - isVWapInside || - isX3MaInside - // - ; - - // - bool isVWap3MaBullish = - isVWapBullish || - isX3MaBullish; - - // - bool isVWap3MaBearish = - isVWapBearish || - isX3MaBearish; - - // - // - // - - // - bool isDirectionalBullishPassed = - // - isInside && - isBullish && - isBullishTrend && - isVWap3MaBullish && - isBullishScorePassed - // - ; - - // - bool isDirectionalBearishPassed = - // - isInside && - isBearish && - isBearishTrend && - isVWap3MaBearish && - isBearishScorePassed - // - ; - - // - bool isDirectionalPassed = - isDirectionalBullishPassed || - isDirectionalBearishPassed; - - // - bool isReversalBullishPassed = - // - isInside && - isBullish && - isBearishTrend && - isVWap3MaBearish && - isBearishScorePassed - // - ; - - // - bool isReversalBearishPassed = - // - isInside && - isBearish && - isBullishTrend && - isVWap3MaBullish && - isBullishScorePassed - // - ; - - // - bool isReversalPassed = isReversalBullishPassed || - isReversalBearishPassed; - - // - result = isReversalPassed || - isDirectionalPassed; - - // - if (result) - { - isReversal = isReversalPassed; - } - - // - return result; -} - -/** - * Detect Targets Based on Selected Zone for Specified type of Directions ... - * - * @param targets: double Collection ... - * @param selectedZone: XOBFVG instance, selected Zone ... - * @param forDir: ENUM_X_DIRECTION specified Position Direction ... - * @param workingone: X121SMCStrategyXWZWorkingZone instance, Specified Working Zone ... - * @param barIndex: int Specified Bar Index ... - * - * @return ( bool ) - */ -bool DetectSelectedZonesTargets( - double &targets[], - XOBFVG &selectedZone, - ENUM_X_DIRECTION forDir, - ENUM_X121SMC_XWZ_PRIORITY forPriority, - X121SMCStrategyXWZWorkingZone &workingZone, - int barIndex = 0 // -) -{ - // - bool result = false; - - // - Clean(targets); - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (barIndex == 0) - { - barIndex++; - } - - // - result = - // - selectedZone.IsValid() && - HasDirection(forDir) && - workingZone.IsValid() && - forPriority != X121SMC_XWZ_PRIORITY_NONE - // - ; - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - XOHCL cBar; - result = cBar.Init( - workingZone.symbol, - workingZone.period, - barIndex // - ); - if (!result) - { - // - cBar.Clean(); - return result; - } - - // - int idx = -1; - bool has = false; - XOBFVG tmpZones[]; - - // - // Based On Waiting Zones ... - has = workingZone.HasWaitingZones(); - if (has) - { - // - Copy( - workingZone.waitingZones, - tmpZones // - ); - - // - while (HasChild(tmpZones)) - { - // - XOBFVG iOBFVG; - - // - idx = GetYoungest(tmpZones); - if (!IsValidIndex(idx)) - { - // - iOBFVG.Clean(); - break; - } - - // - iOBFVG = tmpZones[idx]; - ArrayRemove( - tmpZones, - idx, - 1 // - ); - - // - double iTarget = - isBullish - ? iOBFVG.ob.Lower() - : iOBFVG.ob.Upper(); - - // - has = - isBullish - ? cBar.high < iTarget - : cBar.low > iTarget; - - // - if (has) - { - // - Add( - iTarget, - targets // - ); - } - - // - iOBFVG.Clean(); - } - - // - Clean(tmpZones); - } - - // - // Based On Breaked Zones ... - has = workingZone.HasBreakedZones(); - if (has) - { - Copy( - workingZone.breakedZones, - tmpZones // - ); - - // - while (HasChild(tmpZones)) - { - // - XOBFVG iOBFVG; - - // - idx = GetYoungest(tmpZones); - if (!IsValidIndex(idx)) - { - // - iOBFVG.Clean(); - break; - } - - // - iOBFVG = tmpZones[idx]; - ArrayRemove( - tmpZones, - idx, - 1 // - ); - - // - double iTarget = - isBullish - ? iOBFVG.ob.Lower() - : iOBFVG.ob.Upper(); - - // - has = - isBullish - ? cBar.high < iTarget - : cBar.low > iTarget; - - // - if (has) - { - // - Add( - iTarget, - targets // - ); - } - - // - iOBFVG.Clean(); - } - - // - Clean(tmpZones); - } - - // - // Based On Priority ... - has = forPriority != X121SMC_XWZ_PRIORITY_NONE; - if (has) - { - // - switch (forPriority) - { - // - case X121SMC_XWZ_PRIORITY_WEAK: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_LOW: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_REGULAR: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_HIGH: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter3, - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter1, - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_STRONG_HIGH: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Strong High ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Strong High ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - } - break; - } - } - - // - result = HasChild(targets); - - // - // Cleanup ... - cBar.Clean(); - Clean(tmpZones); - - // - return result; -} - -/** - * Detect Targets Based on Selected Zone for Specified type of Directions ... - * - * @param targets: double Collection ... - * @param selectedZone: XBoxZone instance, selected Zone ... - * @param forDir: ENUM_X_DIRECTION specified Position Direction ... - * @param workingone: X121SMCStrategyXWZWorkingZone instance, Specified Working Zone ... - * @param barIndex: int Specified Bar Index ... - * - * @return ( bool ) - */ -bool DetectSelectedZonesTargets( - double &targets[], - XBoxZone &selectedZone, - ENUM_X_DIRECTION forDir, - ENUM_X121SMC_XWZ_PRIORITY forPriority, - X121SMCStrategyXWZWorkingZone &workingZone, - int barIndex = 0 // -) -{ - // - bool result = false; - - // - Clean(targets); - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (barIndex == 0) - { - barIndex++; - } - - // - result = - // - selectedZone.IsValid() && - HasDirection(forDir) && - workingZone.IsValid() && - forPriority != X121SMC_XWZ_PRIORITY_NONE - // - ; - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - XOHCL cBar; - result = cBar.Init( - workingZone.symbol, - workingZone.period, - barIndex // - ); - if (!result) - { - // - cBar.Clean(); - return result; - } - - // - int idx = -1; - bool has = false; - XOBFVG tmpZones[]; - - // - // Based On Waiting Zones ... - has = workingZone.HasWaitingZones(); - if (has) - { - // - Copy( - workingZone.waitingZones, - tmpZones // - ); - - // - while (HasChild(tmpZones)) - { - // - XOBFVG iOBFVG; - - // - idx = GetYoungest(tmpZones); - if (!IsValidIndex(idx)) - { - // - iOBFVG.Clean(); - break; - } - - // - iOBFVG = tmpZones[idx]; - ArrayRemove( - tmpZones, - idx, - 1 // - ); - - // - double iTarget = - isBullish - ? iOBFVG.ob.Lower() - : iOBFVG.ob.Upper(); - - // - has = - isBullish - ? cBar.high < iTarget - : cBar.low > iTarget; - - // - if (has) - { - // - Add( - iTarget, - targets // - ); - } - - // - iOBFVG.Clean(); - } - - // - Clean(tmpZones); - } - - // - // Based On Breaked Zones ... - has = workingZone.HasBreakedZones(); - if (has) - { - Copy( - workingZone.breakedZones, - tmpZones // - ); - - // - while (HasChild(tmpZones)) - { - // - XOBFVG iOBFVG; - - // - idx = GetYoungest(tmpZones); - if (!IsValidIndex(idx)) - { - // - iOBFVG.Clean(); - break; - } - - // - iOBFVG = tmpZones[idx]; - ArrayRemove( - tmpZones, - idx, - 1 // - ); - - // - double iTarget = - isBullish - ? iOBFVG.ob.Lower() - : iOBFVG.ob.Upper(); - - // - has = - isBullish - ? cBar.high < iTarget - : cBar.low > iTarget; - - // - if (has) - { - // - Add( - iTarget, - targets // - ); - } - - // - iOBFVG.Clean(); - } - - // - Clean(tmpZones); - } - - // - // Based On Priority ... - has = forPriority != X121SMC_XWZ_PRIORITY_NONE; - if (has) - { - // - switch (forPriority) - { - // - case X121SMC_XWZ_PRIORITY_WEAK: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_LOW: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_REGULAR: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_HIGH: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter3, - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter1, - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_STRONG_HIGH: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Strong High ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Strong High ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - } - break; - } - } - - // - result = HasChild(targets); - - // - // Cleanup ... - cBar.Clean(); - Clean(tmpZones); - - // - return result; -} - -/** - * Detect SL Candidates Based on Selected Zone for Specified type of Directions ... - * - * @param sls: double Collection ... - * @param selectedZone: XOBFVG instance, selected Zone ... - * @param forDir: ENUM_X_DIRECTION specified Position Direction ... - * @param workingZone: X121SMCStrategyXWZWorkingZone instance, Specified Working Zone ... - * @param barIndex: int Specified Bar Index ... - * @param maxAllowedSLDistanceInPoint: doube max Allowe SL distance ... - * - * @return ( bool ) - */ -bool DetectSelectedZoneSLCandidates( - double &sls[], - XOBFVG &selectedZone, - ENUM_X_DIRECTION forDir, - X121SMCStrategyXWZWorkingZone &workingZone, - X121Conditions &conditions, - int barIndex = 0, - double maxAllowedSLDistanceInPoint = 300 // -) -{ - // - bool result = false; - - // - Clean(sls); - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (barIndex == 0) - { - barIndex++; - } - - // - result = - // - selectedZone.IsValid() && - HasDirection(forDir) && - workingZone.IsValid() - // - ; - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - double pivot = - isBullish - ? selectedZone.ob.Lower() - : selectedZone.ob.Upper(); - double points = GetPoints(workingZone.symbol); - - // - XOHCL cBar; - result = cBar.Init( - workingZone.symbol, - workingZone.period, - barIndex // - ); - if (!result) - { - // - cBar.Clean(); - return result; - } - - // - int idx = -1; - bool has = false; - - // - double pvSL = isBullish - ? conditions.valesBuffer[0] - : conditions.peaksBuffer[1]; - - // - Add( - pvSL, - sls // - ); - - // - // Based On Passed Bars ... - // XOHCL passedBar; - // bool isPassed = false; - // bool isBodyState = false; - // ENUM_X_DIRECTION passedDir = selectedZone.GetDirection(); - - // // - // // Started Bar ... - // isPassed = selectedZone.ob.IsStarted( - // passedDir, - // passedBar, - // isBodyState // - // ); - // if (isPassed) - // { - // // - // double iSL = - // isBullish - // ? passedBar.low - // : passedBar.high; - // double iSLDiff = MathAbs(iSL - pivot); - // has = - // iSLDiff > 0 && - // iSLDiff <= maxAllowedSLDistanceInPoint * points; - // if (has) - // { - // // - // Add( - // iSL, - // sls // - // ); - // } - // } - - // // - // // Activation Bar ... - // passedBar.Clean(); - // isPassed = selectedZone.ob.IsActivated( - // passedDir, - // passedBar, - // isBodyState // - // ); - // if (isPassed) - // { - // // - // double iSL = - // isBullish - // ? passedBar.low - // : passedBar.high; - // double iSLDiff = MathAbs(iSL - pivot); - // has = - // iSLDiff > 0 && - // iSLDiff <= maxAllowedSLDistanceInPoint * points; - // if (has) - // { - // // - // Add( - // iSL, - // sls // - // ); - // } - // } - - // // - // // Worked Bar ... - // passedBar.Clean(); - // isPassed = selectedZone.ob.IsActivated( - // passedDir, - // passedBar, - // isBodyState // - // ); - // if (isPassed) - // { - // // - // double iSL = - // isBullish - // ? passedBar.low - // : passedBar.high; - // double iSLDiff = MathAbs(iSL - pivot); - // has = - // iSLDiff > 0 && - // iSLDiff <= maxAllowedSLDistanceInPoint * points; - // if (has) - // { - // // - // Add( - // iSL, - // sls // - // ); - // } - // } - - // // - // // Breaked Bar ... - // passedBar.Clean(); - // isPassed = selectedZone.ob.IsActivated( - // passedDir, - // passedBar, - // isBodyState // - // ); - // if (isPassed) - // { - // // - // double iSL = - // isBullish - // ? passedBar.low - // : passedBar.high; - // double iSLDiff = MathAbs(iSL - pivot); - // has = - // iSLDiff > 0 && - // iSLDiff <= maxAllowedSLDistanceInPoint * points; - // if (has) - // { - // // - // Add( - // iSL, - // sls // - // ); - // } - // } - - // - // Based On Consolidation Zones ... - has = workingZone.HasConsolidationZones(); - if (has) - { - // - XConsolidationZone tmpZones[]; - Copy( - workingZone.consolidationZones, - tmpZones // - ); - XConsolidationZone selectedConsolidationZone; - - // - while (HasChild(tmpZones)) - { - // - idx = GetYoungest(tmpZones); - if (!IsValidIndex(idx)) - { - break; - } - - // - XConsolidationZone iZone = tmpZones[idx]; - - // - ArrayRemove( - tmpZones, - idx, - 1 // - ); - - // - has = - !selectedConsolidationZone.IsValid() - ? isBullish - ? cBar.low < iZone.upper - : cBar.high < iZone.lower - : isBullish - ? selectedConsolidationZone.lower < iZone.lower - : selectedConsolidationZone.upper > iZone.upper; - if (has) - { - // - selectedConsolidationZone = iZone; - iZone.Clean(); - break; - } - - // - iZone.Clean(); - } - - // - Clean(tmpZones); - has = selectedConsolidationZone.IsValid(); - if (has) - { - // - double iSL = - isBullish - ? selectedConsolidationZone.lower - : selectedConsolidationZone.upper; - double iSLDiff = MathAbs(iSL - pivot); - has = - iSLDiff > 0 && - iSLDiff <= maxAllowedSLDistanceInPoint * points; - if (has) - { - // - Add( - iSL, - sls // - ); - } - } - } - - // - // Based On Supply and Demand Zones ... - - // - // Demand Zones ... - has = workingZone.HasDemandZones(); - if (has) - { - // - XCDemandZone *tmpZones[]; - Copy( - workingZone.demandZones, - tmpZones // - ); - XCDemandZone *selectedDemand = NULL; - - // - while (HasChild(tmpZones)) - { - // - idx = GetLowest(tmpZones); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - XCDemandZone *iZone = tmpZones[idx]; - ArrayRemove( - tmpZones, - idx, - 1 // - ); - - // - // Validate Zone ... - has = - isBullish - ? IsBelowDiff( - iZone, - selectedZone.ob, - true // Ignore Inside ... - ) - : IsAboveDiff( - iZone, - selectedZone.ob, - true // Ignore Inside ... - ); - if (!has) - { - continue; - } - - // - has = - selectedDemand == NULL - ? true - : isBullish - ? selectedDemand.Lower() < iZone.Lower() - : selectedDemand.Upper() > iZone.Upper(); - if (!has) - { - continue; - } - - // - selectedDemand = iZone; - } - - // - has = selectedDemand != NULL; - if (has) - { - // - double iSL = - isBullish - ? selectedDemand.Lower() - : selectedDemand.Upper(); - double iSLDiff = MathAbs(iSL - pivot); - has = - iSLDiff > 0 && - iSLDiff <= maxAllowedSLDistanceInPoint * points; - if (has) - { - // - Add( - iSL, - sls // - ); - } - } - - // - Clean(tmpZones); - ZeroMemory(selectedDemand); - } - - // - // Support Zones ... - // has = workingZone.HasSupportZones(); - // if (has) - // { - // // - // XCSupportZone *tmpZones[]; - // Copy( - // workingZone.supportZones, - // tmpZones // - // ); - // XCSupportZone *selectedSupport = NULL; - - // // - // while (HasChild(tmpZones)) - // { - // // - // idx = GetLowest(tmpZones); - // has = IsValidIndex(idx); - // if (!has) - // { - // break; - // } - - // // - // XCSupportZone *iZone = tmpZones[idx]; - // ArrayRemove( - // tmpZones, - // idx, - // 1 // - // ); - - // // - // // Validate Zone ... - // has = - // isBullish - // ? IsBelowDiff( - // iZone, - // selectedZone.ob, - // true // Ignore Inside ... - // ) - // : IsAboveDiff( - // iZone, - // selectedZone.ob, - // true // Ignore Inside ... - // ); - // if (!has) - // { - // continue; - // } - - // // - // has = - // selectedSupport == NULL - // ? true - // : isBullish - // ? selectedSupport.Lower() < iZone.Lower() - // : selectedSupport.Upper() > iZone.Upper(); - // if (!has) - // { - // continue; - // } - - // // - // selectedSupport = iZone; - - // // - // } - - // // - // has = selectedSupport != NULL; - // if (has) - // { - // // - // double iSL = isBullish - // ? selectedSupport.Lower() - // : selectedSupport.Upper(); - // double iSLDiff = MathAbs(iSL - pivot); - // has = - // iSLDiff > 0 && - // iSLDiff <= maxAllowedSLDistanceInPoint * points; - // if (has) - // { - // // - // Add( - // iSL, - // sls // - // ); - // } - // } - - // // - // Clean(tmpZones); - // ZeroMemory(selectedSupport); - // } - - // - // Supply Zones ... - has = workingZone.HasSupplyZones(); - if (has) - { - // - XCSupplyZone *tmpZones[]; - Copy( - workingZone.supplyZones, - tmpZones // - ); - XCSupplyZone *selectedSupply = NULL; - - // - while (HasChild(tmpZones)) - { - // - idx = GetHighest(tmpZones); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - XCSupplyZone *iZone = tmpZones[idx]; - ArrayRemove( - tmpZones, - idx, - 1 // - ); - - // - // Validate Zone ... - has = - !isBullish - ? IsAboveDiff( - iZone, - selectedZone.ob, - true // Ignore Inside ... - ) - : IsBelowDiff( - iZone, - selectedZone.ob, - true // Ignore Inside ... - ); - if (!has) - { - continue; - } - - // - has = - selectedSupply == NULL - ? true - : !isBullish - ? selectedSupply.Upper() > iZone.Upper() - : selectedSupply.Lower() < iZone.Lower(); - if (!has) - { - continue; - } - - // - selectedSupply = iZone; - - // - } - - // - has = selectedSupply != NULL; - if (has) - { - // - double iSL = - !isBullish - ? selectedSupply.Upper() - : selectedSupply.Lower(); - double iSLDiff = MathAbs(iSL - pivot); - has = - iSLDiff > 0 && - iSLDiff <= maxAllowedSLDistanceInPoint * points; - if (has) - { - // - Add( - iSL, - sls // - ); - } - } - - // - Clean(tmpZones); - ZeroMemory(selectedSupply); - } - - // - // Resistance Zones ... - // has = workingZone.HasDemandZones(); - // if (has) - // { - // // - // XCResistanceZone *tmpZones[]; - // Copy( - // workingZone.resistanceZones, - // tmpZones // - // ); - // XCResistanceZone *selectedResistance = NULL; - - // // - // while (HasChild(tmpZones)) - // { - // // - // idx = GetHighest(tmpZones); - // has = IsValidIndex(idx); - // if (!has) - // { - // break; - // } - - // // - // XCResistanceZone *iZone = tmpZones[idx]; - // ArrayRemove( - // tmpZones, - // idx, - // 1 // - // ); - - // // - // // Validate Zone ... - // has = - // !isBullish - // ? IsAboveDiff( - // iZone, - // selectedZone.ob, - // true // Ignore Inside ... - // ) - // : IsBelowDiff( - // iZone, - // selectedZone.ob, - // true // Ignore Inside ... - // ); - // if (!has) - // { - // continue; - // } - - // // - // has = - // selectedResistance == NULL - // ? true - // : !isBullish - // ? selectedResistance.Upper() < iZone.Upper() - // : selectedResistance.Lower() > iZone.Lower(); - // if (!has) - // { - // continue; - // } - - // // - // selectedResistance = iZone; - - // // - // } - - // // - // has = selectedResistance != NULL; - // if (has) - // { - // // - // double iSL = - // !isBullish - // ? selectedResistance.Upper() - // : selectedResistance.Lower(); - // double iSLDiff = MathAbs(iSL - pivot); - // has = - // iSLDiff > 0 && - // iSLDiff <= maxAllowedSLDistanceInPoint * points; - // if (has) - // { - // // - // Add( - // iSL, - // sls // - // ); - // } - // } - - // // - // Clean(tmpZones); - // ZeroMemory(selectedResistance); - // } - - // - // Cleanp Resources ... - - // - cBar.Clean(); - // passedBar.Clean(); - result = HasChild(sls); - - // - return result; -} - -// -// -// - -bool DetectX121Conditions( - double &pivot, - double &point, - double &sls[], - double &targets[], - ENUM_X_DIRECTION &dir, - XPOIState &stfState, - XPOIState &ttfState, - X121Conditions &conditions, - XCPOIDrawer *drawer = NULL // -) -{ - // - bool result = false; - - // - bool canDraw = drawer != NULL; - - // - pivot = 0; - point = 0; - Clean(sls); - Clean(targets); - dir = X_DIRECTION_NONE; - - // - result = - stfState.IsValid() && - ttfState.IsValid() && - stfState.HasChild() && - ttfState.HasChild(); - if (!result) - { - return result; - } - - // - int idx = -1; - int count = 0; - bool has = false; - - // - // Detect Inside STF Order Blocks Zones ... - - // - XOBFVG tmpWaitingZones[]; - count = ExtractOBFVGs( - tmpWaitingZones, - stfState, - ttfState // - ); - has = IsValidSize(count); - if (has) - { - // - if (canDraw) - { - // - for (int i = 0; i < count; i++) - { - // - XOBFVG iOBFVG = tmpWaitingZones[i]; - - // - iOBFVG.UpdateTo(); - - // - XCBaseObject *iOBFVGObjects[]; - int iOBFVGObjectsCount = drawer.DrawOBFVG( - iOBFVG, - iOBFVGObjects // - ); - } - } - } - - // - - // - return result; -} - // \ No newline at end of file diff --git a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 index c028f6f1..749cfda9 100644 --- a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 @@ -767,7 +767,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // // XPV ... - x121Inputs.xpvInputs.showSar = showAll || false; + x121Inputs.xpvInputs.showSar = showAll || true; x121Inputs.xpvInputs.showPeaks = showAll || true; x121Inputs.xpvInputs.showVales = showAll || true;