diff --git a/Classes/x-saherelm.x-market.pattern.class.mq5 b/Classes/x-saherelm.x-market.pattern.class.mq5 index cf1bf71e..9e008f46 100644 --- a/Classes/x-saherelm.x-market.pattern.class.mq5 +++ b/Classes/x-saherelm.x-market.pattern.class.mq5 @@ -1672,10 +1672,9 @@ class XCMarketPatternDetector : public XCBase */ bool IsLegPattern( XOHCL &bar, - XBoxZone &zone, + XLeg &leg, int validationLength = 3, - int loopback = 10 //, - // Forces ... + int loopback = 10 // ) { // @@ -1683,7 +1682,7 @@ class XCMarketPatternDetector : public XCBase // // Prepare ... - zone.Clean(); + leg.Clean(); // // Normalize ... @@ -1717,6 +1716,7 @@ class XCMarketPatternDetector : public XCBase XOHCL iBar; XOHCL pBar; XOHCL iZBar; + XBoxZone zone; XBoxZone iZone; XBoxZone jZone; bool has = false; @@ -2032,6 +2032,31 @@ class XCMarketPatternDetector : public XCBase result = zone.IsValid(); } + // + // Prepare XLeg ... + if (result) + { + // + leg.dir = zone.dir; + leg.time = zone.from; + leg.upper = zone.upper; + leg.lower = zone.lower; + leg.symbol = zone.symbol; + leg.period = zone.period; + Copy(patterns, leg.patterns); + Copy(supports, leg.supports); + Copy(bullishBars, leg.bullishBars); + Copy(bearishBars, leg.bearishBars); + Copy(resistances, leg.resistances); + Copy(bullishFVGs, leg.bullishFVGs); + Copy(bearishFVGs, leg.bearishFVGs); + leg.sequentialBullishBars = sequentialsBullishBarsCount; + leg.sequentialBearishBars = sequentialsBearishBarsCount; + + // + result = leg.IsValid(); + } + // // Cleanup ... if (!result) @@ -2040,6 +2065,7 @@ class XCMarketPatternDetector : public XCBase } iBar.Clean(); pBar.Clean(); + zone.Clean(); iZBar.Clean(); iZone.Clean(); jZone.Clean(); diff --git a/Classes/x-saherelm.x-poi.drawer.class.mq5 b/Classes/x-saherelm.x-poi.drawer.class.mq5 index 3b9888a1..3a57c251 100644 --- a/Classes/x-saherelm.x-poi.drawer.class.mq5 +++ b/Classes/x-saherelm.x-poi.drawer.class.mq5 @@ -2526,6 +2526,29 @@ class XCPOIDrawer : public XCBase patternPivot.Clean(); } + /** + * Draw a Collection of Pattern Analysis ... + * + * @param analysises: XPatternAnalysis, collection reference to Data Source ... + * @param config: XPatternAnalysisDrawConfig, reference to Specified Drawing Config ... + */ + void DrawPatternAnalysises( + XPatternAnalysis &analysises[], + XPatternAnalysisDrawConfig &config // + ) { + // + bool has = HasChild(analysises); + if (!has) { + return; + } + + // + int count = ArraySize(analysises); + for (int i = 0; i < count; i++) { + DrawPatternAnalysis(analysises[i], config); + } + } + /** * Draw Specified Pivots Analysis ... * diff --git a/Libraries/x-saherelm.x-pivot.analysis.lib.mq5 b/Libraries/x-saherelm.x-pivot.analysis.lib.mq5 index 29ae1c11..504eb9de 100644 --- a/Libraries/x-saherelm.x-pivot.analysis.lib.mq5 +++ b/Libraries/x-saherelm.x-pivot.analysis.lib.mq5 @@ -2323,10 +2323,10 @@ struct XPatternAnalysis /** * Extract All Exists Patterns Pivots ... - * + * * @param dest: XPivot, collection reference to holds Extracted Patterns ... * @param forDir: ENUM_X_DIRECTION, Specified Direction of Extractions ... - * + * * @return ( int ) */ int GetPatterns( @@ -2584,7 +2584,8 @@ struct XPatternAnalysisConfig /** * Remove all Allowed Patterns and Directions ... */ - void CleanPatterns() { + void CleanPatterns() + { // XClean(allowedDirs); XClean(allowedPatterns); @@ -2915,6 +2916,199 @@ struct XPatternAnalysisDrawConfig } }; +/** + * an strucutre to Model Specified Leg Pattern ... + **/ +struct XLeg +{ + // + // Props ... + + // + datetime time; + string symbol; + ENUM_X_DIRECTION dir; + ENUM_TIMEFRAMES period; + + // + double upper; + double lower; + + // + XOHCL bullishBars[]; + XOHCL bearishBars[]; + + // + XBoxZone supports[]; + XBoxZone resistances[]; + + // + XBoxZone bullishFVGs[]; + XBoxZone bearishFVGs[]; + + // + XPatternAnalysis patterns[]; + + // + int sequentialBullishBars; + int sequentialBearishBars; + + // + // Constructor ... + + // + // Tools ... + + /** + * Cleanup ... + */ + void Clean() + { + // + time = NULL; + symbol = NULL; + period = NULL; + dir = X_DIRECTION_NONE; + + // + upper = 0; + lower = 0; + sequentialBullishBars = 0; + sequentialBearishBars = 0; + + // + XClean(patterns); + XClean(supports); + XClean(bullishBars); + XClean(bearishBars); + XClean(resistances); + XClean(bullishFVGs); + XClean(bearishFVGs); + } + + /** + * Validate ... + * + * @return ( bool ) + */ + bool IsValid() + { + // + bool result = false; + + // + result = + IsXValid(time) && + IsXValid(symbol) && + IsXValid(period) && + HasDirection(dir) && + NotEmptyZero(upper) && + NotEmptyZero(lower) && + upper > lower; + + // + return result; + } + + /** + * Check is Bullish ... + * + * @return ( bool ) + */ + bool IsBullish() + { + return IsValid() && + IsXBullish(dir); + } + + /** + * Check is Bearish ... + * + * @return ( bool ) + */ + bool IsBearish() + { + return IsValid() && + IsXBearish(dir); + } + + /** + * Converts a Leg to XBoxZone ... + * + * @param zone: XBoxZone, reference to holds Converted ... + * + * @return ( bool ) + */ + bool ToBox(XBoxZone &zone) + { + // + bool result = false; + + // + // Prepare ... + zone.Clean(); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + zone.at = time; + zone.dir = dir; + zone.from = time; + zone.upper = upper; + zone.lower = lower; + zone.symbol = symbol; + zone.period = period; + zone.to = TimeCurrent(); + zone.type = ToXString(X_BAR_PATTERN_LEG); + + // + result = zone.IsValid(); + + // + // Cleanup ... + if (!result) + { + zone.Clean(); + } + + // + return result; + } + + /** + * Update Times of Collections ... + * + * @param value: datetime, Specified Time ... + */ + void UpdateTimes(datetime value = NULL) + { + // + // Normalize ... + value = NormalizeTime(value); + + // + // Validate ... + if (!IsValid()) + { + return; + } + + // + UpdateToTime(supports, value); + UpdateToTime(resistances, value); + UpdateToTime(bullishFVGs, value); + UpdateToTime(bearishFVGs, value); + } + + // +}; + // // Extensions ... diff --git a/XFIMAEA/Classes/x-saherelm.xfima.signaller.class.mq5 b/XFIMAEA/Classes/x-saherelm.xfima.signaller.class.mq5 index 798544f0..7886f044 100644 --- a/XFIMAEA/Classes/x-saherelm.xfima.signaller.class.mq5 +++ b/XFIMAEA/Classes/x-saherelm.xfima.signaller.class.mq5 @@ -343,6 +343,10 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller return; } + // + // Manage Leg ... + ManageLeg(iBar); + // // Strategy X ... has = HasSignal( @@ -516,6 +520,118 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller // // Props ... + // + XLeg leg; // Exists Leg ... + + // + bool HasLeg() + { + return leg.IsValid(); + } + + // + bool ValidateLeg(XOHCL &bar) + { + // + bool result = false; + + // + result = HasLeg() && bar.IsValid(); + if (!result) + { + return result; + } + + // + result = + leg.IsBullish() + ? bar.low > leg.lower + : leg.IsBearish() + ? bar.high < leg.upper + : false; + + // + return result; + } + + // + void DrawLeg() + { + // + if (!HasLeg()) + { + return; + } + + // + // Update to Times ... + leg.UpdateTimes(); + + // + // Draw Leg Box ... + XBoxZone legZone; + leg.ToBox(legZone); + if (legZone.IsValid()) + { + // + legZone.to = TimeCurrent(); + poiDrawer.DrawZone(legZone, structureDrawConfig.drawConfig); + } + + // + // Draw Legs Other Stufs ... + return; + + // + // FVGs ... + poiDrawer.DrawZones(leg.bullishFVGs, structureDrawConfig.drawConfig); + poiDrawer.DrawZones(leg.bearishFVGs, structureDrawConfig.drawConfig); + + // + // Support and Resistances ... + poiDrawer.DrawZones(leg.supports, structureDrawConfig.drawConfig); + poiDrawer.DrawZones(leg.resistances, structureDrawConfig.drawConfig); + + // + // Patterns ... + poiDrawer.DrawPatternAnalysises(leg.patterns, structureDrawConfig.barAnalysisDrawConfig); + } + + // + void ManageLeg(XOHCL &bar) + { + // + if (HasLeg()) + { + // + if (!ValidateLeg(bar)) + { + // + // Invalidate XLeg ... + leg.Clean(); + } + } + + // + // Detect New Leg ... + if (!HasLeg()) + { + poiDetector.IsLegPattern(bar, leg); + } + + // + // Update Exists Leg ... + if (HasLeg()) + { + // + // Update to Times ... + leg.UpdateTimes(); + + // + DrawLeg(); + } + } + // // Implementing Strategies ... @@ -1905,51 +2021,80 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller // if (result) { - // - UpdateToTime(orderFlow, bar.time); - poiDrawer.DrawZones(orderFlow, structureDrawConfig.drawConfig); - poiDrawer.DrawPatternAnalysis(pBarPatterns, structureDrawConfig.barAnalysisDrawConfig); + // // + // UpdateToTime(orderFlow, bar.time); + // poiDrawer.DrawZones(orderFlow, structureDrawConfig.drawConfig); + // poiDrawer.DrawPatternAnalysis(pBarPatterns, structureDrawConfig.barAnalysisDrawConfig); - // - // Draw ATR Band Middle ... - if (NotEmptyZero(atrBandMiddle)) - { - // - XPOIDrawConfig iConfig = structureDrawConfig.drawConfig; - iConfig.trendRayLeft = false; - iConfig.trendRayRight = false; + // // + // // Draw ATR Band Middle ... + // if (NotEmptyZero(atrBandMiddle)) + // { + // // + // XPOIDrawConfig iConfig = structureDrawConfig.drawConfig; + // iConfig.trendRayLeft = false; + // iConfig.trendRayRight = false; - // - datetime to = bar.time; - datetime from = p2Bar.BeforeOn(); - string trendName = "ATRBandMiddle_" + ToXString(TimeToSeconds(p2Bar.time)); - poiDrawer.DrawTrendLine( - trendName, - atrBandMiddle, - from, - atrBandMiddle, - to, - iConfig, - clrYellow // - ); + // // + // datetime to = bar.time; + // datetime from = p2Bar.BeforeOn(); + // string trendName = "ATRBandMiddle_" + ToXString(TimeToSeconds(p2Bar.time)); + // poiDrawer.DrawTrendLine( + // trendName, + // atrBandMiddle, + // from, + // atrBandMiddle, + // to, + // iConfig, + // clrYellow // + // ); - // - iConfig.Clean(); - } + // // + // iConfig.Clean(); + // } - // - Print("OrderFlow ..."); + // // + // Print("OrderFlow ..."); } - // - XBoxZone legZone; - result = poiDetector.IsLegPattern(pBar, legZone); - if (result) - { - // - poiDrawer.DrawZone(legZone, structureDrawConfig.drawConfig); - Print("Leg Pattern Detected ..."); - } + // // + // XLeg leg; + // result = poiDetector.IsLegPattern(pBar, leg); + // if (result) + // { + // // + // // Update to Times ... + // leg.UpdateTimes(bar.time); + + // // + // // Draw Leg Box ... + // XBoxZone legZone; + // leg.ToBox(legZone); + // if (legZone.IsValid()) + // { + // poiDrawer.DrawZone(legZone, structureDrawConfig.drawConfig); + // } + + // // + // // Draw Legs Other Stufs ... + + // // + // // FVGs ... + // poiDrawer.DrawZones(leg.bullishFVGs, structureDrawConfig.drawConfig); + // poiDrawer.DrawZones(leg.bearishFVGs, structureDrawConfig.drawConfig); + + // // + // // Support and Resistances ... + // poiDrawer.DrawZones(leg.supports, structureDrawConfig.drawConfig); + // poiDrawer.DrawZones(leg.resistances, structureDrawConfig.drawConfig); + + // // + // // Patterns ... + // poiDrawer.DrawPatternAnalysises(leg.patterns, structureDrawConfig.barAnalysisDrawConfig); + + // // + // Print("Leg Pattern Detected ..."); + // } // isBullish =