From 71fe9abf122da6bfc7835d824fcb02398aa04f15 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Fri, 23 May 2025 05:21:58 +0330 Subject: [PATCH] last ... --- Indicators/x-saherelm.x121.xczone.mq5 | 390 +++++++++++++++++++------- 1 file changed, 286 insertions(+), 104 deletions(-) diff --git a/Indicators/x-saherelm.x121.xczone.mq5 b/Indicators/x-saherelm.x121.xczone.mq5 index 1e04b0e2..1d805194 100644 --- a/Indicators/x-saherelm.x121.xczone.mq5 +++ b/Indicators/x-saherelm.x121.xczone.mq5 @@ -215,18 +215,41 @@ input ENUM_X_MA_METHOD hkSignalBarMethod = X_MA_MODE_EMA; // Hiken Ashi Sign // // Validating ... input group "Validating"; +input bool forceHasSwing = true; // Force Blocks to Have Swing +input bool forceHasFLiquidity = false; // Force Blocks to Have Following Liquidity +input bool forceHasRLiquidity = false; // Force Blocks to Have Reversal Liquidity +input bool validateGapSequence = false; // Validate Block's Gap Sequence +input bool validateBlockEdgeBreakout = false; // Validate Block's Edge Breakout // // Filtering ... input group "Filtering"; +input bool filterBasedOnSar = false; // Filter Based on Sar +input bool filterBasedOnRSI = false; // Filter Based on RSI +input bool filterBasedOnADX = false; // Filter Based on ADX +input bool filterBasedOnTrend = false; // Filter Based on Trend +input bool filterBasedOnDelta = false; // Filter Based on Delta +input bool filterBasedOnVolume = false; // Filter Based on Volume +input bool filterBasedOnSignalBar = false; // Filter Based on Signal Bar +input bool filterBasedOnTrendBars = false; // Filter Based on Trend Bars +input bool filterBasedOnHKSignalBar = false; // Filter Based on Hiken Ashi Signal Bar + +// +// Alert ... +input group "Alerts"; +input string alertPrefix = ""; // Alert Prefix +input bool _logAlerts = true; // Log Alerts +input bool _pushAlerts = false; // Push Alerts +input bool _mailAlerts = false; // Mail Alerts +input bool _terminalAlerts = true; // Terminal Alerts // // Presentation ... input group "Presentation"; input bool showBars = true; // Show Bars -input bool showHKBars = false; // Show Hiken Ashi Bars input bool showSar = false; // Show Sar input bool showTrend = false; // Show Trend +input bool showHKBars = false; // Show Hiken Ashi Bars input bool showTrendBars = false; // Show Trend Bars input bool showSignalBars = false; // Show Signal Bars input bool showHKSignalBars = false; // Show Hiken Ashi Signal Bars @@ -234,12 +257,13 @@ input bool showHKSignalBars = false; // Show Hiken Ashi Signal Bars // // Draws ... input bool drawZones = true; // Draw Detected Zones -input bool drawSignals = true; // Draw Zone's Risk Reward Ratios +input bool drawSignals = true; // Draw Zone's Signal // input int startCalculationForLastBars = 1000; // Calculate Last n Bars -int sarArrowCode = 159; // Sar Arrow Code -int rrZoneLength = 7; // Draw Risk Reward Ratio till n Bars +input int sarArrowCode = 159; // Sar Arrow Code +input int rrZoneLength = 7; // Draw Risk Reward Ratio till n Bars +input int maxSignalR2R = 4; // Max Allowed Signal R2R // // Styling ... @@ -265,31 +289,6 @@ input color fvgBullishColor = clrLime; // FVG Bullish Color input color fvgBearishColor = clrRed; // FVG Bearish Color input ENUM_LINE_STYLE fvgStyle = STYLE_SOLID; // FVG Style -// -// Alert ... -input group "Alerts"; -input string alertPrefix = ""; // Alert Prefix -input bool _logAlerts = false; // Log Alerts -input bool _pushAlerts = false; // Push Alerts -input bool _mailAlerts = false; // Mail Alerts -input bool _terminalAlerts = false; // Terminal Alerts - -// -// -// -bool forceHasSwing = true; // Force Blocks to Have Swing -bool forceHasFLiquidity = false; // Force Blocks to Have Following Liquidity -bool forceHasRLiquidity = false; // Force Blocks to Have Reversal Liquidity -bool validateGapSequence = true; // Validate Block's Gap Sequence -bool validateBlockEdgeBreakout = true; // Validate Block's Edge Breakout -bool filterBasedOnDelta = false; // Filter Based on Delta -bool filterBasedOnVolume = false; // Filter Based on Volume -bool filterBasedOnSignalBar = false; // Filter Based on Signal Bar -bool filterBasedOnHKSignalBar = false; // Filter Based on Hiken Ashi Signal Bar -bool filterBasedOnSar = false; // Filter Based on Sar -bool filterBasedOnTrend = false; // Filter Based on Trend -bool filterBasedOnTrendBars = false; // Filter Based on Trend Bars - // // Buffers ... @@ -1241,8 +1240,11 @@ void CalculateBuffers( * * @param barIndex: Integer ... */ -void FillBuffersZero(int barIndex) +void FillBuffersZero(int bar_index) { + // + sarColorBuffer[bar_index] = hideColorIDX; + trendColorBuffer[bar_index] = hideColorIDX; } /** @@ -1615,43 +1617,20 @@ void DetectTriggerBlock( ); // - if (showTrendBars) - { - // - XOHCL zTrendBar; - int zTrendIDX = iBarShift( + // Detect Trend Bar ... + XOHCL zTrendBar; + int zTrendIDX = iBarShift( + _Symbol, + mTrendPeriod, + zBar.time // + ); + has = + has && + zTrendBar.Init( _Symbol, mTrendPeriod, - zBar.time // + zTrendIDX + 1 // ); - isDone = - has && - zTrendBar.Init( - _Symbol, - mTrendPeriod, - zTrendIDX + 1 // - ); - if (isDone) - { - // - XCOHCLObject *iObj; - isDone = drawer.CreateBar( - zTrendBar, - iObj, - zBar.time // - ); - if (isDone) - { - // - // Style Object ... - - // - // Store Object ... - mObjects.Add(iObj); - } - } - zTrendBar.Clean(); - } // // Define Zone Structure ... @@ -1935,33 +1914,33 @@ void DetectTriggerBlock( { // double iDelta = deltaBuffer[bar_index]; - double iDeltaPrev = deltaBuffer[lastBarIndex]; + double iPDelta = deltaBuffer[lastBarIndex]; // - bool isDeltaUp = iDelta > iDeltaPrev; - bool isDeltaDown = iDelta < iDeltaPrev; + bool isDeltaUp = iDelta > iPDelta; + bool isDeltaDown = iDelta < iPDelta; // double iDeltaSignal = deltaSignalBuffer[bar_index]; - double iDeltaSignalPrev = deltaSignalBuffer[lastBarIndex]; + double iPDeltaSignal = deltaSignalBuffer[lastBarIndex]; // - bool isDeltaSignalUp = iDeltaSignal > iDeltaSignalPrev; - bool isDeltaSignalDown = iDeltaSignal < iDeltaSignalPrev; + bool isDeltaSignalUp = iDeltaSignal > iPDeltaSignal; + bool isDeltaSignalDown = iDeltaSignal < iPDeltaSignal; // bool isDeltaSwitchedToBullish = isDeltaUp && isDeltaSignalUp && iDelta > iDeltaSignal && - iDeltaPrev < iDeltaSignalPrev; + iPDelta < iPDeltaSignal; // bool isDeltaSwitchedToBearish = isDeltaDown && isDeltaSignalDown && iDelta < iDeltaSignal && - iDeltaPrev > iDeltaSignalPrev; + iPDelta > iPDeltaSignal; // has = @@ -1978,33 +1957,33 @@ void DetectTriggerBlock( { // double iBullishVolumeSignal = bullishVolumeSignalBuffer[bar_index]; - double iBullishVolumeSignalPrev = bullishVolumeSignalBuffer[lastBarIndex]; + double iPBullishVolumeSignal = bullishVolumeSignalBuffer[lastBarIndex]; // - bool isBullishVolumeSignalUp = iBullishVolumeSignal > iBullishVolumeSignalPrev; - bool isBullishVolumeSignalDown = iBullishVolumeSignal < iBullishVolumeSignalPrev; + bool isBullishVolumeSignalUp = iBullishVolumeSignal > iPBullishVolumeSignal; + bool isBullishVolumeSignalDown = iBullishVolumeSignal < iPBullishVolumeSignal; // double iBearishVolumeSignal = bearishVolumeSignalBuffer[bar_index]; - double iBearishVolumeSignalPrev = bearishVolumeSignalBuffer[lastBarIndex]; + double iPBearishVolumeSignal = bearishVolumeSignalBuffer[lastBarIndex]; // - bool isBearishVolumeSignalUp = iBearishVolumeSignal > iBearishVolumeSignalPrev; - bool isBearishVolumeSignalDown = iBearishVolumeSignal < iBearishVolumeSignalPrev; + bool isBearishVolumeSignalUp = iBearishVolumeSignal > iPBearishVolumeSignal; + bool isBearishVolumeSignalDown = iBearishVolumeSignal < iPBearishVolumeSignal; // bool isVolumeSwitchdToBullish = isBullishVolumeSignalUp && !isBearishVolumeSignalUp && iBullishVolumeSignal > iBearishVolumeSignal && - iBullishVolumeSignalPrev < iBearishVolumeSignalPrev; + iPBullishVolumeSignal < iPBearishVolumeSignal; // bool isVolumeSwitchdToBearish = isBearishVolumeSignalUp && !isBullishVolumeSignalUp && iBearishVolumeSignal > iBullishVolumeSignal && - iBearishVolumeSignalPrev < iBullishVolumeSignalPrev; + iPBearishVolumeSignal < iPBullishVolumeSignal; // has = @@ -2021,29 +2000,29 @@ void DetectTriggerBlock( { // double iSignalOpen = openSignalBuffer[bar_index]; - double iSignalOpenPrev = openSignalBuffer[lastBarIndex]; + double iPSignalOpen = openSignalBuffer[lastBarIndex]; // double iSignalClose = closeSignalBuffer[bar_index]; - double iSignalClosePrev = closeSignalBuffer[lastBarIndex]; + double iPSignalClose = closeSignalBuffer[lastBarIndex]; // bool isSignalBarBullish = iSignalOpen < iSignalClose; - bool isSignalBarBullishPrev = iSignalOpenPrev < iSignalClosePrev; + bool isPSignalBarBullish = iPSignalOpen < iPSignalClose; // bool isSignalBarBearish = iSignalOpen > iSignalClose; - bool isSignalBarBearishPrev = iSignalOpenPrev > iSignalClosePrev; + bool isPSignalBarBearish = iPSignalOpen > iPSignalClose; // bool isSignalBarSwitchedToBullish = isSignalBarBullish && - !isSignalBarBullishPrev; + !isPSignalBarBullish; // bool isSignalBarSwitchedToBearish = isSignalBarBearish && - !isSignalBarBearishPrev; + !isPSignalBarBearish; // has = @@ -2060,29 +2039,29 @@ void DetectTriggerBlock( { // double iHKSignalOpen = openHKSignalBuffer[bar_index]; - double iHKSignalOpenPrev = openHKSignalBuffer[lastBarIndex]; + double iPHKSignalOpen = openHKSignalBuffer[lastBarIndex]; // double iHKSignalClose = closeHKSignalBuffer[bar_index]; - double iHKSignalClosePrev = closeHKSignalBuffer[lastBarIndex]; + double iPHKSignalClose = closeHKSignalBuffer[lastBarIndex]; // bool isHKSignalBarBullish = iHKSignalOpen < iHKSignalClose; - bool isHKSignalBarBullishPrev = iHKSignalOpenPrev < iHKSignalClosePrev; + bool isPHKSignalBarBullish = iPHKSignalOpen < iPHKSignalClose; // bool isHKSignalBarBearish = iHKSignalOpen > iHKSignalClose; - bool isHKSignalBarBearishPrev = iHKSignalOpenPrev > iHKSignalClosePrev; + bool isPHKSignalBarBearish = iPHKSignalOpen > iPHKSignalClose; // bool isHKSignalBarSwitchedToBullish = isHKSignalBarBullish && - !isHKSignalBarBullishPrev; + !isPHKSignalBarBullish; // bool isHKSignalBarSwitchedToBearish = isHKSignalBarBearish && - !isHKSignalBarBearishPrev; + !isPHKSignalBarBearish; // has = @@ -2099,32 +2078,47 @@ void DetectTriggerBlock( { // double iSarState = sarStateBuffer[bar_index]; - double iSarStatePrev = sarStateBuffer[lastBarIndex]; + double iPSarState = sarStateBuffer[lastBarIndex]; + double iP2SarState = sarStateBuffer[lastBarIndex + 1]; // bool isSarBullish = iSarState > 0; - bool isSarBullishPrev = iSarStatePrev > 0; + bool isPSarBullish = iPSarState > 0; + bool isP2SarBullish = iP2SarState > 0; // bool isSarBearish = iSarState < 0; - bool isSarBearishPrev = iSarStatePrev < 0; + bool isPSarBearish = iPSarState < 0; + bool isP2SarBearish = iP2SarState < 0; // bool isSarSwitchedToBullish = isSarBullish && - !isSarBullishPrev; + !isPSarBullish; // bool isSarSwitchedToBearish = isSarBearish && - !isSarBearishPrev; + !isPSarBearish; + + // + bool isSarPSwitchedToBullish = + isPSarBullish && + !isP2SarBullish; + + // + bool isSarPSwitchedToBearish = + isPSarBearish && + !isP2SarBearish; // has = has && (isBullish - ? isSarSwitchedToBullish - : isSarSwitchedToBearish); + ? (isSarSwitchedToBullish || + isSarPSwitchedToBullish) + : (isSarSwitchedToBearish || + isSarPSwitchedToBearish)); } // @@ -2134,15 +2128,15 @@ void DetectTriggerBlock( { // double iTrendState = trendStateBuffer[bar_index]; - double iTrendStatePrev = trendStateBuffer[lastBarIndex]; + double iPTrendState = trendStateBuffer[lastBarIndex]; // bool isTrendBullish = iTrendState > 0; - bool isTrendBullishPrev = iTrendStatePrev > 0; + bool isPTrendBullish = iPTrendState > 0; // bool isTrendBearish = iTrendState < 0; - bool isTrendBearishPrev = iTrendStatePrev < 0; + bool isPTrendBearish = iPTrendState < 0; // double trends[]; @@ -2175,13 +2169,13 @@ void DetectTriggerBlock( bool isTrendSwitchedToBullish = isTrendUp && isTrendBullish && - !isTrendBullishPrev; + !isPTrendBullish; // bool isTrendSwitchedToBearish = isTrendDown && isTrendBearish && - !isTrendBearishPrev; + !isPTrendBearish; // has = @@ -2191,8 +2185,195 @@ void DetectTriggerBlock( : isTrendSwitchedToBearish); } + // + // TREND Bars ... + if (has && + zTrendBar.IsValid() && + filterBasedOnTrendBars) + { + // + // Calculate Trend Bar's Midd Range ... + double mid = zTrendBar.low + ((zTrendBar.high - zTrendBar.low) / 2); + + // + // Check zBar Close based on MID ... + has = + has && + (isBullish + ? zBar.close < mid + : zBar.close > mid); + + // + // Check Trigger Block ... + has = + has && + (isBullish + ? tb.trigger.lower < zTrendBar.GetDown() + : tb.trigger.upper > zTrendBar.GetUp()); + } + + // + // RSI ... + if (has && + filterBasedOnRSI) + { + // + double rsiTrend = (rsiOBLevel + rsiOSLevel) / 2; + + // + double iRSI = rsiBuffer[bar_index]; + double iPRSI = rsiBuffer[lastBarIndex]; + double iP2RSI = rsiBuffer[lastBarIndex + 1]; + + // + bool isRSICrossedOverOS = + iRSI > rsiOSLevel && + iPRSI <= rsiOSLevel; + + // + bool isRSICrossedUnderOB = + iRSI < rsiOBLevel && + iPRSI >= rsiOBLevel; + + // + bool isPRSICrossedOverOS = + iPRSI > rsiOSLevel && + iP2RSI <= rsiOSLevel; + + // + bool isPRSICrossedUnderOB = + iPRSI < rsiOBLevel && + iP2RSI >= rsiOBLevel; + + // + has = + has && + (isBullish + ? (isRSICrossedOverOS || + isPRSICrossedOverOS) + : (isRSICrossedUnderOB || + isPRSICrossedUnderOB)); + } + + // + // ADX ... + if (has && + filterBasedOnADX) + { + // + // ADX ... + double iADX = adxBuffer[bar_index]; + double iPADX = adxBuffer[lastBarIndex]; + double iP2ADX = adxBuffer[lastBarIndex + 1]; + + // + // ADX +DI ... + double iADXP = adxpBuffer[bar_index]; + double iPADXP = adxpBuffer[lastBarIndex]; + double iP2ADXP = adxpBuffer[lastBarIndex + 1]; + + // + // ADX -DI ... + double iADXN = adxnBuffer[bar_index]; + double iPADXN = adxnBuffer[lastBarIndex]; + double iP2ADXN = adxnBuffer[lastBarIndex + 1]; + + // + // Preparing Conditions ... + + // + bool isADXBullish = iADX > adxThreshold; + bool isADXBearish = iADX < adxThreshold; + + // + bool isPADXBullish = iPADX > adxThreshold; + bool isPADXBearish = iPADX < adxThreshold; + + // + bool isP2ADXBullish = iP2ADX > adxThreshold; + bool isP2ADXBearish = iP2ADX < adxThreshold; + + // + bool isADXSwitchedToBullish = + isADXBullish && + !isPADXBullish; + + // + bool isADXSwitchedToBearish = + isADXBearish && + !isPADXBearish; + + // + bool isPADXSwitchedToBullish = + isPADXBullish && + !isP2ADXBullish; + + // + bool isPADXSwitchedToBearish = + isPADXBearish && + !isP2ADXBearish; + + // + has = + has && + (isBullish + ? (isADXSwitchedToBullish || + isPADXSwitchedToBullish) + : (isADXSwitchedToBearish || + isPADXSwitchedToBearish)); + } + + // + // SIGNAL ... + if (has && + (drawSignals && + maxSignalR2R > 0)) + { + // + double targets[]; + for (int i = 1; i <= maxSignalR2R; i++) + { + // + Add( + (double)i, + targets // + ); + } + has = ToSignal( + tb.trigger, + tb.signal, + targets // + ); + } + // // Handle Draw ... + + // + // Draw Trend Bar ... + if (has && + showTrendBars) + { + // + XCOHCLObject *iObj; + isDone = drawer.CreateBar( + zTrendBar, + iObj, + zBar.time // + ); + if (isDone) + { + // + // Style Object ... + + // + // Store Object ... + mObjects.Add(iObj); + } + } + + // + // Draw Trigger Block ... if (has && drawZones) { @@ -2236,6 +2417,7 @@ void DetectTriggerBlock( tb.Clean(); zBar.Clean(); iBar.Clean(); + zTrendBar.Clean(); } //