From 696d3a55dac34e96efd933085bfe1cb185257472 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Thu, 25 Sep 2025 01:07:32 +0330 Subject: [PATCH] last ... --- Classes/x-saherelm.x-market.pattern.class.mq5 | 147 +++++++++++++++- Experts/x-saherelm.xfima.backtester.ea.mq5 | 158 ++++++++++-------- 2 files changed, 236 insertions(+), 69 deletions(-) diff --git a/Classes/x-saherelm.x-market.pattern.class.mq5 b/Classes/x-saherelm.x-market.pattern.class.mq5 index 20000a2b..14504453 100644 --- a/Classes/x-saherelm.x-market.pattern.class.mq5 +++ b/Classes/x-saherelm.x-market.pattern.class.mq5 @@ -1179,7 +1179,7 @@ class XCMarketPatternDetector : public XCBase iBar, ob, true, // Force FVG Bar Type ... - true // Force OB First Two Bar InDirection ... + true // Force OB First Two Bar InDirection ... ); if (!has) { @@ -1224,6 +1224,151 @@ class XCMarketPatternDetector : public XCBase return result; } + /** + * Detect Liquidity Sweeps ... + * + * @param bar: XOHCL, Specified Bar ... + * @param dir: ENUM_X_DIRECTION a reference for Direction ... + * @param sweeperBar: XOHCL, reference for Holding Sweeper Bar ... + * @param zone: XBoxZone, reference for Holding new Support/Resistance after Liquidity Sweeped ... + * @param sweepedLiquidity: XBoxZone, reference for Holding Sweeped Liquidity Zone ... + * @param liquidityLoopbackLength: int, Max Allowed Length to Sweep a Liquidity ... + * @param zoneValidationLength: int, Liquidity Detection Validatio Length ... + * @param zodeMaxAllowedLoopback: int, Max Allowed Loopback Length to Detect Liquidity ... + * + * @return ( bool ) + */ + bool HasSweepedLiquidity( + XOHCL &bar, + ENUM_X_DIRECTION &dir, + XOHCL &sweeperBar, + XBoxZone &zone, + XBoxZone &sweepedLiquidity, + int liquidityLoopbackLength = 21, + int zoneValidationLength = 21, + int zodeMaxAllowedLoopback = 1500 // + ) + { + // + bool result = false; + + // + // Prepare ... + zone.Clean(); + sweeperBar.Clean(); + CleanDirection(dir); + sweepedLiquidity.Clean(); + + // + // Normalize ... + zoneValidationLength = NormalizeInt(zoneValidationLength, 7); + liquidityLoopbackLength = NormalizeInt(liquidityLoopbackLength, 5); + zodeMaxAllowedLoopback = NormalizeInt(zodeMaxAllowedLoopback, 21, 1500); + + // + // Validate ... + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + XOHCL supportBar; + XOHCL resistanceBar; + datetime barBeofreOn = bar.BeforeOn(); + + // + // Current Bar must has Support / Resistance ... + + // + // Support ... + bool hasSupport = HasSupport( + bar, + supportBar, + zoneValidationLength, + zodeMaxAllowedLoopback // + ); + + // + // Validate Fresh Support ... + hasSupport = + hasSupport && + supportBar.time == barBeofreOn; + + // + // Validate Support Box Exists ... + hasSupport = + hasSupport && + ToSupportBox(supportBar, zone); + + // + // Resistance ... + bool hasResistance = HasResistance( + bar, + resistanceBar, + zoneValidationLength, + zodeMaxAllowedLoopback // + ); + + // + // Validate Fresh Resistance ... + hasResistance = + hasResistance && + resistanceBar.time == barBeofreOn; + + // + // Validate Resistance Box Existx ... + hasResistance = + hasResistance && + ToResistanceBox(resistanceBar, zone); + + // + result = + hasSupport || + hasResistance; + if (!result) + { + // + zone.Clean(); + sweeperBar.Clean(); + supportBar.Clean(); + CleanDirection(dir); + resistanceBar.Clean(); + sweepedLiquidity.Clean(); + + // + return result; + } + + // + + // + // Validate ... + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + result = HasDirection(dir); + + // + // Cleanup Resources ... + if (!result) + { + // + zone.Clean(); + sweeperBar.Clean(); + CleanDirection(dir); + sweepedLiquidity.Clean(); + } + + // + return result; + } + // // Trending ... diff --git a/Experts/x-saherelm.xfima.backtester.ea.mq5 b/Experts/x-saherelm.xfima.backtester.ea.mq5 index 70bd28e2..456a8c8c 100644 --- a/Experts/x-saherelm.xfima.backtester.ea.mq5 +++ b/Experts/x-saherelm.xfima.backtester.ea.mq5 @@ -456,38 +456,45 @@ void OnTick() fima1Signaller.OnTick(); fima2Signaller.OnTick(); - // // - // // Initial Bar for Analysis ... - // XOHCL cBar; - // bool isInited = cBar.Init( - // _Symbol, - // _Period, - // 1 // - // ); + // + // Initial Bar for Analysis ... + XOHCL cBar; + bool isInited = cBar.Init( + _Symbol, + _Period, + 1 // + ); + // + // Here We Apply Custom Detecting ... + detectorConfig.OffDetectors(); + detectorConfig.detectSupport = true; + detectorConfig.detectResistance = true; + detectorConfig.detectSignalKeyBarPattern = false; + detectorConfig.supportAndResistanceValidationLength = 21; // // Analyse Market ... - // fima2Signaller.poiDetector.AnalyseMarket( - // cBar, - // marketStructure, - // detectorConfig // - // ); - // CArrayObj *iObjects; - // int drawnsCount = fima2Signaller.poiDrawer.DrawMarketStructure( - // marketStructure, - // marketStructureDrawerConfig, - // iObjects // - // ); - // if (IsValidSize(drawnsCount)) - // { - // // - // AddObjects( - // iObjects, - // eaDraws // - // ); - // } + fima2Signaller.poiDetector.AnalyseMarket( + cBar, + marketStructure, + detectorConfig // + ); + CArrayObj *iObjects; + int drawnsCount = fima2Signaller.poiDrawer.DrawMarketStructure( + marketStructure, + marketStructureDrawerConfig, + iObjects // + ); + if (IsValidSize(drawnsCount)) + { + // + AddObjects( + iObjects, + eaDraws // + ); + } - // // + // // if (HasDirection(marketStructure.signalKeyBarPatternDir)) // { // Print("Detected ..."); @@ -496,10 +503,25 @@ void OnTick() // { // Print("Detected ..."); // } - // if (marketStructure.support.IsValid() || marketStructure.resistance.IsValid()) - // { - // Print("Detected ..."); - // } + if (marketStructure.support.IsValid() || marketStructure.resistance.IsValid()) + { + // + // Check Conditions ... + datetime beforeTime = cBar.BeforeOn(); + bool hasSupport = + (marketStructure.support.IsValid() && + marketStructure.support.from == beforeTime); + bool hasResistance = + (marketStructure.resistance.IsValid() && + marketStructure.resistance.from == beforeTime); + bool has = + hasSupport || + hasResistance; + if (has) + { + Print("Detected ..."); + } + } } // @@ -680,44 +702,44 @@ void OnSignalTriggered(XSignal &signal) eaDraws.Add(iObj); } - // - // Here We Apply Custom Detecting ... - detectorConfig.OffDetectors(); - detectorConfig.detectSupport = true; - detectorConfig.detectResistance= true; - detectorConfig.detectSignalKeyBarPattern = true; + // // + // // Here We Apply Custom Detecting ... + // detectorConfig.OffDetectors(); + // detectorConfig.detectSupport = true; + // detectorConfig.detectResistance= true; + // detectorConfig.detectSignalKeyBarPattern = true; - // - // Initial Bar for Analysis ... - // at Signal Time ... - XOHCL signalBar; - bool isInited = signalBar.Init( - signal.symbol, - signal.period, - signal.time // - ); + // // + // // Initial Bar for Analysis ... + // // at Signal Time ... + // XOHCL signalBar; + // bool isInited = signalBar.Init( + // signal.symbol, + // signal.period, + // signal.time // + // ); - // - // Analyse Market ... - fima1Signaller.poiDetector.AnalyseMarket( - signalBar, - marketStructure, - detectorConfig // - ); - CArrayObj *iObjects; - int drawnsCount = fima2Signaller.poiDrawer.DrawMarketStructure( - marketStructure, - marketStructureDrawerConfig, - iObjects // - ); - if (IsValidSize(drawnsCount)) - { - // - AddObjects( - iObjects, - eaDraws // - ); - } + // // + // // Analyse Market ... + // fima1Signaller.poiDetector.AnalyseMarket( + // signalBar, + // marketStructure, + // detectorConfig // + // ); + // CArrayObj *iObjects; + // int drawnsCount = fima2Signaller.poiDrawer.DrawMarketStructure( + // marketStructure, + // marketStructureDrawerConfig, + // iObjects // + // ); + // if (IsValidSize(drawnsCount)) + // { + // // + // AddObjects( + // iObjects, + // eaDraws // + // ); + // } // // Alert Issued Signal ...