diff --git a/Documents/BKP/XFIMA Signals/x-saherelm.xfima.signaller.class copy.mq5 b/Documents/BKP/XFIMA Signals/x-saherelm.xfima.signaller.class copy.mq5 index 749cb7ee..65f73531 100644 --- a/Documents/BKP/XFIMA Signals/x-saherelm.xfima.signaller.class copy.mq5 +++ b/Documents/BKP/XFIMA Signals/x-saherelm.xfima.signaller.class copy.mq5 @@ -286,9 +286,24 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller // Configure ... drawLeg = true; drawZones = true; + drawIZones = true; + drawTrends = true; + drawSCTrend = true; + drawMCTrend = true; + drawLCTrend = true; + drawHCTrend = true; drawSupport = true; + drawISupport = true; drawOrderFlow = true; drawResistance = true; + drawIResistance = true; + + // + manageLegs = true; + manageZones = true; + manageIZones = true; + manageTrends = false; + manageOrderFlow = true; // structureConfig.Default(); @@ -443,6 +458,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller // XClean(guards); + return result; // int positionsCount = ArraySize(positions); @@ -600,7 +616,9 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller // ManageLeg(bar); + ManageTrends(bar); ManageZones(p2Bar); + ManageIZones(p2Bar); ManageOrderFlow(p3Bar); // @@ -621,6 +639,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller XLeg leg; // Exists Leg ... bool drawLeg; // Draw Leg ... + bool manageLegs; // bool HasLeg() @@ -745,6 +764,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller // bool drawOrderFlow; XBoxZone orderFlow[]; + bool manageOrderFlow; ENUM_X_DIRECTION orderFlowDir; // @@ -932,6 +952,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller XBoxZone resistance; bool drawZones; bool drawSupport; + bool manageZones; bool drawResistance; // @@ -978,6 +999,13 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller !IsBreaked(support, X_PRICE_CLOSE); if (!result) { + // + iResistance = support; + iResistance.breakAt = NULL; + iResistance.dir = X_DIRECTION_BEARISH; + iResistance.to = bar.time + (PeriodSeconds(bar.period)); + iResistance.from = bar.time - (PeriodSeconds(bar.period)); + // support.breakAt = bar.time; support.Clean(); @@ -994,6 +1022,13 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller !IsBreaked(resistance, X_PRICE_CLOSE); if (!result) { + // + iSupport = resistance; + iSupport.breakAt = NULL; + iSupport.dir = X_DIRECTION_BULLISH; + iSupport.to = bar.time + (PeriodSeconds(bar.period)); + iSupport.from = bar.time - (PeriodSeconds(bar.period)); + // resistance.breakAt = bar.time; resistance.Clean(); @@ -1048,6 +1083,14 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller // Support ... if (IsXValid(support.breakAt)) { + // + iResistance = support; + iResistance.breakAt = NULL; + iResistance.dir = X_DIRECTION_BEARISH; + iResistance.to = bar.time + (PeriodSeconds(bar.period)); + iResistance.from = bar.time - (PeriodSeconds(bar.period)); + + // support.Clean(); } @@ -1055,6 +1098,14 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller // Resistance ... if (IsXValid(resistance.breakAt)) { + // + iSupport = resistance; + iSupport.breakAt = NULL; + iSupport.dir = X_DIRECTION_BULLISH; + iSupport.to = bar.time + (PeriodSeconds(bar.period)); + iSupport.from = bar.time - (PeriodSeconds(bar.period)); + + // resistance.Clean(); } } @@ -1085,6 +1136,18 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller !IsBreaked(support, X_PRICE_CLOSE); if (!has) { + // + if (support.IsValid()) + { + // + iResistance = support; + iResistance.breakAt = NULL; + iResistance.dir = X_DIRECTION_BEARISH; + iResistance.to = bar.time + (PeriodSeconds(bar.period)); + iResistance.from = bar.time - (PeriodSeconds(bar.period)); + } + + // support.Clean(); } } @@ -1110,6 +1173,18 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller !IsBreaked(resistance, X_PRICE_CLOSE); if (!has) { + // + if (resistance.IsValid()) + { + // + iSupport = resistance; + iSupport.breakAt = NULL; + iSupport.dir = X_DIRECTION_BULLISH; + iSupport.to = bar.time + (PeriodSeconds(bar.period)); + iSupport.from = bar.time - (PeriodSeconds(bar.period)); + } + + // resistance.Clean(); } } @@ -1124,7 +1199,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller { // support.to = bar.time; - support.type = "XFIMASUP"; + support.type = "XFIMASup"; } // @@ -1144,6 +1219,323 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller tmpBar.Clean(); } + // + XBoxZone iSupport; + XBoxZone iResistance; + bool drawIZones; + bool drawISupport; + bool manageIZones; + bool drawIResistance; + + // + bool HasIZones() + { + // + return HasISupport() || + HasIResistance(); + } + + // + bool HasISupport() + { + return iSupport.IsValid(); + } + + // + bool HasIResistance() + { + return iResistance.IsValid(); + } + + // + void DrawIZones() + { + // + if (!drawIZones || !HasIZones()) + { + return; + } + + // + if (drawISupport && HasISupport()) + { + poiDrawer.DrawZone(iSupport, structureDrawConfig.drawConfig); + } + + // + if (drawIResistance && HasIResistance()) + { + poiDrawer.DrawZone(iResistance, structureDrawConfig.drawConfig); + } + } + + // + bool ValidateIZones(XOHCL &bar) + { + // + bool result = false; + + // + // Validate ... + result = bar.IsValid() && + HasIZones(); + if (!result) + { + return result; + } + + // + + // + // Support ... + bool hasSupport = HasISupport(); + if (hasSupport) + { + // + result = bar.close > iSupport.lower && + !IsBreaked(iSupport, X_PRICE_CLOSE); + if (!result) + { + // + iSupport.breakAt = bar.time; + iSupport.Clean(); + } + } + + // + // Resistance ... + bool hasResistance = HasIResistance(); + if (hasResistance) + { + // + result = bar.close < iResistance.upper && + !IsBreaked(iResistance, X_PRICE_CLOSE); + if (!result) + { + // + iResistance.breakAt = bar.time; + iResistance.Clean(); + } + } + + // + result = + (hasSupport && !HasISupport()) || + (hasResistance && !HasIResistance()); + + // + return result; + } + + // + void ManageIZones(XOHCL &bar) + { + // + // Validate Exists ... + if (HasIZones()) + { + // + if (!ValidateIZones(bar)) + { + // + // Invalidate Zones ... + + // + // Support ... + if (IsXValid(iSupport.breakAt)) + { + iSupport.Clean(); + } + + // + // Resistance ... + if (IsXValid(iResistance.breakAt)) + { + iResistance.Clean(); + } + } + } + + // + // Update Exists ... + if (HasIZones()) + { + // + if (HasISupport()) + { + // + iSupport.to = bar.time; + iSupport.type = "XFIMAISup"; + } + + // + if (HasIResistance()) + { + // + iResistance.to = bar.time; + iResistance.type = "XFIMAIRes"; + } + + // + DrawIZones(); + } + } + + // + // Trends ... + + // + XTrend scTrend; + XTrend mcTrend; + XTrend lcTrend; + XTrend hcTrend; + + // + bool drawTrends; + bool drawSCTrend; + bool drawMCTrend; + bool drawLCTrend; + bool drawHCTrend; + bool manageTrends; + + // + bool HasTrend() + { + // + bool result = + HasSCTrend() || + HasMCTrend() || + HasLCTrend() || + HasHCTrend(); + + // + return result; + } + + // + bool HasSCTrend() + { + return scTrend.IsValid() && + scTrend.HasTrend(); + } + + // + bool HasMCTrend() + { + return mcTrend.IsValid() && + mcTrend.HasTrend(); + } + + // + bool HasLCTrend() + { + return lcTrend.IsValid() && + lcTrend.HasTrend(); + } + + // + bool HasHCTrend() + { + return hcTrend.IsValid() && + hcTrend.HasTrend(); + } + + // + void DrawTrends() + { + // + if (!drawTrends || !HasTrend()) + { + return; + } + + // + // SC ... + if (drawSCTrend && HasSCTrend()) + { + poiDrawer.DrawTrendLine(scTrend, structureDrawConfig.drawConfig); + } + + // + // MC ... + if (drawMCTrend && HasMCTrend()) + { + poiDrawer.DrawTrendLine(mcTrend, structureDrawConfig.drawConfig); + } + + // + // LC ... + if (drawLCTrend && HasLCTrend()) + { + poiDrawer.DrawTrendLine(lcTrend, structureDrawConfig.drawConfig); + } + + // + // HC ... + if (drawHCTrend && HasHCTrend()) + { + poiDrawer.DrawTrendLine(hcTrend, structureDrawConfig.drawConfig); + } + } + + // + void ManageTrends(XOHCL &bar) + { + // + // Validate ... + bool has = bar.IsValid(); + if (!has) + { + return; + } + + // + XTrend tmpTrend; + + // + // SC ... + tmpTrend.Clean(); + has = fimaParser.HasSCTrend(tmpTrend, bar.Index()); + if (has) + { + scTrend = tmpTrend; + } + + // + // MC ... + tmpTrend.Clean(); + has = fimaParser.HasMCTrend(tmpTrend, bar.Index()); + if (has) + { + mcTrend = tmpTrend; + } + + // + // LC ... + tmpTrend.Clean(); + has = fimaParser.HasLCTrend(tmpTrend, bar.Index()); + if (has) + { + lcTrend = tmpTrend; + } + + // + // HC ... + tmpTrend.Clean(); + has = fimaParser.HasHCTrend(tmpTrend, bar.Index()); + if (has) + { + hcTrend = tmpTrend; + } + + // + DrawTrends(); + + // + // Cleanup ... + tmpTrend.Clean(); + } + // // Implementing Strategies ... @@ -1173,8 +1565,8 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller // // Signaller Flags ... bool useSignaller1 = false; - bool useSignaller2 = false; - bool useSignaller3 = false; + bool useSignaller2 = true; + bool useSignaller3 = true; bool useSignaller4 = true; // @@ -1193,17 +1585,25 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller // Draw Flags ... bool draw = true; bool drawZone = true; - bool drawMarketStructurePivots = true; - bool drawMarketStructureAnalysis = true; - bool drawMarketStructureOrderFlow = true; + bool drawMarketStructurePivots = false; + bool drawMarketStructureAnalysis = false; + bool drawMarketStructureOrderFlow = false; XPOIDrawConfig iDrawConfig; // drawLeg = false; - drawZones = true; - drawSupport = true; + drawZones = false; + drawIZones = false; + drawTrends = false; + drawSCTrend = false; + drawMCTrend = false; + drawLCTrend = false; + drawHCTrend = false; + drawSupport = false; + drawISupport = false; drawOrderFlow = false; - drawResistance = true; + drawResistance = false; + drawIResistance = false; // // Signal Checking ... @@ -1212,19 +1612,6 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller // Analyse Market Strucutre ... XFIMAMarketStructure marketStructure; - // - // Check Market ... - // result = HasLeg() && - // HasOrderFlow() && - // orderFlowDir == leg.dir; - // result = HasBearishOrderFlow(); - // if (result) - // { - // // - // result = false; - // DebugBreak(); - // } - // // Signaller 1 ... if (!result && useSignaller1) @@ -1535,13 +1922,6 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller dir = X_DIRECTION_NONE; } - // - // Debug Breake ... - if (result) - { - DebugBreak(); - } - // // Cleanup ... iDrawConfig.Clean(); @@ -2102,7 +2482,22 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller } /** - * Check Bar Has Signal Based on Strategy 4 ... + * Check Bar Has Signal Based on Strategy 3 ... + * + * Strategy 3: + * =========== + * - Works Based On Breaked Support or Resistances ... + * - Looking for a Support or Resistance to Breaked ... + * - Validate Breaker Bar to Change Peak or Vale ... + * - Validate Bar Opposit Side of Breaker Bar's Shadow ... + * - Validate by Checking Market Strucutre to Has Directional Zone + * (Support for Resistance Break / Resistance for Support Break) ... + * - Validate Breaker Bar to Has Directional FVG ... + * + * Manipulations: + * ================ + * there are Some Flags properties to Change Validations in Strategy ... + * we can use them for Testing Purposes ... * * @param bar: XOHCL, reference to Bar ... * @param zone: XBoxZone, reference to holds affected zone ... @@ -2136,12 +2531,13 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller } // - // Configurations ... - int patternsFillValidation = 3; + // Validation Flags ... // - // Validation Flags ... - bool validateByBarPatterns = true; + bool validateByPVChanges = true; + bool validateByGapExists = true; + bool validateByBarShadows = true; + bool validateHasDirectionalZone = true; // // Define Requirements ... @@ -2176,134 +2572,264 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller // // Retrieve pBar Patterns ... + XBoxZone _fvg; + XBoxZone _support; + XBoxZone _resistance; XPatternAnalysis pBarPatterns; + XPatternAnalysis p2BarPatterns; XPatternAnalysisConfig patternConfig = structureConfig.barsAnalysisConfig; + + // poiDetector.AnalyseBarPatterns( pBar, pBarPatterns, patternConfig // ); + poiDetector.AnalyseBarPatterns( + p2Bar, + p2BarPatterns, + patternConfig // + ); // - int pBarBullishPatternsCount = - !pBarPatterns.IsValid() - ? 0 - : pBarPatterns.Count(X_DIRECTION_BULLISH); - bool isPBarFillBullishPatterns = - IsValidSize(pBarBullishPatternsCount) && - pBarBullishPatternsCount >= patternsFillValidation; - bool isPBarHasBullishPatterns = - pBarPatterns.IsValid() && - ( - // - pBarPatterns.IsPinned(X_DIRECTION_BULLISH) || - pBarPatterns.IsEngulfed(X_DIRECTION_BULLISH) || - pBarPatterns.IsMomentum(X_DIRECTION_BULLISH) || - pBarPatterns.IsPiercing(X_DIRECTION_BULLISH) || - pBarPatterns.IsSignalKey(X_DIRECTION_BULLISH) - // - ); + // Price Must Break Support or Resistance ... // - int pBarBearishPatternsCount = - !pBarPatterns.IsValid() - ? 0 - : pBarPatterns.Count(X_DIRECTION_BEARISH); - bool isPBarFillBearishPatterns = - IsValidSize(pBarBearishPatternsCount) && - pBarBearishPatternsCount >= patternsFillValidation; - bool isPBarHasBearishPatterns = - pBarPatterns.IsValid() && - ( - // - pBarPatterns.IsPinned(X_DIRECTION_BEARISH) || - pBarPatterns.IsEngulfed(X_DIRECTION_BEARISH) || - pBarPatterns.IsMomentum(X_DIRECTION_BEARISH) || - pBarPatterns.IsPiercing(X_DIRECTION_BEARISH) || - pBarPatterns.IsSignalKey(X_DIRECTION_BEARISH) - // - ); + // Extract Support and Resistance ... + bool hasSupport = p2BarPatterns.IsSupport(); + bool hasResistance = p2BarPatterns.IsResistance(); + if (hasSupport) + { + // + XOHCL tmpBar; + XPivot tmpPivot; + hasSupport = p2BarPatterns.GetSupport(tmpBar, tmpPivot, _support); + tmpBar.Clean(); + tmpPivot.Clean(); + } + if (hasResistance) + { + // + XOHCL tmpBar; + XPivot tmpPivot; + hasResistance = p2BarPatterns.GetResistance(tmpBar, tmpPivot, _resistance); + tmpBar.Clean(); + tmpPivot.Clean(); + } // - bool hasSupport = HasSupport(); - bool hasResistance = HasResistance(); + bool hasBreakedSupport = hasSupport && + pBar.close < _support.lower && + p2Bar.close > _support.lower; + bool hasBreakedResistance = hasResistance && + pBar.close > _resistance.upper && + p2Bar.close < _resistance.upper; // - bool isP2BarInSupport = hasSupport && - pBar.low > support.lower && - p2Bar.low < support.upper && - p2Bar.low > support.lower; + isBullish = hasBreakedResistance; + isBearish = hasBreakedSupport; // - bool isP2BarInResistance = hasResistance && - pBar.high < resistance.upper && - p2Bar.high > resistance.lower && - p2Bar.high < resistance.upper; - - // - isBullish = - hasSupport && - isP2BarInSupport; - - // - isBearish = - hasResistance && - isP2BarInResistance; - - // - // Summarize Result ... result = isBullish || isBearish; // - // Validate Bar Patterns ... - if (result && validateByBarPatterns) + // Validate By PV Changed ... + // Breaker Bar must Change Peak or Value ... + if (result && validateByPVChanges) { + // + bool isPeakOverLast = fimaParser.IsPeakOverLast(pBar.Index()); + bool isValeUnderLast = fimaParser.IsValeUnderLast(pBar.Index()); + // isBullish = isBullish && - isPBarHasBullishPatterns && - isPBarFillBullishPatterns; + isPeakOverLast; // isBearish = isBearish && - isPBarHasBearishPatterns && - isPBarFillBearishPatterns; + isValeUnderLast; // - // Summarize result ... + // Summarize Result ... result = isBullish || isBearish; } // - if (result) + // Validate by Bar Shadows ... + // Breakre Bar Side Shadow must not Reached ... + if (result && validateByBarShadows) { // - poiDrawer.DrawPatternAnalysis(pBarPatterns, structureDrawConfig.barAnalysisDrawConfig); - // poiDrawer.DrawPatternAnalysis(p2BarPatterns, structureDrawConfig.barAnalysisDrawConfig); - DebugBreak(); + isBullish = + isBullish && + pBar.low > p2Bar.low; // - result = false; - isBullish = false; - isBearish = false; + isBearish = + isBearish && + pBar.high < p2Bar.high; + + // + // Summarize Result ... + result = isBullish || isBearish; } // - // Validate ... - result = isBullish || - isBearish; - - // - // Prepare Zone ... - if (result) + // Validate Has Directional Zone ... + if (result && validateHasDirectionalZone) { + // + isBullish = + isBullish && + hasSupport; + + // + isBearish = + isBearish && + hasResistance; + + // + // Summarize Result ... + result = isBullish || isBearish; } // - // Prepare Targets ... + // Validate By Gap Exists ... + if (result && validateByGapExists) + { + // + ENUM_X_DIRECTION tmpDir; + bool hasFVG = poiDetector.HasFVG( + pBar, + tmpDir, + _fvg // + ); + + // + isBullish = + isBullish && + hasFVG && + IsXBullish(tmpDir); + + // + isBearish = + isBearish && + hasFVG && + IsXBearish(tmpDir); + + // + // Summarize Result ... + result = isBullish || isBearish; + } + + // + // Prepare Direction and Zone ... if (result) { + // + if (isBullish) + { + // + zone = _resistance; + zone.dir = Opposit(_resistance.dir); + dir = zone.dir; + zone.upper = MathMax(zone.upper, _fvg.upper); + zone.lower = MathMin(zone.lower, _fvg.lower); + } + + // + if (isBearish) + { + // + zone = _support; + zone.dir = Opposit(_support.dir); + dir = zone.dir; + zone.upper = MathMax(zone.upper, _fvg.upper); + zone.lower = MathMin(zone.lower, _fvg.lower); + } + + // + // Zone Validation Base ... + result = zone.IsValid(); + if (result) + { + // + // Validate By Trend of Zone ... + XTrend zoneTrend; + XTrend zoneToTrend; + + // + // Detecting Trends ... + result = poiDetector.HasBoundaryTrend(zone, zoneTrend, false); + result = result && + poiDetector.HasBoundaryTrend(zone, zoneToTrend, true); + + // + // Validate Trend ... + result = + result && + zone.dir == zoneTrend.dir && + zone.dir == zoneToTrend.dir; + + // + // Draw ... + if (result) + { + // + XPOIDrawConfig iConfig = structureDrawConfig.drawConfig; + iConfig.trendRayLeft = false; + iConfig.trendRayRight = false; + + // + poiDrawer.DrawTrendLine(zoneTrend, iConfig); + poiDrawer.DrawTrendLine(zoneToTrend, iConfig); + + // + iConfig.Clean(); + } + + // + // Cleanup ... + zoneTrend.Clean(); + zoneToTrend.Clean(); + + // + // Reset Flags ... + if (!result) + { + // + zone.Clean(); + isBullish = false; + isBearish = false; + } + } + + // + result = zone.IsValid(); + } + + // + if (result) + { + // + if (_support.IsValid()) + { + poiDrawer.DrawZone(_support, structureDrawConfig.drawConfig); + } + + // + if (_resistance.IsValid()) + { + poiDrawer.DrawZone(_resistance, structureDrawConfig.drawConfig); + } + + // + if (pBarPatterns.IsValid()) + { + poiDrawer.DrawPatternAnalysis(pBarPatterns, structureDrawConfig.barAnalysisDrawConfig); + } } // @@ -2318,9 +2844,9 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller pBar.Clean(); p2Bar.Clean(); p3Bar.Clean(); - // pBarPatterns.Clean(); - // patternConfig.Clean(); - // p2BarPatterns.Clean(); + pBarPatterns.Clean(); + p2BarPatterns.Clean(); + patternConfig.Clean(); // return result; @@ -2450,8 +2976,9 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller // XTrend boundaryTrend; - double boundaryMax = EMPTY_VALUE; - double boundaryMin = EMPTY_VALUE; + XTrend boundaryZoneTrend; + + // double atrBandUpper = EMPTY_VALUE; double atrBandLower = EMPTY_VALUE; double atrBandMiddle = EMPTY_VALUE; @@ -2806,8 +3333,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller // // Validate ... - result = isBullish || - isBearish; + result = isBullish || isBearish; if (result) { // @@ -2844,205 +3370,42 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller if (result && validateByXFIMABoundary) { // - // Reading Zones Boundary ... - XPivot uppers[]; - XPivot lowers[]; - int boundariesCount = poiDetector.CollectZonesBoundary(uppers, lowers, zone); - int lowestIDX = GetLowest(lowers); - int highestIDX = GetHighest(uppers); - if (IsValidIndex(lowestIDX)) - { - boundaryMin = lowers[lowestIDX].value; - } - if (IsValidIndex(highestIDX)) - { - boundaryMax = uppers[highestIDX].value; - } + // Try to Retrieve Boundary To Trend ... + result = poiDetector.HasBoundaryTrend( + zone, + boundaryTrend, + true // + ); // - isBullish = - isBullish && - IsValidIndex(lowestIDX) && - IsValidSize(boundariesCount) && - zone.lower > lowers[lowestIDX].value; + // Try to Retrieve Boundary Zone Trend ... + result = + result && + poiDetector.HasBoundaryTrend( + zone, + boundaryZoneTrend, + false // + ); // - isBearish = - isBearish && - IsValidIndex(highestIDX) && - IsValidSize(boundariesCount) && - zone.upper < uppers[highestIDX].value; + // Check and Validate Trend Direction ... + result = + result && + zone.dir == boundaryTrend.dir && + zone.dir == boundaryZoneTrend.dir; // - // Detect Directions of Boundary ... - - // - bool isUppersBullish = uppers[0].value > uppers[1].value; - bool isUppersBearish = uppers[0].value < uppers[1].value; - - // - bool isLowersBullish = lowers[0].value > lowers[1].value; - bool isLowersBearish = lowers[0].value < lowers[1].value; - - // - bool isBoundaryBullish = isUppersBullish || isLowersBullish; - bool isBoundaryBearish = isUppersBearish || isLowersBearish; - - // - bool isBoundaryTrend = isBoundaryBullish || isBoundaryBearish; - if (isBoundaryTrend) - { - // - double fromPrice = - isBoundaryBullish - ? isLowersBullish - ? lowers[1].value - : isUppersBullish - ? uppers[1].value - : EMPTY_VALUE - : isBoundaryBearish - ? isUppersBearish - ? uppers[1].value - : isLowersBearish - ? lowers[1].value - : EMPTY_VALUE - : EMPTY_VALUE; - - // - double toPrice = - isBoundaryBullish - ? isLowersBullish - ? lowers[0].value - : isUppersBullish - ? uppers[0].value - : EMPTY_VALUE - : isBoundaryBearish - ? isUppersBearish - ? uppers[0].value - : isLowersBearish - ? lowers[0].value - : EMPTY_VALUE - : EMPTY_VALUE; - - // - if (NotEmptyZero(fromPrice) && NotEmptyZero(toPrice)) - { - // - boundaryTrend.Init( - zone.symbol, - zone.period, - bar.time, - fromPrice, - zone.from, - toPrice, - zone.to // - ); - - // - // Validate By Boundary Trend ... - if (validateByXFIMABoundaryTrend) - { - // - isBullish = - isBullish && - boundaryTrend.IsValid() && - boundaryTrend.IsBullish(); - - // - isBearish = - isBearish && - boundaryTrend.IsValid() && - boundaryTrend.IsBearish(); - - // - // Summarizing Result ... - result = isBullish || isBearish; - if (!result) - { - zone.Clean(); - } - } - } - } - - // - // Cleanup ... - XClean(uppers); - XClean(lowers); - - // - // Summarize Result ... - result = isBullish || isBearish; + // Reset Flags ... if (!result) { + // zone.Clean(); + result = false; + isBullish = false; + isBearish = false; } } - // - // Draws ... - if (result) - { - // - if (NotEmptyZero(boundaryMin)) - { - // - XPOIDrawConfig iConfig = structureDrawConfig.drawConfig; - iConfig.trendRayLeft = false; - iConfig.trendRayRight = false; - poiDrawer.DrawTrendLine( - "LOWEST_" + ToXString(TimeToSeconds(zone.from)), - boundaryMin, - zone.from, - boundaryMin, - zone.to, - iConfig, - clrYellow // - ); - iConfig.Clean(); - } - - // - if (NotEmptyZero(boundaryMax)) - { - // - XPOIDrawConfig iConfig = structureDrawConfig.drawConfig; - iConfig.trendRayLeft = false; - iConfig.trendRayRight = false; - poiDrawer.DrawTrendLine( - "HIGHEST_" + ToXString(TimeToSeconds(zone.from)), - boundaryMax, - zone.from, - boundaryMax, - zone.to, - iConfig, - clrYellow // - ); - iConfig.Clean(); - } - - // - if (boundaryTrend.IsValid()) - { - // - XPOIDrawConfig iConfig = structureDrawConfig.drawConfig; - iConfig.trendRayLeft = false; - iConfig.trendRayRight = false; - poiDrawer.DrawTrendLine( - boundaryTrend, - iConfig // - ); - iConfig.Clean(); - } - - // - poiDrawer.DrawZone(zone, structureDrawConfig.drawConfig); - poiDrawer.DrawPatternAnalysis(pBarPatterns, structureDrawConfig.barAnalysisDrawConfig); - - // - DebugBreak(); - } - // // Manage Stops ... if (result) @@ -3087,7 +3450,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller iTarget.doRFOnEntry = true; iTarget.target = highRiskTP; iTarget.volumeMultiplier = 0.8; - AddRef(iTarget, targets); + // AddRef(iTarget, targets); // // Cleanup ... @@ -3110,6 +3473,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller pBarPatterns.Clean(); boundaryTrend.Clean(); patternConfig.Clean(); + boundaryZoneTrend.Clean(); // return result; diff --git a/XFIMAEA/Classes/x-saherelm.xfima.parser.class.mq5 b/XFIMAEA/Classes/x-saherelm.xfima.parser.class.mq5 index 15dbc2a4..5d6c06db 100644 --- a/XFIMAEA/Classes/x-saherelm.xfima.parser.class.mq5 +++ b/XFIMAEA/Classes/x-saherelm.xfima.parser.class.mq5 @@ -4002,7 +4002,7 @@ class XCXFIMAHelperParser : XCBase { // // Define Requirements ... - + // datetime toTime = NULL; datetime fromTime = NULL; @@ -5121,7 +5121,7 @@ class XCXFIMAHelperParser : XCBase { // // Define Requirements ... - + // datetime toTime = NULL; datetime fromTime = NULL; @@ -6240,7 +6240,7 @@ class XCXFIMAHelperParser : XCBase { // // Define Requirements ... - + // datetime toTime = NULL; datetime fromTime = NULL; @@ -7359,7 +7359,7 @@ class XCXFIMAHelperParser : XCBase { // // Define Requirements ... - + // datetime toTime = NULL; datetime fromTime = NULL; @@ -7467,6 +7467,158 @@ class XCXFIMAHelperParser : XCBase return result; } + /** + * Retrieve Cycles MA(s) ... + * + * @param scMA: double, reference to holds cycle value ... + * @param mcMA: double, reference to holds cycle value ... + * @param lcMA: double, reference to holds cycle value ... + * @param hcMA: double, reference to holds cycle value ... + * @param barIndex: int, Specified Bar Index ... + */ + void GetCycleMAs( + double &scMA, + double &mcMA, + double &lcMA, + double &hcMA, + int barIndex = 0 // + ) + { + // + // Prepare ... + scMA = EMPTY_VALUE; + mcMA = EMPTY_VALUE; + lcMA = EMPTY_VALUE; + hcMA = EMPTY_VALUE; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + bool has = IsValid(); + if (!has) + { + return; + } + + // + scMA = helper.GetSCMA(barIndex); + mcMA = helper.GetMCMA(barIndex); + lcMA = helper.GetLCMA(barIndex); + hcMA = helper.GetHCMA(barIndex); + } + + /** + * Retrieve Cycles MA State(s) ... + * + * @param scMAState: double, reference to holds cycle value ... + * @param mcMAState: double, reference to holds cycle value ... + * @param lcMAState: double, reference to holds cycle value ... + * @param hcMAState: double, reference to holds cycle value ... + * @param barIndex: int, Specified Bar Index ... + */ + void GetCycleMAStates( + double &scMAState, + double &mcMAState, + double &lcMAState, + double &hcMAState, + int barIndex = 0 // + ) + { + // + // Prepare ... + scMAState = EMPTY_VALUE; + mcMAState = EMPTY_VALUE; + lcMAState = EMPTY_VALUE; + hcMAState = EMPTY_VALUE; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + bool has = IsValid(); + if (!has) + { + return; + } + + // + scMAState = helper.GetSCMAState(barIndex); + mcMAState = helper.GetMCMAState(barIndex); + lcMAState = helper.GetLCMAState(barIndex); + hcMAState = helper.GetHCMAState(barIndex); + } + + /** + * Check Cycle Hind and Long is Bullish or not ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsCycleMABullish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + result = + IsLCMABullish(barIndex) && + IsHCMABullish(barIndex); + + // + return result; + } + + /** + * Check Cycle Hind and Long is Bearish or not ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsCycleMABearish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + result = + IsLCMABearish(barIndex) && + IsHCMABearish(barIndex); + + // + return result; + } + // // Boundary Tools ... // ============================= diff --git a/XFIMAEA/Classes/x-saherelm.xfima.signaller.class.mq5 b/XFIMAEA/Classes/x-saherelm.xfima.signaller.class.mq5 index 9ccc0b4c..3680a698 100644 --- a/XFIMAEA/Classes/x-saherelm.xfima.signaller.class.mq5 +++ b/XFIMAEA/Classes/x-saherelm.xfima.signaller.class.mq5 @@ -298,6 +298,13 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller drawResistance = true; drawIResistance = true; + // + manageLegs = true; + manageZones = true; + manageIZones = true; + manageTrends = false; + manageOrderFlow = true; + // structureConfig.Default(); structureDrawConfig.Default(); @@ -632,6 +639,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller XLeg leg; // Exists Leg ... bool drawLeg; // Draw Leg ... + bool manageLegs; // bool HasLeg() @@ -756,6 +764,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller // bool drawOrderFlow; XBoxZone orderFlow[]; + bool manageOrderFlow; ENUM_X_DIRECTION orderFlowDir; // @@ -943,6 +952,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller XBoxZone resistance; bool drawZones; bool drawSupport; + bool manageZones; bool drawResistance; // @@ -1214,6 +1224,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller XBoxZone iResistance; bool drawIZones; bool drawISupport; + bool manageIZones; bool drawIResistance; // @@ -1385,6 +1396,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller bool drawMCTrend; bool drawLCTrend; bool drawHCTrend; + bool manageTrends; // bool HasTrend() @@ -1552,10 +1564,10 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller // // Signaller Flags ... - bool useSignaller1 = false; + bool useSignaller1 = true; bool useSignaller2 = false; - bool useSignaller3 = true; - bool useSignaller4 = true; + bool useSignaller3 = false; + bool useSignaller4 = false; // // Validator Flags ... @@ -1600,82 +1612,154 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller // Analyse Market Strucutre ... XFIMAMarketStructure marketStructure; + // + // Signal Detection Flags ... + + // + XBoxZone tmpZone; + ENUM_X_DIRECTION tmpDir; + + // + bool signaller1HasSignal = false; + bool signaller2HasSignal = false; + bool signaller3HasSignal = false; + bool signaller4HasSignal = false; + // // Signaller 1 ... - if (!result && useSignaller1) + if (useSignaller1) { // - result = Strategy1HasSignal( + signaller1HasSignal = Strategy1HasSignal( bar, - zone, + tmpZone, targets, - dir // + tmpDir // ); // - if (result) + if (signaller1HasSignal) { - provider = "1"; + // + provider += "1"; + + // + if (!zone.IsValid()) + { + // + dir = tmpDir; + zone = tmpZone; + } } + + // + tmpZone.Clean(); + tmpDir = X_DIRECTION_NONE; } // // Signaller 2 ... - if (!result && useSignaller2) + if (useSignaller2) { // - result = Strategy2HasSignal( + signaller2HasSignal = Strategy2HasSignal( bar, - zone, + tmpZone, targets, - dir // + tmpDir // ); // - if (result) + if (signaller2HasSignal) { - provider = "2"; + // + provider += "2"; + + // + if (!zone.IsValid()) + { + // + dir = tmpDir; + zone = tmpZone; + } } + + // + tmpZone.Clean(); + tmpDir = X_DIRECTION_NONE; } // // Signaller 3 ... - if (!result && useSignaller3) + if (useSignaller3) { // - result = Strategy3HasSignal( + signaller3HasSignal = Strategy3HasSignal( bar, - zone, + tmpZone, targets, - dir // + tmpDir // ); // - if (result) + if (signaller3HasSignal) { - provider = "3"; + // + provider += "3"; + + // + if (!zone.IsValid()) + { + // + dir = tmpDir; + zone = tmpZone; + } } + + // + tmpZone.Clean(); + tmpDir = X_DIRECTION_NONE; } // // Signaller 4 ... - if (!result && useSignaller4) + if (useSignaller4) { // - result = Strategy4HasSignal( + signaller4HasSignal = Strategy4HasSignal( bar, - zone, + tmpZone, targets, - dir // + tmpDir // ); // - if (result) + if (signaller4HasSignal) { - provider = "4"; + // + provider += "4"; + + // + if (!zone.IsValid()) + { + // + dir = tmpDir; + zone = tmpZone; + } } + + // + tmpZone.Clean(); + tmpDir = X_DIRECTION_NONE; } + // + // Summarize Signallers Result ... + result = signaller1HasSignal || + signaller2HasSignal || + signaller3HasSignal || + signaller4HasSignal; + // // Signal Validating ... @@ -1849,6 +1933,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller // // Draw Market Structure ... + // // Analyse Market Structure if Required ... if (!marketStructure.IsValid()) @@ -1898,6 +1983,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller // // Other Drawing Materials ... + Print("Signaller Providers: ", provider); } // @@ -1912,6 +1998,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller // // Cleanup ... + tmpZone.Clean(); iDrawConfig.Clean(); marketStructure.Clean(); @@ -2197,7 +2284,20 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller } /** - * Check Bar Has Signal Based on Strategy 3 ... + * Check Bar Has Signal Based on Strategy 2 ... + * + * Strategy 2: + * =========== + * - Works Based On PBar Patterns Focused on PinBar ... + * - Looking for a Bar Directional Pattern Happens ... + * - Validate Fast Ma Over/Under Slow ... + * - Validate P2Peak/Vale doesnt Under or Over Last (InDirectional) ... + * - Validate P2Bar Has Directional Market Strucuture Zone (OB, FVG, Support/Resistance) ... + * + * Manipulations: + * ================ + * there are Some Flags properties to Change Validations in Strategy ... + * we can use them for Testing Purposes ... * * @param bar: XOHCL, reference to Bar ... * @param zone: XBoxZone, reference to holds affected zone ... @@ -2236,6 +2336,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller // XOHCL pBar; XOHCL p2Bar; + XOHCL p3Bar; bool isBullish = false; bool isBearish = false; @@ -2244,11 +2345,14 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller result = bar.GetPreviousBar(pBar); result = result && pBar.GetPreviousBar(p2Bar); + result = result && + p2Bar.GetPreviousBar(p3Bar); if (!result) { // pBar.Clean(); p2Bar.Clean(); + p3Bar.Clean(); // return result; @@ -2256,37 +2360,59 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller // // Reading pBar Patterns ... - XPatternAnalysis pBarAnalysis; + XPatternAnalysis pBarPatterns; poiDetector.AnalyseBarPatterns( pBar, - pBarAnalysis, + pBarPatterns, structureConfig.barsAnalysisConfig // ); + bool hasSupport = pBarPatterns.IsSupport(); + bool hasResistance = pBarPatterns.IsResistance(); + + // + // Check Boundary Trend ... + XTrend boundaryTrend; + bool hasBoundaryTrend = fimaParser.HasBoundaryTrend(boundaryTrend, pBar.Index()); + bool hasBoundaryBullishTrend = hasBoundaryTrend && boundaryTrend.IsBullish(); + bool hasBoundaryBearishTrend = hasBoundaryTrend && boundaryTrend.IsBearish(); // // Check Bar Patterns ... + + // + // Bars Sequences ... + bool hasBullishSequence = p3Bar.IsBearish() && + pBar.IsBullish(); + bool hasBearishSequence = p3Bar.IsBullish() && + pBar.IsBearish(); + + // + // Bullish ... bool isPBarHasBullishPatterns = (bar.close > pBar.low || bar.open > pBar.low) && ( // - pBarAnalysis.IsPinned(X_DIRECTION_BULLISH) || - pBarAnalysis.IsEngulfed(X_DIRECTION_BULLISH) || - pBarAnalysis.IsMomentum(X_DIRECTION_BULLISH) || - pBarAnalysis.IsPiercing(X_DIRECTION_BULLISH) || - pBarAnalysis.IsSignalKey(X_DIRECTION_BULLISH) + pBarPatterns.IsPinned(X_DIRECTION_BULLISH) || + pBarPatterns.IsEngulfed(X_DIRECTION_BULLISH) || + pBarPatterns.IsMomentum(X_DIRECTION_BULLISH) || + pBarPatterns.IsPiercing(X_DIRECTION_BULLISH) || + pBarPatterns.IsSignalKey(X_DIRECTION_BULLISH) // ); + + // + // Bearish ... bool isPBarHasBearishPatterns = (bar.close < pBar.high || bar.open < pBar.high) && ( // - pBarAnalysis.IsPinned(X_DIRECTION_BEARISH) || - pBarAnalysis.IsEngulfed(X_DIRECTION_BEARISH) || - pBarAnalysis.IsMomentum(X_DIRECTION_BEARISH) || - pBarAnalysis.IsPiercing(X_DIRECTION_BEARISH) || - pBarAnalysis.IsSignalKey(X_DIRECTION_BEARISH) + pBarPatterns.IsPinned(X_DIRECTION_BEARISH) || + pBarPatterns.IsEngulfed(X_DIRECTION_BEARISH) || + pBarPatterns.IsMomentum(X_DIRECTION_BEARISH) || + pBarPatterns.IsPiercing(X_DIRECTION_BEARISH) || + pBarPatterns.IsSignalKey(X_DIRECTION_BEARISH) // ); @@ -2329,17 +2455,34 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller isP2BarPinned && IsXBearish(p2Dir); + // + // Check Based On LC and HC MA State ... + + // + bool isLCMABullish = fimaParser.IsLCMABullish(pBar.Index()); + bool isHCMABullish = fimaParser.IsHCMABullish(pBar.Index()); + bool isCycleMABullish = isLCMABullish && isHCMABullish; + + // + bool isLCMABearish = fimaParser.IsLCMABearish(pBar.Index()); + bool isHCMABearish = fimaParser.IsHCMABearish(pBar.Index()); + bool isCycleMABearish = isLCMABearish && isHCMABearish; + // // Do ... // isBullish = // + hasSupport && isFastOverLast && isValeUnderLast && + isCycleMABullish && + hasBullishSequence && !isP2PeakUnderLast && isPBarCloseOverFast && isP2BarBullishPinned && + hasBoundaryBullishTrend && isPBarHasBullishPatterns // ; @@ -2347,11 +2490,15 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller // isBearish = // + hasResistance && isPeakOverLast && isFastUnderLast && + isCycleMABearish && !isP2ValeOverLast && + hasBearishSequence && isPBarCloseUnderFast && isP2BarBearishPinned && + hasBoundaryBearishTrend && isPBarHasBearishPatterns // ; @@ -2386,61 +2533,19 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller ); // - // Manage Stops ... + // Draws ... if (result) { // - double entry = GetEntry(zone.symbol, zone.dir); - double riskSide = zone.IsBullish() ? zone.lower : zone.upper; - double risk = MathAbs(entry - riskSide); + // XPOIDrawConfig iConfig = structureDrawConfig.drawConfig; + // iConfig.trendRayLeft = false; + // iConfig.trendRayRight = false; + // poiDrawer.DrawTrendLine(boundaryTrend, iConfig); + // poiDrawer.DrawZone(zone, structureDrawConfig.drawConfig); + // iConfig.Clean(); // - // Collecting Affected Zones ... - XBoxZone tmps[]; - XBoxZone zones[]; - XBoxZone actedZones[]; - XBoxZone insideZones[]; - XBoxZone breakedZones[]; - XBoxZone affectedZones[]; - - // - // Support and Resistances ... - poiDetector.CollectZones(bar, tmps); - Copy(tmps, zones, false); - - // - // OBS ... - poiDetector.CollectOBs(bar, tmps); - Copy(tmps, zones, false); - - // - // FVGs ... - poiDetector.CollectFVGs(bar, tmps); - Copy(tmps, zones, false); - - // - ExtractAffectedZones(bar, zones, affectedZones); - - // - // Acteds Zones ... - ExtractActeds(bar, actedZones, affectedZones); - - // - // Inside Zones ... - ExtractInsides(bar, insideZones, affectedZones); - - // - // Breaked Zones ... - ExtractBreakeds(bar, breakedZones, affectedZones); - - // - // Cleanup ... - XClean(tmps); - XClean(zones); - XClean(actedZones); - XClean(insideZones); - XClean(breakedZones); - XClean(affectedZones); + // DebugBreak(); } // @@ -2464,13 +2569,31 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller } pBar.Clean(); p2Bar.Clean(); + p3Bar.Clean(); + pBarPatterns.Clean(); + boundaryTrend.Clean(); // return result; } /** - * Check Bar Has Signal Based on Strategy 4 ... + * Check Bar Has Signal Based on Strategy 3 ... + * + * Strategy 3: + * =========== + * - Works Based On Breaked Support or Resistances ... + * - Looking for a Support or Resistance to Breaked ... + * - Validate Breaker Bar to Change Peak or Vale ... + * - Validate Bar Opposit Side of Breaker Bar's Shadow ... + * - Validate by Checking Market Strucutre to Has Directional Zone + * (Support for Resistance Break / Resistance for Support Break) ... + * - Validate Breaker Bar to Has Directional FVG ... + * + * Manipulations: + * ================ + * there are Some Flags properties to Change Validations in Strategy ... + * we can use them for Testing Purposes ... * * @param bar: XOHCL, reference to Bar ... * @param zone: XBoxZone, reference to holds affected zone ... @@ -2750,17 +2873,17 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller // Draw ... if (result) { - // - XPOIDrawConfig iConfig = structureDrawConfig.drawConfig; - iConfig.trendRayLeft = false; - iConfig.trendRayRight = false; + // // + // XPOIDrawConfig iConfig = structureDrawConfig.drawConfig; + // iConfig.trendRayLeft = false; + // iConfig.trendRayRight = false; - // - poiDrawer.DrawTrendLine(zoneTrend, iConfig); - poiDrawer.DrawTrendLine(zoneToTrend, iConfig); + // // + // poiDrawer.DrawTrendLine(zoneTrend, iConfig); + // poiDrawer.DrawTrendLine(zoneToTrend, iConfig); - // - iConfig.Clean(); + // // + // iConfig.Clean(); } // @@ -3423,7 +3546,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller iTarget.doRFOnEntry = true; iTarget.target = highRiskTP; iTarget.volumeMultiplier = 0.8; - AddRef(iTarget, targets); + // AddRef(iTarget, targets); // // Cleanup ...