diff --git a/Documents/BKP/XFIMA Signals/1.mq5 b/Documents/BKP/XFIMA Signals/1.mq5 new file mode 100644 index 00000000..4dd62939 --- /dev/null +++ b/Documents/BKP/XFIMA Signals/1.mq5 @@ -0,0 +1,1195 @@ + + /** + * Check Bar Has Signal Based on Strategy 3 ... + * + * @param bar: XOHCL, reference to Bar ... + * @param zone: XBoxZone, reference to holds affected zone ... + * @param targets: XTarget, reference to detected Signal's Targets collections ... + * @param dir: ENUM_X_DIRECTION, detected Signal's direction ... + * + * @return ( bool ) + */ + bool Strategy1HasSignal( + XOHCL &bar, + XBoxZone &zone, + XTarget &targets[], + ENUM_X_DIRECTION &dir // + ) + { + // + bool result = false; + + // + // Prepare ... + zone.Clean(); + XClean(targets); + dir = X_DIRECTION_NONE; + + // + // Validate ... + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + // Validator Flags ... + bool validateByATRZone = false; + bool validateByBarPatterns = false; + bool validateRejectedXFIMA = true; + bool validateByAffectedZone = false; + bool validateStartedPullback = true; + bool validateStartedPinnedBar = true; + bool validateByPinBarZoneTrend = false; + bool validateByDirectionalZones = false; + bool validateByDoubleBarPatterns = false; + bool validateByCycleMAsDirection = true; + bool validateByInDirectionalZones = false; + + // + // Define Requirements ... + + // + XOHCL pBar; + XOHCL p2Bar; + XOHCL p3Bar; + XBoxZone atrBox; + XBoxZone mcPVZone; + XBoxZone lcPVZone; + XBoxZone hcPVZone; + double rejecteds[]; + XBoxZone supports[]; + XBoxZone pinBarZone; + XBoxZone pullbackZone; + XBoxZone affectedZone; + XBoxZone liquidityZone; + XBoxZone resistances[]; + XTrend pinBarZoneTrend; + bool isBullish = false; + bool isBearish = false; + XPatternAnalysis iPatterns; + XPatternAnalysis iPPatterns; + XPatternAnalysis pBarPatterns; + XPatternAnalysis p2BarPatterns; + XPatternAnalysis p3BarPatterns; + ENUM_X_BAR_PATTERN doublePatterns[]; + XPatternAnalysisConfig iPatternsConfig; + + // + // Reading Bars ... + result = bar.GetPreviousBar(pBar); + result = result && + pBar.GetPreviousBar(p2Bar); + result = result && + p2Bar.GetPreviousBar(p3Bar); + if (!result) + { + // + pBar.Clean(); + p2Bar.Clean(); + p3Bar.Clean(); + + // + return result; + } + + // + // Reading Bar Patterns ... + iPatternsConfig.Default(); + iPatternsConfig.FullPattern(); + result = + result && + poiDetector.AnalyseBarPatterns( + pBar, + pBarPatterns, + iPatternsConfig // + ); + result = + result && + poiDetector.AnalyseBarPatterns( + p2Bar, + p2BarPatterns, + iPatternsConfig // + ); + result = + result && + poiDetector.AnalyseBarPatterns( + p3Bar, + p3BarPatterns, + iPatternsConfig // + ); + if (!result) + { + // + pBar.Clean(); + p2Bar.Clean(); + p3Bar.Clean(); + pBarPatterns.Clean(); + p2BarPatterns.Clean(); + p3BarPatterns.Clean(); + iPatternsConfig.Clean(); + + // + return result; + } + + // + // Detect Support / Resistance / FVG Touches ... + + + // + // Prepare Zone ... + if (result) + { + // + string type = NULL; + datetime to = NULL; + datetime from = NULL; + double upper = EMPTY_VALUE; + double lower = EMPTY_VALUE; + ENUM_X_DIRECTION zDir = X_DIRECTION_NONE; + + // + zone.at = bar.time; + zone.symbol = bar.symbol; + zone.period = bar.period; + + // + if (pinBarZone.IsValid()) + { + // + upper = + !NotEmptyZero(upper) + ? pinBarZone.upper + : MathMax(upper, pinBarZone.upper); + + // + lower = + !NotEmptyZero(lower) + ? pinBarZone.lower + : MathMin(lower, pinBarZone.lower); + + // + to = bar.time; + from = !IsXValid(from) + ? pinBarZone.from + : MathMin(from, pinBarZone.from); + + // + zDir = pinBarZone.dir; + type = pinBarZone.type; + } + + // + if (pullbackZone.IsValid()) + { + // + upper = + !NotEmptyZero(upper) + ? pullbackZone.upper + : MathMax(upper, pullbackZone.upper); + + // + lower = + !NotEmptyZero(lower) + ? pullbackZone.lower + : MathMin(lower, pullbackZone.lower); + + // + from = !IsXValid(from) + ? pullbackZone.from + : MathMin(from, pullbackZone.from); + + // + if (!HasDirection(zDir)) + { + zDir = pullbackZone.dir; + } + + // + type = + !IsXValid(type) + ? pullbackZone.type + : type + "_" + pullbackZone.type; + } + + // + zone.to = to; + zone.dir = zDir; + zone.from = from; + zone.type = type; + zone.upper = upper; + zone.lower = lower; + + // + result = zone.IsValid(); + if (result) + { + // + int zoneLength = zone.FromIndex() - zone.ToIndex(); + double zoneLL = pBar.FindLowest(zoneLength, MODE_LOW); + double zoneHH = pBar.FindHighest(zoneLength, MODE_HIGH); + + // + if (zone.IsBullish()) + { + zone.lower = MathMin(zone.lower, zoneLL); + } + if (zone.IsBearish()) + { + zone.upper = MathMax(zone.upper, zoneHH); + } + } + + // + // Validating Zone by Shadows ... + if (result) + { + // + XOHCL iBar; + int idx = -1; + bool canContinue = true; + while (canContinue) + { + // + idx = zone.FromIndex() + 1; + canContinue = IsValidIndex(idx); + if (!canContinue) + { + break; + } + + // + iBar.Clean(); + canContinue = pBar.BarAt(idx, iBar); + if (!canContinue) + { + break; + } + + // + canContinue = isBullish + ? iBar.low > zone.lower + : iBar.high < zone.upper; + if (!canContinue) + { + break; + } + + // + zone.from = iBar.time; + } + } + + // + if (!result) + { + // + result = false; + isBullish = false; + isBearish = false; + dir = X_DIRECTION_NONE; + } + } + + // + // Validate Bu Liquidity ... + if (result) + { + // + // Detecting Liquidity ... + XOHCL liqBar; + int idx = zone.FromIndex() + 1; + result = IsValidIndex(idx); + result = result && + bar.BarAt(idx, liqBar); + if (result) + { + // + liquidityZone = zone; + + // + if (isBullish) + { + // + liquidityZone.upper = liquidityZone.lower; + liquidityZone.lower = liqBar.low; + } + else if (isBearish) + { + // + liquidityZone.lower = liquidityZone.upper; + liquidityZone.upper = liqBar.high; + } + } + + // + liqBar.Clean(); + result = liquidityZone.IsValid(); + if (!result) + { + // + zone.Clean(); + result = false; + isBullish = false; + isBearish = false; + dir = X_DIRECTION_NONE; + } + } + + // + // Validate By Affected Zone ... + if (result && validateByAffectedZone) + { + // + // Check pBar is Reject Zone ... + + // // + // // Prepare Zone ... + + // // + // XOHCL tmpBar; + // XBoxZone tmpZone; + + // // + // isBullish = + // isBullish && + // poiDetector.IsSupportTouched( + // p2Bar, + // tmpBar, + // tmpZone, + // 5, + // 21 // + // ); + // if (isBullish) + // { + // affectedZone = tmpZone; + // } + + // // + // isBearish = + // isBearish && + // poiDetector.IsResistanceTouched( + // p2Bar, + // tmpBar, + // tmpZone, + // 5, + // 21 // + // ); + // if (isBearish) + // { + // affectedZone = tmpZone; + // } + + // // + // tmpBar.Clean(); + // tmpZone.Clean(); + + // // + // result = isBullish || isBearish; + } + + // + if (result) + { + // + poiDrawer.DrawZone(zone, structureDrawConfig.drawConfig); + poiDrawer.DrawZone(liquidityZone, structureDrawConfig.drawConfig); + DebugBreak(); + } + + // + zone.Clean(); + result = false; + isBullish = false; + isBearish = false; + dir = X_DIRECTION_NONE; + + // + // Looking For a Pin Bar in P2Bar ... + bool isP2BarIsPinBar = poiDetector.IsPinnedBar( + p2Bar, + dir, + 4, // Shadow Multiplier ... + 4, // Minimum Range Multiplier ... + true // Force Pin Bar Direction ... + ); + if (isP2BarIsPinBar) + { + // + isP2BarIsPinBar = ToBox( + p2Bar, + pinBarZone, + dir, + X_BAR_PATTERN_PINNED // + ); + if (isP2BarIsPinBar) + { + // + pinBarZone.to = bar.time; + + // + // Validate By PinBar Zone Trend ... + if (validateByPinBarZoneTrend) + { + // + isP2BarIsPinBar = poiDetector.HasBoundaryTrend( + pinBarZone, + pinBarZoneTrend, + false // + ); + + // + isP2BarIsPinBar = + isP2BarIsPinBar && + dir == pinBarZoneTrend.dir; + } + + // + // Validate PinBar Zone By XFIMA ... + if (validateRejectedXFIMA) + { + // + int rejectedsCount = poiDetector.IsRejectXFIMA(p2Bar, rejecteds, pinBarZone.dir); + isP2BarIsPinBar = IsValidSize(rejectedsCount); + } + } + } + bool isP2BarPinnedBullish = isP2BarIsPinBar && IsXBullish(dir); + bool isP2BarPinnedBearish = isP2BarIsPinBar && IsXBearish(dir); + + // + // Check P2Bar is Pullback Bar ... + bool isPBarIsPullBack = poiDetector.IsPullbackPattern( + pBar, + pullbackZone, + dir, + 2, // Pull back Length ... + false // Force Break Pullback ... + ); + bool isPBarPullbackBullish = isPBarIsPullBack && pullbackZone.IsBullish(); + bool isPBarPullbackBaerish = isPBarIsPullBack && pullbackZone.IsBearish(); + if (isPBarIsPullBack && validateRejectedXFIMA) + { + // + double iRejecteds[]; + int rejectedCounts = poiDetector.IsRejectXFIMA( + p2Bar, + iRejecteds, + dir, + X_PRICE_CLOSE, + X_PRICE_OPEN, + X_PRICE_OPEN, + X_PRICE_CLOSE, + false // + ); + isPBarIsPullBack = IsValidSize(rejectedCounts); + if (isPBarIsPullBack) + { + // + Copy( + iRejecteds, + rejecteds, + false // + ); + } + } + + // + isBullish = + isP2BarPinnedBullish || + isPBarPullbackBullish; + + // + isBearish = + isP2BarPinnedBearish || + isPBarPullbackBullish; + + // + result = isBullish || isBearish; + + // + // Validate Starter Pinned ... + if (result && validateStartedPinnedBar && !validateStartedPullback) + { + // + isBullish = + isBullish && + isP2BarPinnedBullish; + + // + isBearish = + isBearish && + isP2BarPinnedBearish; + + // + result = isBullish || isBearish; + } + + // + // Validate Starter Pullback ... + if (result && !validateStartedPinnedBar && validateStartedPullback) + { + // + isBullish = + isBullish && + isPBarPullbackBullish; + + // + isBearish = + isBearish && + isPBarPullbackBaerish; + + // + result = isBullish || isBearish; + } + + // + // Validate By ATR Zone ... + if (result && validateByATRZone) + { + // + // Checking ATR Box ... + bool hasATRBox = fimaParser.GetATRBox( + atrBox, + bar.Index() // + ); + bool hasATRBoxBullish = hasATRBox && atrBox.IsBullish(); + bool hasATRBoxBearish = hasATRBox && atrBox.IsBearish(); + + // + isBullish = + isBullish && + hasATRBoxBullish; + + // + isBearish = + isBearish && + hasATRBoxBearish; + + // + // Summarize Result ... + result = isBullish || isBearish; + } + + // + // Detect Directional Candlestic Patterns ... + if (result && validateByBarPatterns) + { + // + // Bullish ... + bool isPBarHasBullishPatterns = + (bar.close > pBar.low || + bar.open > pBar.low) && + ( + // + 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) + // + ); + bool isP2BarHasBullishPatterns = + (bar.close > p2Bar.low || + bar.open > p2Bar.low) && + ( + // + p2BarPatterns.IsPinned(X_DIRECTION_BULLISH) || + p2BarPatterns.IsEngulfed(X_DIRECTION_BULLISH) || + p2BarPatterns.IsMomentum(X_DIRECTION_BULLISH) || + p2BarPatterns.IsPiercing(X_DIRECTION_BULLISH) || + p2BarPatterns.IsSignalKey(X_DIRECTION_BULLISH) + // + ); + bool isP3BarHasBullishPatterns = + (bar.close > p3Bar.low || + bar.open > p3Bar.low) && + ( + // + p3BarPatterns.IsPinned(X_DIRECTION_BULLISH) || + p3BarPatterns.IsEngulfed(X_DIRECTION_BULLISH) || + p3BarPatterns.IsMomentum(X_DIRECTION_BULLISH) || + p3BarPatterns.IsPiercing(X_DIRECTION_BULLISH) || + p3BarPatterns.IsSignalKey(X_DIRECTION_BULLISH) + // + ); + + // + // Bearish ... + bool isPBarHasBearishPatterns = + (bar.close < pBar.high || + bar.open < pBar.high) && + ( + // + 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) + // + ); + bool isP2BarHasBearishPatterns = + (bar.close < p2Bar.high || + bar.open < p2Bar.high) && + ( + // + p2BarPatterns.IsPinned(X_DIRECTION_BEARISH) || + p2BarPatterns.IsEngulfed(X_DIRECTION_BEARISH) || + p2BarPatterns.IsMomentum(X_DIRECTION_BEARISH) || + p2BarPatterns.IsPiercing(X_DIRECTION_BEARISH) || + p2BarPatterns.IsSignalKey(X_DIRECTION_BEARISH) + // + ); + bool isP3BarHasBearishPatterns = + (bar.close < p3Bar.high || + bar.open < p3Bar.high) && + ( + // + p3BarPatterns.IsPinned(X_DIRECTION_BEARISH) || + p3BarPatterns.IsEngulfed(X_DIRECTION_BEARISH) || + p3BarPatterns.IsMomentum(X_DIRECTION_BEARISH) || + p3BarPatterns.IsPiercing(X_DIRECTION_BEARISH) || + p3BarPatterns.IsSignalKey(X_DIRECTION_BEARISH) + // + ); + + // + bool hasBullishPatterns = + isPBarHasBullishPatterns && + (isP2BarHasBullishPatterns || + isP3BarHasBullishPatterns); + + // + bool hasBearishPatterns = + isPBarHasBearishPatterns && + (isP2BarHasBearishPatterns || + isP3BarHasBearishPatterns); + + // + isBullish = + isBullish && + hasBullishPatterns; + + // + isBearish = + isBearish && + hasBearishPatterns; + + // + // Summarize Result ... + result = isBullish || isBearish; + } + + // + // Validating Market Direction ... + if (result && validateByCycleMAsDirection) + { + // + // Bullish ... + bool isLCBullish = fimaParser.IsLCMABullish(pBar.Index()); + bool isHCBullish = fimaParser.IsHCMABullish(pBar.Index()); + bool isLCHigherLow = + (fimaParser.IsLCHigherLow(pBar.Index()) || + fimaParser.IsLCHigherLow(p2Bar.Index()) || + fimaParser.IsLCHigherLow(p3Bar.Index())); + bool isCyclesBullish = + isLCBullish && + isHCBullish && + isLCHigherLow; + + // + // Bearish ... + bool isLCBearish = fimaParser.IsLCMABearish(pBar.Index()); + bool isHCBearish = fimaParser.IsHCMABearish(pBar.Index()); + bool isLCLowerHigh = + (fimaParser.IsLCLowerHigh(pBar.Index()) || + fimaParser.IsLCLowerHigh(p2Bar.Index()) || + fimaParser.IsLCLowerHigh(p3Bar.Index())); + bool isCyclesBearish = + isLCBearish && + isHCBearish && + isLCLowerHigh; + + // + isBullish = + isBullish && + isCyclesBullish; + + // + isBearish = + isBearish && + isCyclesBearish; + + // + // Summarize Result ... + result = isBullish || isBearish; + } + + // + // Validate By Double Bar Patterns ... + if (result && validateByDoubleBarPatterns) + { + // + GetCandlestickPatterns(doublePatterns); + bool hasDoublePatterns = poiDetector.HasDoublePatterns( + pBar, + dir, + iPatterns, + iPPatterns, + doublePatterns, + iPatternsConfig, + 5 // + ); + bool hasBullishDoublePatterns = hasDoublePatterns && IsXBullish(dir); + bool hasBearishDoublePatterns = hasDoublePatterns && IsXBearish(dir); + + // + isBullish = + isBullish && + hasBullishDoublePatterns; + + // + isBearish = + isBearish && + hasBearishDoublePatterns; + + // + // Summarize Result ... + result = isBullish || isBearish; + } + + // + // Validate by Directional Zones ... + if (result && validateByDirectionalZones) + { + // + // Collecting Zones ... + XOHCL tmpBar; + XPivot tmpPivot; + XBoxZone tmpZone; + + // + // Support ... + bool hasSupport = pBarPatterns.IsSupport(); + if (hasSupport) + { + // + hasSupport = pBarPatterns.GetSupport(tmpBar, tmpPivot, tmpZone); + if (hasSupport) + { + AddIfNotExists(tmpZone, supports); + } + } + hasSupport = p2BarPatterns.IsSupport(); + if (hasSupport) + { + // + hasSupport = p2BarPatterns.GetSupport(tmpBar, tmpPivot, tmpZone); + if (hasSupport) + { + AddIfNotExists(tmpZone, supports); + } + } + hasSupport = p3BarPatterns.IsSupport(); + if (hasSupport) + { + // + hasSupport = p3BarPatterns.GetSupport(tmpBar, tmpPivot, tmpZone); + if (hasSupport) + { + AddIfNotExists(tmpZone, supports); + } + } + hasSupport = HasChild(supports); + + // + // Resistance ... + bool hasResistance = pBarPatterns.IsResistance(); + if (hasResistance) + { + // + hasResistance = pBarPatterns.GetResistance(tmpBar, tmpPivot, tmpZone); + if (hasResistance) + { + AddIfNotExists(tmpZone, resistances); + } + } + hasResistance = p2BarPatterns.IsResistance(); + if (hasResistance) + { + // + hasResistance = p2BarPatterns.GetResistance(tmpBar, tmpPivot, tmpZone); + if (hasResistance) + { + AddIfNotExists(tmpZone, resistances); + } + } + hasResistance = p3BarPatterns.IsResistance(); + if (hasResistance) + { + // + hasResistance = p3BarPatterns.GetResistance(tmpBar, tmpPivot, tmpZone); + if (hasResistance) + { + AddIfNotExists(tmpZone, resistances); + } + } + hasResistance = HasChild(resistances); + + // + // Cleanup ... + tmpBar.Clean(); + tmpZone.Clean(); + tmpPivot.Clean(); + + // + // Validating ... + + // + isBullish = + isBullish && + hasSupport; + + // + isBearish = + isBearish && + hasResistance; + + // + // Summarize Result ... + result = isBullish || isBearish; + } + + // + // Validate by InDirectional Zones ... + if (result && validateByInDirectionalZones) + { + // + // Collecting Zones ... + XOHCL tmpBar; + XPivot tmpPivot; + XBoxZone tmpZone; + + // + // Supports ... + bool hasSupport = false; + if (!HasChild(supports)) + { + // + hasSupport = pBarPatterns.IsSupport(); + if (hasSupport) + { + // + hasSupport = pBarPatterns.GetSupport(tmpBar, tmpPivot, tmpZone); + if (hasSupport) + { + AddIfNotExists(tmpZone, supports); + } + } + hasSupport = p2BarPatterns.IsSupport(); + if (hasSupport) + { + // + hasSupport = p2BarPatterns.GetSupport(tmpBar, tmpPivot, tmpZone); + if (hasSupport) + { + AddIfNotExists(tmpZone, supports); + } + } + hasSupport = p3BarPatterns.IsSupport(); + if (hasSupport) + { + // + hasSupport = p3BarPatterns.GetSupport(tmpBar, tmpPivot, tmpZone); + if (hasSupport) + { + AddIfNotExists(tmpZone, supports); + } + } + hasSupport = HasChild(supports); + } + hasSupport = HasChild(supports); + + // + // Resistances ... + bool hasResistance = false; + if (!HasChild(resistances)) + { + // + hasResistance = pBarPatterns.IsResistance(); + if (hasResistance) + { + // + hasResistance = pBarPatterns.GetResistance(tmpBar, tmpPivot, tmpZone); + if (hasResistance) + { + AddIfNotExists(tmpZone, resistances); + } + } + hasResistance = p2BarPatterns.IsResistance(); + if (hasResistance) + { + // + hasResistance = p2BarPatterns.GetResistance(tmpBar, tmpPivot, tmpZone); + if (hasResistance) + { + AddIfNotExists(tmpZone, resistances); + } + } + hasResistance = p3BarPatterns.IsResistance(); + if (hasResistance) + { + // + hasResistance = p3BarPatterns.GetResistance(tmpBar, tmpPivot, tmpZone); + if (hasResistance) + { + AddIfNotExists(tmpZone, resistances); + } + } + hasResistance = HasChild(resistances); + } + hasResistance = HasChild(resistances); + + // + // Cleanup ... + tmpBar.Clean(); + tmpZone.Clean(); + tmpPivot.Clean(); + + // + // Validate by Not InDirectional Exixsts ... + result = + (isBullish && !hasResistance) || + (isBearish && !hasSupport); + + // + // Validate InDirectional Distance by TP ... + if (!result) + { + // + // Calculate Requirements ... + double points = GetPoints(bar.symbol); + double entry = GetEntry(bar.symbol, (isBullish ? X_DIRECTION_BULLISH : X_DIRECTION_BEARISH)); + double slAddition = slAdditionDistance <= 0 ? 0 : slAdditionDistance * points; + double sl = isBullish + ? pinBarZone.lower - slAddition + : pinBarZone.upper + slAddition; + double risk = MathAbs(entry - sl); + double tpReward = defaultSignalR2R * risk; + double tp = isBullish + ? entry + tpReward + : entry - tpReward; + + // + int idx = -1; + if (isBullish) + { + idx = GetYoungest(resistances); + } + else if (isBearish) + { + idx = GetYoungest(supports); + } + result = IsValidIndex(idx); + result = + result && + (isBullish + ? tp < resistances[idx].lower + : tp > supports[idx].upper); + } + + // + // Reset Flags ... + if (!result) + { + // + result = false; + isBullish = false; + isBearish = false; + dir = X_DIRECTION_NONE; + } + } + + // + // Detecting Direction ... + if (result) + { + // + dir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + result = HasDirection(dir); + } + + // + // Prepare Zone ... + if (result) + { + // + // Since Zone Prepared in Above Steps ... + // here we only Validate it ... + result = zone.IsValid(); + } + + // + // Draws ... + if (result) + { + // + XPOIDrawConfig iConfig = structureDrawConfig.drawConfig; + XPatternAnalysisDrawConfig iPatternsConfig = structureDrawConfig.barAnalysisDrawConfig; + iConfig.trendRayLeft = false; + iConfig.trendRayRight = false; + + // + // PinBar Zone ... + if (pinBarZone.IsValid()) + { + poiDrawer.DrawZone(pinBarZone, iConfig); + } + + // + // Pullback Zone ... + if (pullbackZone.IsValid()) + { + poiDrawer.DrawZone(pullbackZone, iConfig); + } + + // + // PinBar Zone Trend ... + if (pinBarZoneTrend.IsValid()) + { + poiDrawer.DrawTrendLine(pinBarZoneTrend, iConfig); + } + + // + // Rejected Values ... + if (HasChild(rejecteds)) + { + // + XTrend iTrend; + bool has = false; + int count = ArraySize(rejecteds); + datetime toTime = zone.to + PeriodSeconds(zone.period); + datetime fromTime = zone.to - PeriodSeconds(zone.period); + for (int i = 0; i < count; i++) + { + // + // Initialize Trend ... + iTrend.Clean(); + has = iTrend.Init( + bar.symbol, + bar.period, + bar.time, + rejecteds[i], + fromTime, + rejecteds[i], + toTime // + ); + if (has) + { + poiDrawer.DrawTrendLine(iTrend, iConfig); + } + } + } + + // + // Draw Zone ... + if (zone.IsValid()) + { + // + iConfig.zonesStyle = STYLE_DASHDOT; + iConfig.bullishColor = clrYellow; + iConfig.bearishColor = clrDarkOrange; + + // + poiDrawer.DrawZone(zone, iConfig); + } + + // + // poiDrawer.DrawZone(mcPVZone, iConfig); + // poiDrawer.DrawZone(lcPVZone, iConfig); + // poiDrawer.DrawZone(hcPVZone, iConfig); + + // + // poiDrawer.DrawZone(pinBarZone, iConfig); + // poiDrawer.DrawZone(pullbackZone, iConfig); + // poiDrawer.DrawTrendLine(pinBarZoneTrend, iConfig); + + // + poiDrawer.DrawPatternAnalysis(pBarPatterns, iPatternsConfig); + poiDrawer.DrawPatternAnalysis(p2BarPatterns, iPatternsConfig); + poiDrawer.DrawPatternAnalysis(p3BarPatterns, iPatternsConfig); + + // + // if (hasATRBox) + // { + // poiDrawer.DrawZone(atrBox, iConfig); + // } + + // + // if (hasDoublePatterns) + // { + // // + // poiDrawer.DrawPatternAnalysis(iPatterns, iPatternsConfig); + // poiDrawer.DrawPatternAnalysis(iPPatterns, iPatternsConfig); + // } + + // + iConfig.Clean(); + iPatternsConfig.Clean(); + + // + DebugBreak(); + + // // + // result = false; + // isBullish = false; + // isBearish = false; + // zone.Clean(); + } + + // + // Prepare Targets ... + if (result) + { + } + + // + // Cleanup ... + if (!result) + { + // + zone.Clean(); + XClean(targets); + dir = X_DIRECTION_NONE; + } + pBar.Clean(); + p2Bar.Clean(); + p3Bar.Clean(); + XClean(supports); + mcPVZone.Clean(); + lcPVZone.Clean(); + hcPVZone.Clean(); + XClean(rejecteds); + iPatterns.Clean(); + pinBarZone.Clean(); + iPPatterns.Clean(); + XClean(resistances); + affectedZone.Clean(); + pullbackZone.Clean(); + pBarPatterns.Clean(); + p2BarPatterns.Clean(); + p3BarPatterns.Clean(); + XClean(doublePatterns); + pinBarZoneTrend.Clean(); + iPatternsConfig.Clean(); + + // + return result; + } diff --git a/Libraries/x-saherelm.x-poi.extensions.lib.mq5 b/Libraries/x-saherelm.x-poi.extensions.lib.mq5 index 17929094..b352d0d8 100644 --- a/Libraries/x-saherelm.x-poi.extensions.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.extensions.lib.mq5 @@ -4064,6 +4064,7 @@ bool ToPivot( * @param prefix: string, Specified Pattern Type ... * @param peakPriceType: ENUM_X_PRICE, Specified Peak Pivot's Applied Price ... * @param valePriceType: ENUM_X_PRICE, Specified Vale Pivot's Applied Price ... + * @param setFromByBreakerBar: bool, Set Box From Time to Breaker Bar ... * * @return ( bool ) */ @@ -4073,7 +4074,8 @@ bool ToBox( ENUM_X_DIRECTION forDir, string prefix = NULL, ENUM_X_PRICE peakPriceType = X_PRICE_HIGH, - ENUM_X_PRICE valePriceType = X_PRICE_LOW // + ENUM_X_PRICE valePriceType = X_PRICE_LOW, + bool setFromByBreakerBar = false // ) { // @@ -4119,7 +4121,8 @@ bool ToBox( forDir, iPattern, peakPriceType, - valePriceType // + valePriceType, + setFromByBreakerBar // ); } // @@ -4177,6 +4180,7 @@ bool ToBox( * @param prefix: string, Specified Pattern Type ... * @param peakPriceType: ENUM_X_PRICE, Specified Peak Pivot's Applied Price ... * @param valePriceType: ENUM_X_PRICE, Specified Vale Pivot's Applied Price ... + * @param setFromByBreakerBar: bool, Set Box From Time to Breaker Bar ... * * @return ( bool ) */ @@ -4186,7 +4190,8 @@ bool ToBox( ENUM_X_DIRECTION patternDir, ENUM_X_BAR_PATTERN pattern, ENUM_X_PRICE peakPriceType = X_PRICE_HIGH, - ENUM_X_PRICE valePriceType = X_PRICE_LOW // + ENUM_X_PRICE valePriceType = X_PRICE_LOW, + bool setFromByBreakerBar = false // ) { // @@ -4245,17 +4250,21 @@ bool ToBox( // case X_BAR_PATTERN_HIGH: { // - tmpBar.Clean(); - has = GetBreakerBar( - bar, - tmpBar, - peakPriceType, - peakPriceType, - X_DIRECTION_BULLISH // - ); - if (has) + if (setFromByBreakerBar) { - iFrom = tmpBar.time; + // + tmpBar.Clean(); + has = GetBreakerBar( + bar, + tmpBar, + peakPriceType, + peakPriceType, + X_DIRECTION_BULLISH // + ); + if (has) + { + iFrom = tmpBar.time; + } } // @@ -4267,17 +4276,21 @@ bool ToBox( // case X_BAR_PATTERN_LOW: { // - tmpBar.Clean(); - has = GetBreakerBar( - bar, - tmpBar, - valePriceType, - valePriceType, - X_DIRECTION_BEARISH // - ); - if (has) + if (setFromByBreakerBar) { - iFrom = tmpBar.time; + // + tmpBar.Clean(); + has = GetBreakerBar( + bar, + tmpBar, + valePriceType, + valePriceType, + X_DIRECTION_BEARISH // + ); + if (has) + { + iFrom = tmpBar.time; + } } // @@ -4289,20 +4302,24 @@ bool ToBox( // case X_BAR_PATTERN_MOMENTUM: { // - tmpBar.Clean(); - ENUM_X_PRICE iPType = isBullish - ? valePriceType - : peakPriceType; - has = GetBreakerBar( - bar, - tmpBar, - iPType, - iPType, - patternDir // - ); - if (has) + if (setFromByBreakerBar) { - iFrom = tmpBar.time; + // + tmpBar.Clean(); + ENUM_X_PRICE iPType = isBullish + ? valePriceType + : peakPriceType; + has = GetBreakerBar( + bar, + tmpBar, + iPType, + iPType, + patternDir // + ); + if (has) + { + iFrom = tmpBar.time; + } } // @@ -4314,20 +4331,24 @@ bool ToBox( // case X_BAR_PATTERN_ENGULFED: { // - tmpBar.Clean(); - ENUM_X_PRICE iPType = isBullish - ? valePriceType - : peakPriceType; - has = GetBreakerBar( - bar, - tmpBar, - iPType, - iPType, - patternDir // - ); - if (has) + if (setFromByBreakerBar) { - iFrom = tmpBar.time; + // + tmpBar.Clean(); + ENUM_X_PRICE iPType = isBullish + ? valePriceType + : peakPriceType; + has = GetBreakerBar( + bar, + tmpBar, + iPType, + iPType, + patternDir // + ); + if (has) + { + iFrom = tmpBar.time; + } } // @@ -4362,20 +4383,24 @@ bool ToBox( // case X_BAR_PATTERN_PINNED: { // - tmpBar.Clean(); - ENUM_X_PRICE iPType = isBullish - ? valePriceType - : peakPriceType; - has = GetBreakerBar( - bar, - tmpBar, - iPType, - iPType, - patternDir // - ); - if (has) + if (setFromByBreakerBar) { - iFrom = tmpBar.time; + // + tmpBar.Clean(); + ENUM_X_PRICE iPType = isBullish + ? valePriceType + : peakPriceType; + has = GetBreakerBar( + bar, + tmpBar, + iPType, + iPType, + patternDir // + ); + if (has) + { + iFrom = tmpBar.time; + } } // @@ -4407,7 +4432,10 @@ bool ToBox( if (has) { // - iFrom = tmpBar.time; + if (setFromByBreakerBar) + { + iFrom = tmpBar.time; + } // int idx = -1; @@ -4421,20 +4449,24 @@ bool ToBox( // case X_BAR_PATTERN_PIERCING: { // - tmpBar.Clean(); - ENUM_X_PRICE iPType = isBullish - ? valePriceType - : peakPriceType; - has = GetBreakerBar( - bar, - tmpBar, - iPType, - iPType, - patternDir // - ); - if (has) + if (setFromByBreakerBar) { - iFrom = tmpBar.time; + // + tmpBar.Clean(); + ENUM_X_PRICE iPType = isBullish + ? valePriceType + : peakPriceType; + has = GetBreakerBar( + bar, + tmpBar, + iPType, + iPType, + patternDir // + ); + if (has) + { + iFrom = tmpBar.time; + } } // @@ -4446,20 +4478,24 @@ bool ToBox( // case X_BAR_PATTERN_RISING: { // - tmpBar.Clean(); - ENUM_X_PRICE iPType = isBullish - ? valePriceType - : peakPriceType; - has = GetBreakerBar( - bar, - tmpBar, - iPType, - iPType, - patternDir // - ); - if (has) + if (setFromByBreakerBar) { - iFrom = tmpBar.time; + // + tmpBar.Clean(); + ENUM_X_PRICE iPType = isBullish + ? valePriceType + : peakPriceType; + has = GetBreakerBar( + bar, + tmpBar, + iPType, + iPType, + patternDir // + ); + if (has) + { + iFrom = tmpBar.time; + } } // @@ -4471,20 +4507,24 @@ bool ToBox( // case X_BAR_PATTERN_FLAG: { // - tmpBar.Clean(); - ENUM_X_PRICE iPType = isBullish - ? valePriceType - : peakPriceType; - has = GetBreakerBar( - bar, - tmpBar, - iPType, - iPType, - patternDir // - ); - if (has) + if (setFromByBreakerBar) { - iFrom = tmpBar.time; + // + tmpBar.Clean(); + ENUM_X_PRICE iPType = isBullish + ? valePriceType + : peakPriceType; + has = GetBreakerBar( + bar, + tmpBar, + iPType, + iPType, + patternDir // + ); + if (has) + { + iFrom = tmpBar.time; + } } // @@ -4498,20 +4538,24 @@ bool ToBox( // case X_BAR_PATTERN_SIGNALKEY: { // - tmpBar.Clean(); - ENUM_X_PRICE iPType = isBullish - ? valePriceType - : peakPriceType; - has = GetBreakerBar( - bar, - tmpBar, - iPType, - iPType, - patternDir // - ); - if (has) + if (setFromByBreakerBar) { - iFrom = tmpBar.time; + // + tmpBar.Clean(); + ENUM_X_PRICE iPType = isBullish + ? valePriceType + : peakPriceType; + has = GetBreakerBar( + bar, + tmpBar, + iPType, + iPType, + patternDir // + ); + if (has) + { + iFrom = tmpBar.time; + } } // @@ -4566,20 +4610,24 @@ bool ToBox( // case X_BAR_PATTERN_SUPPORT: { // - tmpBar.Clean(); - ENUM_X_PRICE iPType = isBullish - ? valePriceType - : peakPriceType; - has = GetBreakerBar( - bar, - tmpBar, - iPType, - iPType, - patternDir // - ); - if (has) + if (setFromByBreakerBar) { - iFrom = tmpBar.time; + // + tmpBar.Clean(); + ENUM_X_PRICE iPType = isBullish + ? valePriceType + : peakPriceType; + has = GetBreakerBar( + bar, + tmpBar, + iPType, + iPType, + patternDir // + ); + if (has) + { + iFrom = tmpBar.time; + } } // @@ -4597,20 +4645,24 @@ bool ToBox( // case X_BAR_PATTERN_RESISTANCE: { // - tmpBar.Clean(); - ENUM_X_PRICE iPType = isBullish - ? valePriceType - : peakPriceType; - has = GetBreakerBar( - bar, - tmpBar, - iPType, - iPType, - patternDir // - ); - if (has) + if (setFromByBreakerBar) { - iFrom = tmpBar.time; + // + tmpBar.Clean(); + ENUM_X_PRICE iPType = isBullish + ? valePriceType + : peakPriceType; + has = GetBreakerBar( + bar, + tmpBar, + iPType, + iPType, + patternDir // + ); + if (has) + { + iFrom = tmpBar.time; + } } // diff --git a/XFIMAEA/Classes/x-saherelm.xfima.signaller.class.mq5 b/XFIMAEA/Classes/x-saherelm.xfima.signaller.class.mq5 index 8da83db4..66c360f8 100644 --- a/XFIMAEA/Classes/x-saherelm.xfima.signaller.class.mq5 +++ b/XFIMAEA/Classes/x-saherelm.xfima.signaller.class.mq5 @@ -1917,17 +1917,8 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller // // Validator Flags ... - bool validateByATRZone = false; - bool validateByBarPatterns = false; - bool validateRejectedXFIMA = true; - bool validateByAffectedZone = false; - bool validateStartedPullback = true; - bool validateStartedPinnedBar = true; - bool validateByPinBarZoneTrend = false; - bool validateByDirectionalZones = false; - bool validateByDoubleBarPatterns = false; - bool validateByCycleMAsDirection = true; - bool validateByInDirectionalZones = false; + bool validateByCyclesTrend = true; + bool validateByMaFastSlowGrows = true; // // Define Requirements ... @@ -1936,25 +1927,11 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller XOHCL pBar; XOHCL p2Bar; XOHCL p3Bar; - XBoxZone atrBox; - XBoxZone mcPVZone; - XBoxZone lcPVZone; - XBoxZone hcPVZone; - double rejecteds[]; - XBoxZone supports[]; - XBoxZone pinBarZone; - XBoxZone pullbackZone; - XBoxZone affectedZone; - XBoxZone resistances[]; - XTrend pinBarZoneTrend; bool isBullish = false; bool isBearish = false; - XPatternAnalysis iPatterns; - XPatternAnalysis iPPatterns; XPatternAnalysis pBarPatterns; XPatternAnalysis p2BarPatterns; XPatternAnalysis p3BarPatterns; - ENUM_X_BAR_PATTERN doublePatterns[]; XPatternAnalysisConfig iPatternsConfig; // @@ -2016,788 +1993,106 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller } // - // Looking For a Pin Bar in P2Bar ... - bool isP2BarIsPinBar = poiDetector.IsPinnedBar( - p2Bar, - dir, - 4, // Shadow Multiplier ... - 4, // Minimum Range Multiplier ... - true // Force Pin Bar Direction ... - ); - if (isP2BarIsPinBar) - { - // - isP2BarIsPinBar = ToBox( - p2Bar, - pinBarZone, - dir, - X_BAR_PATTERN_PINNED // - ); - if (isP2BarIsPinBar) - { - // - pinBarZone.to = bar.time; - - // - // Validate By PinBar Zone Trend ... - if (validateByPinBarZoneTrend) - { - // - isP2BarIsPinBar = poiDetector.HasBoundaryTrend( - pinBarZone, - pinBarZoneTrend, - false // - ); - - // - isP2BarIsPinBar = - isP2BarIsPinBar && - dir == pinBarZoneTrend.dir; - } - - // - // Validate PinBar Zone By XFIMA ... - if (validateRejectedXFIMA) - { - // - int rejectedsCount = poiDetector.IsRejectXFIMA(p2Bar, rejecteds, pinBarZone.dir); - isP2BarIsPinBar = IsValidSize(rejectedsCount); - } - } - } - bool isP2BarPinnedBullish = isP2BarIsPinBar && IsXBullish(dir); - bool isP2BarPinnedBearish = isP2BarIsPinBar && IsXBearish(dir); + // Detect a Cross of MAs ... + bool isFastCrossedOverSlow = fimaParser.IsMAFastCrossedOverSlow(p2Bar.Index()); + bool isFastCrossedUnderSlow = fimaParser.IsMAFastCrossedUnderSlow(p2Bar.Index()); // - // Check P2Bar is Pullback Bar ... - bool isPBarIsPullBack = poiDetector.IsPullbackPattern( - pBar, - pullbackZone, - dir, - 2, // Pull back Length ... - false // Force Break Pullback ... - ); - bool isPBarPullbackBullish = isPBarIsPullBack && pullbackZone.IsBullish(); - bool isPBarPullbackBaerish = isPBarIsPullBack && pullbackZone.IsBearish(); - if (isPBarIsPullBack && validateRejectedXFIMA) - { - // - double iRejecteds[]; - int rejectedCounts = poiDetector.IsRejectXFIMA( - p2Bar, - iRejecteds, - dir, - X_PRICE_CLOSE, - X_PRICE_OPEN, - X_PRICE_OPEN, - X_PRICE_CLOSE, - false // - ); - isPBarIsPullBack = IsValidSize(rejectedCounts); - if (isPBarIsPullBack) - { - // - Copy( - iRejecteds, - rejecteds, - false // - ); - } - } - - // - isBullish = - isP2BarPinnedBullish || - isPBarPullbackBullish; - - // - isBearish = - isP2BarPinnedBearish || - isPBarPullbackBullish; + isBullish = isFastCrossedOverSlow; + isBearish = isFastCrossedUnderSlow; // result = isBullish || isBearish; // - // Validate Starter Pinned ... - if (result && validateStartedPinnedBar && !validateStartedPullback) + // Validate Cross By Over/Under Last ... + if (result && validateByMaFastSlowGrows) { + // + // Bullish ... + bool isFastOverLast = fimaParser.IsMAFastOverLast(pBar.Index()); + bool isSlowOverLast = fimaParser.IsMASlowOverLast(pBar.Index()); + bool isOverLast = isFastOverLast && isSlowOverLast; + + // + // Bearish ... + bool isFastUnderLast = fimaParser.IsMAFastUnderLast(pBar.Index()); + bool isSlowUnderLast = fimaParser.IsMASlowUnderLast(pBar.Index()); + bool isUnderLast = isFastUnderLast && isSlowUnderLast; + // isBullish = isBullish && - isP2BarPinnedBullish; + isOverLast; // isBearish = isBearish && - isP2BarPinnedBearish; + isUnderLast; // result = isBullish || isBearish; } // - // Validate Starter Pullback ... - if (result && !validateStartedPinnedBar && validateStartedPullback) + // Validate By Cycles Trend ... + if (result && validateByCyclesTrend) { + // + // Reading Cycles Trend ... + + // + // Bullish ... + + // + bool isLCMABullish = fimaParser.IsLCMABullish(pBar.Index()); + bool isHCMABullish = fimaParser.IsHCMABullish(pBar.Index()); + + // + bool isLCMAOverLast = fimaParser.IsLCMAOverLast(pBar.Index()); + bool isHCMAOverLast = fimaParser.IsHCMAOverLast(pBar.Index()); + + // + bool isCyclesMABullish = isLCMABullish && isHCMABullish && isLCMAOverLast && isHCMAOverLast; + + // + // Bearish ... + + // + bool isLCMABearish = fimaParser.IsLCMABearish(pBar.Index()); + bool isHCMABearish = fimaParser.IsHCMABearish(pBar.Index()); + + // + bool isLCMAUnderLast = fimaParser.IsLCMAUnderLast(pBar.Index()); + bool isHCMAUnderLast = fimaParser.IsHCMAUnderLast(pBar.Index()); + + // + bool isCyclesMABearish = isLCMABearish && isHCMABearish && isLCMAUnderLast && isHCMAUnderLast; + // isBullish = isBullish && - isPBarPullbackBullish; + isCyclesMABullish; // isBearish = isBearish && - isPBarPullbackBaerish; + isCyclesMABearish; // result = isBullish || isBearish; } // - // Prepare Zone ... if (result) { // - string type = NULL; - datetime to = NULL; - datetime from = NULL; - double upper = EMPTY_VALUE; - double lower = EMPTY_VALUE; - ENUM_X_DIRECTION zDir = X_DIRECTION_NONE; + DebugBreak(); // - zone.at = bar.time; - zone.symbol = bar.symbol; - zone.period = bar.period; - - // - if (pinBarZone.IsValid()) - { - // - upper = - !NotEmptyZero(upper) - ? pinBarZone.upper - : MathMax(upper, pinBarZone.upper); - - // - lower = - !NotEmptyZero(lower) - ? pinBarZone.lower - : MathMin(lower, pinBarZone.lower); - - // - to = bar.time; - from = !IsXValid(from) - ? pinBarZone.from - : MathMin(from, pinBarZone.from); - - // - zDir = pinBarZone.dir; - type = pinBarZone.type; - } - - // - if (pullbackZone.IsValid()) - { - // - upper = - !NotEmptyZero(upper) - ? pullbackZone.upper - : MathMax(upper, pullbackZone.upper); - - // - lower = - !NotEmptyZero(lower) - ? pullbackZone.lower - : MathMin(lower, pullbackZone.lower); - - // - from = !IsXValid(from) - ? pullbackZone.from - : MathMin(from, pullbackZone.from); - - // - if (!HasDirection(zDir)) - { - zDir = pullbackZone.dir; - } - - // - type = - !IsXValid(type) - ? pullbackZone.type - : type + "_" + pullbackZone.type; - } - - // - zone.to = to; - zone.dir = zDir; - zone.from = from; - zone.type = type; - zone.upper = upper; - zone.lower = lower; - - // - result = zone.IsValid(); - if (result) - { - // - int zoneLength = zone.FromIndex() - zone.ToIndex(); - double zoneLL = pBar.FindLowest(zoneLength, MODE_LOW); - double zoneHH = pBar.FindHighest(zoneLength, MODE_HIGH); - - // - if (zone.IsBullish()) - { - zone.lower = MathMin(zone.lower, zoneLL); - } - if (zone.IsBearish()) - { - zone.upper = MathMax(zone.upper, zoneHH); - } - } - - // - if (!result) - { - // - result = false; - isBullish = false; - isBearish = false; - dir = X_DIRECTION_NONE; - } - - // - if (result) - { - // - poiDrawer.DrawZone(zone, structureDrawConfig.drawConfig); - DebugBreak(); - } - - // - zone.Clean(); result = false; isBullish = false; isBearish = false; - dir = X_DIRECTION_NONE; - } - - // - // Validate By Affected Zone ... - if (result && validateByAffectedZone) - { - // - // Prepare Zone ... - - // - XOHCL tmpBar; - XBoxZone tmpZone; - - // - isBullish = - isBullish && - poiDetector.IsSupportTouched( - p2Bar, - tmpBar, - tmpZone, - 5, - 21 // - ); - if (isBullish) - { - affectedZone = tmpZone; - } - - // - isBearish = - isBearish && - poiDetector.IsResistanceTouched( - p2Bar, - tmpBar, - tmpZone, - 5, - 21 // - ); - if (isBearish) - { - affectedZone = tmpZone; - } - - // - tmpBar.Clean(); - tmpZone.Clean(); - - // - result = isBullish || isBearish; - } - - // - // Validate By ATR Zone ... - if (result && validateByATRZone) - { - // - // Checking ATR Box ... - bool hasATRBox = fimaParser.GetATRBox( - atrBox, - bar.Index() // - ); - bool hasATRBoxBullish = hasATRBox && atrBox.IsBullish(); - bool hasATRBoxBearish = hasATRBox && atrBox.IsBearish(); - - // - isBullish = - isBullish && - hasATRBoxBullish; - - // - isBearish = - isBearish && - hasATRBoxBearish; - - // - // Summarize Result ... - result = isBullish || isBearish; - } - - // - // Detect Directional Candlestic Patterns ... - if (result && validateByBarPatterns) - { - // - // Bullish ... - bool isPBarHasBullishPatterns = - (bar.close > pBar.low || - bar.open > pBar.low) && - ( - // - 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) - // - ); - bool isP2BarHasBullishPatterns = - (bar.close > p2Bar.low || - bar.open > p2Bar.low) && - ( - // - p2BarPatterns.IsPinned(X_DIRECTION_BULLISH) || - p2BarPatterns.IsEngulfed(X_DIRECTION_BULLISH) || - p2BarPatterns.IsMomentum(X_DIRECTION_BULLISH) || - p2BarPatterns.IsPiercing(X_DIRECTION_BULLISH) || - p2BarPatterns.IsSignalKey(X_DIRECTION_BULLISH) - // - ); - bool isP3BarHasBullishPatterns = - (bar.close > p3Bar.low || - bar.open > p3Bar.low) && - ( - // - p3BarPatterns.IsPinned(X_DIRECTION_BULLISH) || - p3BarPatterns.IsEngulfed(X_DIRECTION_BULLISH) || - p3BarPatterns.IsMomentum(X_DIRECTION_BULLISH) || - p3BarPatterns.IsPiercing(X_DIRECTION_BULLISH) || - p3BarPatterns.IsSignalKey(X_DIRECTION_BULLISH) - // - ); - - // - // Bearish ... - bool isPBarHasBearishPatterns = - (bar.close < pBar.high || - bar.open < pBar.high) && - ( - // - 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) - // - ); - bool isP2BarHasBearishPatterns = - (bar.close < p2Bar.high || - bar.open < p2Bar.high) && - ( - // - p2BarPatterns.IsPinned(X_DIRECTION_BEARISH) || - p2BarPatterns.IsEngulfed(X_DIRECTION_BEARISH) || - p2BarPatterns.IsMomentum(X_DIRECTION_BEARISH) || - p2BarPatterns.IsPiercing(X_DIRECTION_BEARISH) || - p2BarPatterns.IsSignalKey(X_DIRECTION_BEARISH) - // - ); - bool isP3BarHasBearishPatterns = - (bar.close < p3Bar.high || - bar.open < p3Bar.high) && - ( - // - p3BarPatterns.IsPinned(X_DIRECTION_BEARISH) || - p3BarPatterns.IsEngulfed(X_DIRECTION_BEARISH) || - p3BarPatterns.IsMomentum(X_DIRECTION_BEARISH) || - p3BarPatterns.IsPiercing(X_DIRECTION_BEARISH) || - p3BarPatterns.IsSignalKey(X_DIRECTION_BEARISH) - // - ); - - // - bool hasBullishPatterns = - isPBarHasBullishPatterns && - (isP2BarHasBullishPatterns || - isP3BarHasBullishPatterns); - - // - bool hasBearishPatterns = - isPBarHasBearishPatterns && - (isP2BarHasBearishPatterns || - isP3BarHasBearishPatterns); - - // - isBullish = - isBullish && - hasBullishPatterns; - - // - isBearish = - isBearish && - hasBearishPatterns; - - // - // Summarize Result ... - result = isBullish || isBearish; - } - - // - // Validating Market Direction ... - if (result && validateByCycleMAsDirection) - { - // - // Bullish ... - bool isLCBullish = fimaParser.IsLCMABullish(pBar.Index()); - bool isHCBullish = fimaParser.IsHCMABullish(pBar.Index()); - bool isLCHigherLow = - (fimaParser.IsLCHigherLow(pBar.Index()) || - fimaParser.IsLCHigherLow(p2Bar.Index()) || - fimaParser.IsLCHigherLow(p3Bar.Index())); - bool isCyclesBullish = - isLCBullish && - isHCBullish && - isLCHigherLow; - - // - // Bearish ... - bool isLCBearish = fimaParser.IsLCMABearish(pBar.Index()); - bool isHCBearish = fimaParser.IsHCMABearish(pBar.Index()); - bool isLCLowerHigh = - (fimaParser.IsLCLowerHigh(pBar.Index()) || - fimaParser.IsLCLowerHigh(p2Bar.Index()) || - fimaParser.IsLCLowerHigh(p3Bar.Index())); - bool isCyclesBearish = - isLCBearish && - isHCBearish && - isLCLowerHigh; - - // - isBullish = - isBullish && - isCyclesBullish; - - // - isBearish = - isBearish && - isCyclesBearish; - - // - // Summarize Result ... - result = isBullish || isBearish; - } - - // - // Validate By Double Bar Patterns ... - if (result && validateByDoubleBarPatterns) - { - // - GetCandlestickPatterns(doublePatterns); - bool hasDoublePatterns = poiDetector.HasDoublePatterns( - pBar, - dir, - iPatterns, - iPPatterns, - doublePatterns, - iPatternsConfig, - 5 // - ); - bool hasBullishDoublePatterns = hasDoublePatterns && IsXBullish(dir); - bool hasBearishDoublePatterns = hasDoublePatterns && IsXBearish(dir); - - // - isBullish = - isBullish && - hasBullishDoublePatterns; - - // - isBearish = - isBearish && - hasBearishDoublePatterns; - - // - // Summarize Result ... - result = isBullish || isBearish; - } - - // - // Validate by Directional Zones ... - if (result && validateByDirectionalZones) - { - // - // Collecting Zones ... - XOHCL tmpBar; - XPivot tmpPivot; - XBoxZone tmpZone; - - // - // Support ... - bool hasSupport = pBarPatterns.IsSupport(); - if (hasSupport) - { - // - hasSupport = pBarPatterns.GetSupport(tmpBar, tmpPivot, tmpZone); - if (hasSupport) - { - AddIfNotExists(tmpZone, supports); - } - } - hasSupport = p2BarPatterns.IsSupport(); - if (hasSupport) - { - // - hasSupport = p2BarPatterns.GetSupport(tmpBar, tmpPivot, tmpZone); - if (hasSupport) - { - AddIfNotExists(tmpZone, supports); - } - } - hasSupport = p3BarPatterns.IsSupport(); - if (hasSupport) - { - // - hasSupport = p3BarPatterns.GetSupport(tmpBar, tmpPivot, tmpZone); - if (hasSupport) - { - AddIfNotExists(tmpZone, supports); - } - } - hasSupport = HasChild(supports); - - // - // Resistance ... - bool hasResistance = pBarPatterns.IsResistance(); - if (hasResistance) - { - // - hasResistance = pBarPatterns.GetResistance(tmpBar, tmpPivot, tmpZone); - if (hasResistance) - { - AddIfNotExists(tmpZone, resistances); - } - } - hasResistance = p2BarPatterns.IsResistance(); - if (hasResistance) - { - // - hasResistance = p2BarPatterns.GetResistance(tmpBar, tmpPivot, tmpZone); - if (hasResistance) - { - AddIfNotExists(tmpZone, resistances); - } - } - hasResistance = p3BarPatterns.IsResistance(); - if (hasResistance) - { - // - hasResistance = p3BarPatterns.GetResistance(tmpBar, tmpPivot, tmpZone); - if (hasResistance) - { - AddIfNotExists(tmpZone, resistances); - } - } - hasResistance = HasChild(resistances); - - // - // Cleanup ... - tmpBar.Clean(); - tmpZone.Clean(); - tmpPivot.Clean(); - - // - // Validating ... - - // - isBullish = - isBullish && - hasSupport; - - // - isBearish = - isBearish && - hasResistance; - - // - // Summarize Result ... - result = isBullish || isBearish; - } - - // - // Validate by InDirectional Zones ... - if (result && validateByInDirectionalZones) - { - // - // Collecting Zones ... - XOHCL tmpBar; - XPivot tmpPivot; - XBoxZone tmpZone; - - // - // Supports ... - bool hasSupport = false; - if (!HasChild(supports)) - { - // - hasSupport = pBarPatterns.IsSupport(); - if (hasSupport) - { - // - hasSupport = pBarPatterns.GetSupport(tmpBar, tmpPivot, tmpZone); - if (hasSupport) - { - AddIfNotExists(tmpZone, supports); - } - } - hasSupport = p2BarPatterns.IsSupport(); - if (hasSupport) - { - // - hasSupport = p2BarPatterns.GetSupport(tmpBar, tmpPivot, tmpZone); - if (hasSupport) - { - AddIfNotExists(tmpZone, supports); - } - } - hasSupport = p3BarPatterns.IsSupport(); - if (hasSupport) - { - // - hasSupport = p3BarPatterns.GetSupport(tmpBar, tmpPivot, tmpZone); - if (hasSupport) - { - AddIfNotExists(tmpZone, supports); - } - } - hasSupport = HasChild(supports); - } - hasSupport = HasChild(supports); - - // - // Resistances ... - bool hasResistance = false; - if (!HasChild(resistances)) - { - // - hasResistance = pBarPatterns.IsResistance(); - if (hasResistance) - { - // - hasResistance = pBarPatterns.GetResistance(tmpBar, tmpPivot, tmpZone); - if (hasResistance) - { - AddIfNotExists(tmpZone, resistances); - } - } - hasResistance = p2BarPatterns.IsResistance(); - if (hasResistance) - { - // - hasResistance = p2BarPatterns.GetResistance(tmpBar, tmpPivot, tmpZone); - if (hasResistance) - { - AddIfNotExists(tmpZone, resistances); - } - } - hasResistance = p3BarPatterns.IsResistance(); - if (hasResistance) - { - // - hasResistance = p3BarPatterns.GetResistance(tmpBar, tmpPivot, tmpZone); - if (hasResistance) - { - AddIfNotExists(tmpZone, resistances); - } - } - hasResistance = HasChild(resistances); - } - hasResistance = HasChild(resistances); - - // - // Cleanup ... - tmpBar.Clean(); - tmpZone.Clean(); - tmpPivot.Clean(); - - // - // Validate by Not InDirectional Exixsts ... - result = - (isBullish && !hasResistance) || - (isBearish && !hasSupport); - - // - // Validate InDirectional Distance by TP ... - if (!result) - { - // - // Calculate Requirements ... - double points = GetPoints(bar.symbol); - double entry = GetEntry(bar.symbol, (isBullish ? X_DIRECTION_BULLISH : X_DIRECTION_BEARISH)); - double slAddition = slAdditionDistance <= 0 ? 0 : slAdditionDistance * points; - double sl = isBullish - ? pinBarZone.lower - slAddition - : pinBarZone.upper + slAddition; - double risk = MathAbs(entry - sl); - double tpReward = defaultSignalR2R * risk; - double tp = isBullish - ? entry + tpReward - : entry - tpReward; - - // - int idx = -1; - if (isBullish) - { - idx = GetYoungest(resistances); - } - else if (isBearish) - { - idx = GetYoungest(supports); - } - result = IsValidIndex(idx); - result = - result && - (isBullish - ? tp < resistances[idx].lower - : tp > supports[idx].upper); - } - - // - // Reset Flags ... - if (!result) - { - // - result = false; - isBullish = false; - isBearish = false; - dir = X_DIRECTION_NONE; - } } // @@ -2834,58 +2129,6 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller iConfig.trendRayLeft = false; iConfig.trendRayRight = false; - // - // PinBar Zone ... - if (pinBarZone.IsValid()) - { - poiDrawer.DrawZone(pinBarZone, iConfig); - } - - // - // Pullback Zone ... - if (pullbackZone.IsValid()) - { - poiDrawer.DrawZone(pullbackZone, iConfig); - } - - // - // PinBar Zone Trend ... - if (pinBarZoneTrend.IsValid()) - { - poiDrawer.DrawTrendLine(pinBarZoneTrend, iConfig); - } - - // - // Rejected Values ... - if (HasChild(rejecteds)) - { - // - XTrend iTrend; - bool has = false; - int count = ArraySize(rejecteds); - datetime toTime = zone.to + PeriodSeconds(zone.period); - datetime fromTime = zone.to - PeriodSeconds(zone.period); - for (int i = 0; i < count; i++) - { - // - // Initialize Trend ... - iTrend.Clean(); - has = iTrend.Init( - bar.symbol, - bar.period, - bar.time, - rejecteds[i], - fromTime, - rejecteds[i], - toTime // - ); - if (has) - { - poiDrawer.DrawTrendLine(iTrend, iConfig); - } - } - } - // // Draw Zone ... if (zone.IsValid()) @@ -2960,22 +2203,9 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller pBar.Clean(); p2Bar.Clean(); p3Bar.Clean(); - XClean(supports); - mcPVZone.Clean(); - lcPVZone.Clean(); - hcPVZone.Clean(); - XClean(rejecteds); - iPatterns.Clean(); - pinBarZone.Clean(); - iPPatterns.Clean(); - XClean(resistances); - affectedZone.Clean(); - pullbackZone.Clean(); pBarPatterns.Clean(); p2BarPatterns.Clean(); p3BarPatterns.Clean(); - XClean(doublePatterns); - pinBarZoneTrend.Clean(); iPatternsConfig.Clean(); //