diff --git a/Classes/x-saherelm.x-poi.drawer.class.mq5 b/Classes/x-saherelm.x-poi.drawer.class.mq5 index a3eb244d..4c3de25f 100644 --- a/Classes/x-saherelm.x-poi.drawer.class.mq5 +++ b/Classes/x-saherelm.x-poi.drawer.class.mq5 @@ -3260,6 +3260,61 @@ class XCPOIDrawer : public XCBase return result; } + /** + * Create Specific Box on Chart ... + * + * @param box: XBoxZone instance Reference ... + * @param clr: Color ... + * @param width: Integer ... + * @param fill: Boolean ... + * @param style: ENUM_LINE_STYLE member ... + * + * @return ( bool ) + */ + bool DrawBox( + XBoxZone &box, + XCBoxObject *&object // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = box.IsValid(); + if (!result) + { + return result; + } + + // + int width = 1; + bool fill = false; + color clr = + box.IsBullish() + ? BullishFVGColor() + : BearishFVGColor(); + ENUM_LINE_STYLE style = STYLE_DASHDOTDOT; + + // + result = CreateBox( + object, + box.upper, + box.lower, + box.from, + box.to, + clr, + width, + fill, + style // + ); + + // + return result; + } + /** * Create Specific Box on Chart ... * diff --git a/Libraries/x-saherelm.x-poi.extensions.lib.mq5 b/Libraries/x-saherelm.x-poi.extensions.lib.mq5 index 25405c21..b56d9704 100644 --- a/Libraries/x-saherelm.x-poi.extensions.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.extensions.lib.mq5 @@ -1547,8 +1547,8 @@ bool ToBox( box.symbol = item.symbol; box.period = item.period; box.type = IsBullish(item.dir) - ? ToString(X_BULLISH_CONSOLIDATION_ZONE) - : ToString(X_BEARISH_CONSOLIDATION_ZONE); + ? ToString(X_BULLISH_CONSOLIDATION_ZONE) + : ToString(X_BEARISH_CONSOLIDATION_ZONE); // result = box.IsValid(); @@ -2271,6 +2271,185 @@ int ExtractInsideZones( return result; } +/** + * Add Specific Item into a Collection Reference only if it's not Exists ... + * + * @return ( bool ) + */ +template +bool AddIfNotExists( + T *item, + T *&items[] // +) +{ + // + bool result = false; + + // + result = item != NULL; + if (!result) + { + return result; + } + + // + int before = ArraySize(items); + + // + int idx = FindIndex( + item, + items // + ); + bool has = IsValidIndex(idx); + result = !has; + if (!result) + { + return result; + } + + // + Add( + item, + items // + ); + + // + int after = ArraySize(items); + + // + result = after > before; + + // + return result; +} +bool AddIfNotExists( + XConsolidationZone &item, + XConsolidationZone &items[] // +) +{ + // + bool result = false; + + // + result = item.IsValid(); + if (!result) + { + return result; + } + + // + int before = ArraySize(items); + + // + int idx = FindIndex( + item, + items // + ); + bool has = IsValidIndex(idx); + result = !has; + if (!result) + { + return result; + } + + // + AddRef( + item, + items // + ); + + // + int after = ArraySize(items); + + // + result = after > before; + + // + return result; +} + +/** + * Add items Collection reference Members into source Collection only if it's not Exists ...alignas + * @return ( int ) + */ +template +int AddIfNotExists( + T *&items[], + T *&sources[] // +) +{ + // + int result = 0; + + // + bool has = HasChild(items); + if (!has) + { + return result; + } + + // + int before = ArraySize(sources); + + // + int count = ArraySize(items); + for (int i = 0; i < count; i++) + { + // + has = AddIfNotExists( + items[i], + sources // + ); + } + + // + int after = ArraySize(sources); + + // + result = after > before; + + // + return result; +} +int AddIfNotExists( + XConsolidationZone &items[], + XConsolidationZone &sources[] // +) +{ + // + int result = 0; + + // + bool has = HasChild(items); + if (!has) + { + return result; + } + + // + int before = ArraySize(sources); + + // + int count = ArraySize(items); + for (int i = 0; i < count; i++) + { + // + has = AddIfNotExists( + items[i], + sources // + ); + } + + // + int after = ArraySize(sources); + + // + result = after > before; + + // + return result; +} + // template int FilterZones( diff --git a/Libraries/x-saherelm.x-poi.lib.mq5 b/Libraries/x-saherelm.x-poi.lib.mq5 index 449e7ee2..501a6830 100644 --- a/Libraries/x-saherelm.x-poi.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.lib.mq5 @@ -5266,6 +5266,31 @@ struct XBoxZone return result; } + bool IsBullish() + { + return IsValid() && + IsBullish(dir); + } + + bool IsBearish() + { + return IsValid() && + IsBearish(dir); + } + + bool IsSameAs(XBoxZone &item) + { + // + return IsValid() && + dir == item.dir && + from == item.from && + type == item.type && + lower == item.lower && + upper == item.upper && + symbol == item.symbol && + period == item.period; + } + /** * Check Box is Same as another ... * diff --git a/Libraries/x-saherelm.x-poi.state.lib.mq5 b/Libraries/x-saherelm.x-poi.state.lib.mq5 index f8a1da40..1c369288 100644 --- a/Libraries/x-saherelm.x-poi.state.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.state.lib.mq5 @@ -4221,4 +4221,89 @@ int GetLowest( return result; } +bool AddIfNotExists( + XOBFVG &item, + XOBFVG &items[] // +) +{ + // + bool result = false; + + // + result = item.IsValid(); + if (!result) + { + return result; + } + + // + int before = ArraySize(items); + + // + int idx = FindIndex( + item, + items // + ); + bool has = IsValidIndex(idx); + result = !has; + if (!result) + { + return result; + } + + // + AddRef( + item, + items // + ); + + // + int after = ArraySize(items); + + // + result = after > before; + + // + return result; +} + +int AddIfNotExists( + XOBFVG &items[], + XOBFVG &sources[] // +) +{ + // + int result = 0; + + // + bool has = HasChild(items); + if (!has) + { + return result; + } + + // + int before = ArraySize(sources); + + // + int count = ArraySize(items); + for (int i = 0; i < count; i++) + { + // + has = AddIfNotExists( + items[i], + sources // + ); + } + + // + int after = ArraySize(sources); + + // + result = after > before; + + // + return result; +} + // diff --git a/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 b/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 index 20c5ba49..10f59192 100644 --- a/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 @@ -137,7 +137,7 @@ class XCX121SMCXWZSignalDetector : public XCBase } // - bool drawBar = true; + bool drawBar = false; if (drawBar) { // @@ -467,6 +467,22 @@ class XCX121SMCXWZSignalDetector : public XCBase } } + // + bool hasInsideBoxes = hasWorkingZone && + workingZone.HasInsideBoxes(); + if (hasInsideBoxes) + { + Print("Inside Boxes ..."); + } + + // + bool hasBreakedBoxes = hasWorkingZone && + workingZone.HasBreakedBoxes(); + if (hasBreakedBoxes) + { + Print("Breaked Boxes ..."); + } + // // Checking Other Senario for Signals ... // if (!hasWaitingZones && @@ -650,14 +666,38 @@ class XCX121SMCXWZSignalDetector : public XCBase drawer, true, // Draw Waiting Zones .. true, // Draw Inside Zones .. - true, // Draw Breaked Zones .. - true, // Draw Supply Zone .. - true, // Draw Demand Zone .. - true, // Draw Supply Zones .. - true, // Draw Demand Zones .. - true, // Draw Support Zones .. - true // Draw Resistance Zones .. + false, // Draw Breaked Zones .. + false, // Draw Supply Zone .. + false, // 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 ... + // ); } // diff --git a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 index 4193c9f4..003dc1a8 100644 --- a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 @@ -73,14 +73,16 @@ struct X121SMCStrategyXWZWorkingZone XCSupportZone *supportZones[]; XCResistanceZone *resistanceZones[]; - // - XConsolidationZone consolidationZones[]; - // XOBFVG insideZones[]; XOBFVG breakedZones[]; XOBFVG waitingZones[]; + // + XBoxZone insideBoxes[]; + XBoxZone breakedBoxes[]; + XConsolidationZone consolidationZones[]; + // CArrayObj mInsideZoneObjects; CArrayObj mBreakedZoneObjects; @@ -118,6 +120,10 @@ struct X121SMCStrategyXWZWorkingZone Clean(waitingZones); Clean(breakedZones); + // + Clean(insideBoxes); + Clean(breakedBoxes); + // Clean(supportZones); Clean(resistanceZones); @@ -504,10 +510,55 @@ struct X121SMCStrategyXWZWorkingZone 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 // + ); + } + + // + // Detect Waiting Zones based on STF and TTF ... + Clean(tmpWaitingZones); + count = ExtractOBFVGs( + tmpWaitingZones, + stfState, + ttfState // + ); + 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( - supplyZones, + tmpSupplies, NULL, XZONE_STATE_PASSED, false, @@ -518,11 +569,84 @@ struct X121SMCStrategyXWZWorkingZone 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; + } + + // + Add( + tmpSupplies[i], + supplyZones // + ); + + // + iBox.Clean(); + } + } + Clean(tmpSupplies); // // Demand Zones ... + XCDemandZone *tmpDemands[]; count = mtfState.FilterDemandZones( - demandZones, + tmpDemands, NULL, XZONE_STATE_PASSED, false, @@ -533,11 +657,84 @@ struct X121SMCStrategyXWZWorkingZone 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; + } + + // + Add( + tmpDemands[i], + demandZones // + ); + + // + iBox.Clean(); + } + } + Clean(demandZones); // // Support Zones ... + XCSupportZone *tmpSupports[]; count = stfState.FilterSupportZones( - supportZones, + tmpSupports, period, XZONE_STATE_PASSED, false, @@ -548,11 +745,84 @@ struct X121SMCStrategyXWZWorkingZone 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; + } + + // + Add( + tmpSupports[i], + supportZones // + ); + + // + iBox.Clean(); + } + } + Clean(tmpSupports); // - // Resistance Zones ... + // Resistance Zones .. + XCResistanceZone *tmpResistances[]; count = stfState.FilterResistanceZones( - resistanceZones, + tmpResistances, period, XZONE_STATE_PASSED, false, @@ -563,11 +833,260 @@ struct X121SMCStrategyXWZWorkingZone 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; + } + + // + 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; + } + + // + 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; + } + + // + Add( + tmpDemands[i], + demandZones // + ); + + // + iBox.Clean(); + } + } + Clean(demandZones); // // Support Zones ... - count = stfState.FilterSupportZones( - supportZones, + count = ttfState.FilterSupportZones( + tmpSupports, period, XZONE_STATE_PASSED, false, @@ -578,11 +1097,83 @@ struct X121SMCStrategyXWZWorkingZone 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; + } + + // + Add( + tmpSupports[i], + supportZones // + ); + + // + iBox.Clean(); + } + } + Clean(tmpSupports); // - // Resistance Zones ... - count = stfState.FilterResistanceZones( - resistanceZones, + // Resistance Zones .. + count = ttfState.FilterResistanceZones( + tmpResistances, period, XZONE_STATE_PASSED, false, @@ -593,6 +1184,78 @@ struct X121SMCStrategyXWZWorkingZone 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; + } + + // + Add( + tmpResistances[i], + resistanceZones // + ); + + // + iBox.Clean(); + } + } + Clean(tmpResistances); // // Consolidation Zones ... @@ -684,7 +1347,175 @@ struct X121SMCStrategyXWZWorkingZone } // - // Detect Inside Zones ... + // 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) { @@ -768,86 +1599,91 @@ struct X121SMCStrategyXWZWorkingZone } // - // Adding New OBFVG to Waiting Zones if not Exists ... - XOBFVG tmpWaitingZones[]; - count = ExtractOBFVGs( - tmpWaitingZones, - mtfState, - stfState // - ); - has = IsValidSize(count); + // Detect Breaked Boxes ... + has = HasInsideBoxes(); if (has) { // + int mustRemove[]; + count = CountInsideBoxes(); for (int i = 0; i < count; i++) { // - XOBFVG iOBFVG = tmpWaitingZones[i]; + XBoxZone iBox = insideBoxes[i]; + ENUM_X_DIRECTION iDir = iBox.dir; + bool isBullish = iBox.IsBullish(); // - idx = FindIndex( - iOBFVG, - waitingZones // - ); - has = IsValidIndex(idx); - if (has) + 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) { // - iOBFVG.Clean(); - continue; + idx = FindIndex( + iBox, + breakedBoxes // + ); + has = IsValidIndex(idx); + if (!has) + { + // + Add( + i, + mustRemove // + ); + + // + AddRef( + iBox, + breakedBoxes // + ); + } } - - // - AddRef( - iOBFVG, - waitingZones // - ); - - // - iOBFVG.Clean(); } + + // + has = HasChild(mustRemove); + if (has) + { + // + count = ArraySize(mustRemove); + for (int i = 0; i < count; i++) + { + // + ArrayRemove( + insideBoxes, + mustRemove[i], + 1 // + ); + } + } + + // + Clean(mustRemove); } // - // Detect Waiting Zones based on STF and TTF ... - Clean(tmpWaitingZones); - count = ExtractOBFVGs( - tmpWaitingZones, - stfState, - ttfState // - ); - 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(); - } - } + // Cleanup Resource ... // zBar.Clean(); @@ -964,6 +1800,30 @@ struct X121SMCStrategyXWZWorkingZone return ArraySize(consolidationZones); } + // + bool HasInsideBoxes() + { + return HasChild(insideBoxes); + } + + // + int CountInsideBoxes() + { + return ArraySize(insideBoxes); + } + + // + bool HasBreakedBoxes() + { + return HasChild(breakedBoxes); + } + + // + int CountBreakedBoxes() + { + return ArraySize(breakedBoxes); + } + // // // @@ -1270,17 +2130,41 @@ struct X121SMCStrategyXWZWorkingZone } // - has = HasBreakedZones(); + // has = HasBreakedZones(); + // if (has) + // { + // // + // count = CountBreakedZones(); + // for (int i = 0; i < count; i++) + // { + // breakedZones[i].UpdateTo(value); + // } + // } + + // + has = HasInsideBoxes(); if (has) { // - count = CountBreakedZones(); + count = CountInsideBoxes(); for (int i = 0; i < count; i++) { - breakedZones[i].UpdateTo(value); + insideBoxes[i].to = value; } } + // + // has = HasBreakedBoxes(); + // if (has) + // { + // // + // count = CountBreakedBoxes(); + // for (int i = 0; i < count; i++) + // { + // insideBoxes[i].to = value; + // } + // } + // } @@ -1509,6 +2393,7 @@ struct X121SMCStrategyXWZWorkingZone if (drawInsideZones) { // + // Zones ... has = HasInsideZones(); if (has) { @@ -1535,6 +2420,30 @@ struct X121SMCStrategyXWZWorkingZone } } } + + // + // 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); + } + } + } } // @@ -1568,6 +2477,30 @@ struct X121SMCStrategyXWZWorkingZone } } } + + // + // 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); + } + } + } } // @@ -2165,6 +3098,252 @@ bool DetectSelectedZoneConditions( return result; } +/** + * Check an XOBFVG instance has Required Conditions ... + * + * @param zone: XBoxZone instance ... + * @param state: XPOIState instance ... + * @param conditions: X121Conditions instance ... + * + * @return ( bool ) + */ +bool DetectSelectedZoneConditions( + 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 ... * @@ -2643,6 +3822,484 @@ bool DetectSelectedZonesTargets( 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 ... * diff --git a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 index 6d40147c..c028f6f1 100644 --- a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 @@ -768,8 +768,8 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // // XPV ... x121Inputs.xpvInputs.showSar = showAll || false; - x121Inputs.xpvInputs.showPeaks = showAll || false; - x121Inputs.xpvInputs.showVales = showAll || false; + x121Inputs.xpvInputs.showPeaks = showAll || true; + x121Inputs.xpvInputs.showVales = showAll || true; // // XHK ... @@ -805,9 +805,9 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // // XVWAP ... - x121Inputs.xvwapInputs.showVWapFast = showAll || true; - x121Inputs.xvwapInputs.showVWapMedium = showAll || true; - x121Inputs.xvwapInputs.showVWapSlow = showAll || true; + x121Inputs.xvwapInputs.showVWapFast = showAll || false; + x121Inputs.xvwapInputs.showVWapMedium = showAll || false; + x121Inputs.xvwapInputs.showVWapSlow = showAll || false; // // X3MA ...