From 52856ff815456912fcc9a4d1a725a09fd1e7d072 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Tue, 4 Mar 2025 16:18:51 +0330 Subject: [PATCH] last ... --- Libraries/x-saherelm.x-poi.extensions.lib.mq5 | 949 +++--------------- .../Signals/x-121.smc.xwz.signal.class.mq5 | 215 +++- .../Signals/x-121.smc.xwz.signal.lib.mq5 | 432 +++++++- .../Strategy/x-121.smc.strategy.class.mq5 | 38 +- 4 files changed, 753 insertions(+), 881 deletions(-) diff --git a/Libraries/x-saherelm.x-poi.extensions.lib.mq5 b/Libraries/x-saherelm.x-poi.extensions.lib.mq5 index 757bb9d7..2f39a149 100644 --- a/Libraries/x-saherelm.x-poi.extensions.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.extensions.lib.mq5 @@ -2897,815 +2897,140 @@ int FilterZones( // // -// /** -// * Check Trading Conditions based on Specified Box ... -// * -// * @param box: XBoxZone instance Reference, specified Box for Checking Conditions ... -// * @param appliedBox: XBoxZone instance Reference, hold's Selected Box inside Parent which trading conditions happens on it ... -// * @param swingBar: XOHCL instance Reference, holds Swing Bar if Exists ... -// * @param breakerBar: XOHCL instance Reference, holds Breaker Bar if Exists ... -// * @param rejectionBar: XOHCL instance Reference, holds Rejection Bar if Exists ... -// * @param momentumBar: XOHCL instance Reference, holds Momentum Bar if Exists ... -// * @param state: XPOIState instance Reference, provides requirement zone's for check Conditions ... -// * @param barIndex: int, Specified Bar Index ... -// * @param forPeriod: ENUM_TIMEFRAMES member, Specified Conditions Checking Period ... -// * -// * @return ( bool ) -// */ -// bool CheckBoxForTradeConditions( -// XBoxZone &box, -// XBoxZone &appliedBox, -// XOHCL &swingBar, -// XOHCL &breakerBar, -// XOHCL &rejectionBar, -// XOHCL &momentumBar, -// XPOIState &state, -// int barIndex = 0, -// ENUM_TIMEFRAMES forPeriod = NULL // -// ) -// { -// // -// bool result = false; - -// // -// swingBar.Clean(); -// appliedBox.Clean(); -// breakerBar.Clean(); -// momentumBar.Clean(); -// rejectionBar.Clean(); - -// // -// if (barIndex < 0) -// { -// barIndex = 0; -// } - -// // -// result = box.IsValid() && -// state.IsValid() && -// state.HasChild(); -// if (!result) -// { -// return result; -// } - -// // -// if (!IsValid(forPeriod)) -// { -// forPeriod = box.period; -// } - -// // -// string symbol = box.symbol; -// datetime cTime = iTime( -// symbol, -// forPeriod, -// barIndex // -// ); - -// // -// ENUM_X_DIRECTION forDir = box.dir; -// result = HasDirection(forDir); -// if (!result) -// { -// return result; -// } - -// // -// bool isBullish = IsBullish(forDir); - -// // -// int supportsCount = 0; -// bool hasSupports = false; -// XCSupportZone *supports[]; - -// // -// int resistancesCount = 0; -// bool hasResistances = false; -// XCResistanceZone *resistances[]; - -// // -// XBoxZone supResBoxes[]; -// int supresBoxesCount = 0; -// bool hasSupResBoxes = false; - -// // -// int count = 0; -// bool has = false; - -// // -// has = state.HasSupportZones(); -// if (has) -// { -// // -// count = state.CountSupportZones(); -// for (int i = 0; i < count; i++) -// { -// // -// XCSupportZone *iZone = state.supportZones[i]; - -// // -// iZone.To(cTime); - -// // -// XBoxZone iBox; -// bool hasBox = ToBox( -// iBox, -// iZone // -// ); -// if (!hasBox) -// { -// // -// iBox.Clean(); -// continue; -// } - -// // -// // Check From ... -// bool isInside = IsBoxInside( -// iBox, -// box // -// ); -// if (!isInside) -// { -// // -// iBox.Clean(); -// continue; -// } - -// // -// Add( -// iZone, -// supports // -// ); - -// // -// AddRef( -// iBox, -// supResBoxes // -// ); - -// // -// iBox.Clean(); -// } - -// // -// supportsCount = ArraySize(supports); -// hasSupports = IsValidSize(supportsCount); - -// // -// supresBoxesCount = ArraySize(supResBoxes); -// hasSupResBoxes = IsValidSize(supresBoxesCount); -// } - -// // -// has = state.HasResistanceZones(); -// if (has) -// { -// // -// count = state.CountResistanceZones(); -// for (int i = 0; i < count; i++) -// { -// // -// XCResistanceZone *iZone = state.resistanceZones[i]; - -// // -// iZone.To(cTime); - -// // -// XBoxZone iBox; -// bool hasBox = ToBox( -// iBox, -// iZone // -// ); -// if (!hasBox) -// { -// // -// iBox.Clean(); -// continue; -// } - -// // -// // Check From ... -// bool isInside = IsBoxInside( -// iBox, -// box // -// ); -// if (!isInside) -// { -// // -// iBox.Clean(); -// continue; -// } - -// // -// Add( -// iZone, -// resistances // -// ); - -// // -// AddRef( -// iBox, -// supResBoxes // -// ); - -// // -// iBox.Clean(); -// } - -// // -// resistancesCount = ArraySize(resistances); -// hasResistances = IsValidSize(resistancesCount); - -// // -// supresBoxesCount = ArraySize(supResBoxes); -// hasSupResBoxes = IsValidSize(supresBoxesCount); -// } - -// // -// result = hasSupResBoxes; -// if (!result) -// { -// // -// Clean(supports); -// Clean(resistances); -// Clean(supResBoxes); - -// // -// return result; -// } - -// // -// // Detect Bars ... - -// // -// XOHCL zBar; -// result = zBar.Init( -// symbol, -// forPeriod, -// barIndex // -// ); -// if (!result) -// { -// // -// zBar.Clean(); -// Clean(supports); -// Clean(resistances); -// Clean(supResBoxes); - -// // -// return result; -// } - -// // -// XOHCL cBar; -// result = zBar.GetPreviousBar(cBar); -// if (!result) -// { -// // -// zBar.Clean(); -// cBar.Clean(); -// Clean(supports); -// Clean(resistances); -// Clean(supResBoxes); - -// // -// return result; -// } - -// // -// XOHCL pBar; -// result = cBar.GetPreviousBar(pBar); -// if (!result) -// { -// // -// zBar.Clean(); -// cBar.Clean(); -// pBar.Clean(); -// Clean(supports); -// Clean(resistances); -// Clean(supResBoxes); - -// // -// return result; -// } - -// // -// XOHCL ppBar; -// result = pBar.GetPreviousBar(ppBar); -// if (!result) -// { -// // -// zBar.Clean(); -// cBar.Clean(); -// pBar.Clean(); -// ppBar.Clean(); -// Clean(supports); -// Clean(resistances); -// Clean(supResBoxes); - -// // -// return result; -// } -// // -// // Check Conditions ... - -// // -// // Detect Start Senario ... - -// // -// double fiboPressureLevel = GetFiboLevelValue(X_FIBO_LEVEL_382); - -// // -// double fiboUpDown = GetFibonacciLevel( -// pBar.high, -// pBar.low, -// X_FIBO_LEVEL_382, -// X_DIRECTION_BEARISH // -// ); -// double fiboDownUp = GetFibonacciLevel( -// pBar.high, -// pBar.low, -// X_FIBO_LEVEL_382, -// X_DIRECTION_BULLISH // -// ); - -// // -// bool hasFiboToUpPressure = -// fiboDownUp > 0 && -// fiboDownUp <= pBar.GetDown(); -// bool hasFiboToDownPressure = -// fiboUpDown > 0 && -// fiboUpDown >= pBar.GetUp(); - -// // -// int selectedBoxIDX = -1; -// for (int j = 0; j < supresBoxesCount; j++) -// { -// // -// double appliedPrice = -// isBullish -// ? supResBoxes[j].lower -// : supResBoxes[j].upper; - -// // -// // Check Swing Low ... -// bool isSwingLow = -// // -// pBar.low < ppBar.low && -// pBar.low < cBar.low && -// zBar.open > pBar.low && -// // -// appliedPrice > pBar.low && -// appliedPrice < pBar.GetDown() -// // -// ; -// bool isPressuredSwingLow = -// isSwingLow && -// hasFiboToUpPressure; -// bool isPressuredStrongSwingLow = -// pBar.IsBullish() && -// isPressuredSwingLow; - -// // -// bool isSwingHigh = -// // -// pBar.high > ppBar.high && -// pBar.high > cBar.high && -// zBar.open < pBar.high && -// // -// appliedPrice < pBar.high && -// appliedPrice > pBar.GetUp() -// // -// ; -// bool isPressuredSwingHigh = -// isSwingHigh && -// hasFiboToDownPressure; -// bool isPressuredStrongSwingHigh = -// pBar.IsBearish() && -// isPressuredSwingHigh; - -// // -// bool hasValidSwing = -// isBullish -// ? isSwingLow -// : isSwingHigh; -// bool hasValidPressuredSwing = -// isBullish -// ? isPressuredSwingLow -// : isPressuredSwingHigh; -// bool hasValidPressuredStrongSwing = -// isBullish -// ? isPressuredStrongSwingLow -// : isPressuredStrongSwingHigh; -// if (hasValidSwing) -// { -// swingBar = pBar; -// } -// if (hasValidPressuredSwing) -// { -// swingBar = pBar; -// } -// if (hasValidPressuredStrongSwing) -// { -// swingBar = pBar; -// } - -// // -// bool isCBarBreaked = IsBarBreak( -// appliedPrice, -// forDir, -// cBar // -// ); -// if (isCBarBreaked) -// { -// breakerBar = cBar; -// } -// bool isPBarBreaked = IsBarBreak( -// appliedPrice, -// forDir, -// pBar // -// ); -// if (!isCBarBreaked && isPBarBreaked) -// { -// breakerBar = pBar; -// } -// else -// { -// isPBarBreaked = false; -// } -// bool isPPBarBreaked = IsBarBreak( -// appliedPrice, -// forDir, -// ppBar // -// ); -// if (!isCBarBreaked && -// !isPBarBreaked && -// isPPBarBreaked) -// { -// breakerBar = ppBar; -// } -// else -// { -// isPPBarBreaked = false; -// } -// bool isBoxBreaked = isCBarBreaked || -// isPBarBreaked || -// isPPBarBreaked; - -// // -// bool isCBarRejected = IsBarReject( -// appliedPrice, -// forDir, -// cBar // -// ); -// if (isCBarRejected) -// { -// rejectionBar = cBar; -// } -// bool isPBarRejected = IsBarReject( -// appliedPrice, -// forDir, -// pBar // -// ); -// if (!isCBarRejected && isPBarRejected) -// { -// rejectionBar = pBar; -// } -// else -// { -// isPBarRejected = false; -// } -// bool isPPBarRejected = IsBarReject( -// appliedPrice, -// forDir, -// ppBar // -// ); -// if (!isCBarRejected && -// !isPBarRejected && -// isPPBarRejected) -// { -// rejectionBar = ppBar; -// } -// else -// { -// isPPBarRejected = false; -// } -// bool isBoxRejected = isCBarRejected || -// isPBarRejected || -// isPPBarRejected; - -// // -// bool hasRejectionBar = false; -// if (isBullish) -// { -// // -// count = state.CountBullishRejectionBars(); -// for (int i = 0; i < count; i++) -// { -// // -// XCRejectionBar *iZone = state.bullishRejectionBars[i]; - -// // -// XOHCL iBar; -// bool isFilled = iZone.FillBar(iBar); -// if (!isFilled) -// { -// continue; -// } - -// // -// int iBarIndex = iBar.Index(); - -// // -// hasRejectionBar = -// // -// (iBarIndex == cBar.Index() || -// iBarIndex == pBar.Index()) -// // -// ; -// if (hasRejectionBar) -// { -// // -// if (!rejectionBar.IsValid()) -// { -// rejectionBar = iBar; -// } - -// // -// break; -// } -// } -// } -// else -// { -// // -// count = state.CountBearishRejectionBars(); -// for (int i = 0; i < count; i++) -// { -// // -// XCRejectionBar *iZone = state.bearishRejectionBars[i]; - -// // -// XOHCL iBar; -// bool isFilled = iZone.FillBar(iBar); -// if (!isFilled) -// { -// continue; -// } - -// // -// int iBarIndex = iBar.Index(); - -// // -// hasRejectionBar = -// // -// (iBarIndex == cBar.Index() || -// iBarIndex == pBar.Index()) -// // -// ; -// if (hasRejectionBar) -// { -// // -// if (!rejectionBar.IsValid()) -// { -// rejectionBar = iBar; -// } - -// // -// break; -// } -// } -// } - -// // -// bool hasMomentumBar = false; -// if (isBullish) -// { -// // -// count = state.CountBullishMomentumBars(); -// for (int i = 0; i < count; i++) -// { -// // -// XCMomentumBar *iZone = state.bullishMomentumBars[i]; - -// // -// XOHCL iBar; -// bool isFilled = iZone.FillBar(iBar); -// if (!isFilled) -// { -// continue; -// } - -// // -// int iBarIndex = iBar.Index(); - -// // -// hasMomentumBar = -// // -// (iBarIndex == cBar.Index() || -// iBarIndex == pBar.Index()) -// // -// ; -// if (hasMomentumBar) -// { -// // -// if (!momentumBar.IsValid()) -// { -// momentumBar = iBar; -// } - -// // -// break; -// } -// } -// } -// else -// { -// // -// count = state.CountBearishMomentumBars(); -// for (int i = 0; i < count; i++) -// { -// // -// XCMomentumBar *iZone = state.bearishMomentumBars[i]; - -// // -// XOHCL iBar; -// bool isFilled = iZone.FillBar(iBar); -// if (!isFilled) -// { -// continue; -// } - -// // -// int iBarIndex = iBar.Index(); - -// // -// hasMomentumBar = -// // -// (iBarIndex == cBar.Index() || -// iBarIndex == pBar.Index()) -// // -// ; -// if (hasMomentumBar) -// { -// // -// if (!momentumBar.IsValid()) -// { -// momentumBar = iBar; -// } - -// // -// break; -// } -// } -// } - -// // -// bool hasSwing = false; -// if (isBullish) -// { -// // -// count = state.CountSwingLows(); -// for (int i = 0; i < count; i++) -// { -// // -// XCSwing *iSwing = state.swingLows[i]; - -// // -// XOHCL iBar; -// bool isFilled = iSwing.FillBar(iBar); -// if (!isFilled) -// { -// continue; -// } - -// // -// int iBarIndex = iBar.Index(); - -// // -// hasSwing = -// // -// (iBarIndex == cBar.Index() || -// iBarIndex == pBar.Index()) -// // -// ; -// if (hasSwing) -// { -// // -// if (!swingBar.IsValid()) -// { -// swingBar = iBar; -// } - -// // -// break; -// } -// } -// } -// else -// { -// // -// count = state.CountSwingHighs(); -// for (int i = 0; i < count; i++) -// { -// // -// XCSwing *iSwing = state.swingHighs[i]; - -// // -// XOHCL iBar; -// bool isFilled = iSwing.FillBar(iBar); -// if (!isFilled) -// { -// continue; -// } - -// // -// int iBarIndex = iBar.Index(); - -// // -// hasSwing = -// // -// (iBarIndex == cBar.Index() || -// iBarIndex == pBar.Index()) -// // -// ; -// if (hasSwing) -// { -// // -// if (!swingBar.IsValid()) -// { -// swingBar = iBar; -// } - -// // -// break; -// } -// } -// } - -// // -// bool hasRequiredValidations = -// // -// (hasRejectionBar || -// hasMomentumBar) -// // -// || -// // -// (hasRejectionBar || -// hasSwing) -// // -// || -// // -// (hasMomentumBar || -// hasSwing) -// // -// ; - -// // -// result = -// // -// (isBoxBreaked && -// (hasRequiredValidations || -// hasValidPressuredSwing)) -// // -// || -// // -// (isBoxRejected && -// (hasRequiredValidations || -// hasValidPressuredSwing)) -// // -// ; -// if (result) -// { -// // -// selectedBoxIDX = j; -// break; -// } -// } - -// // -// result = -// result && -// (isBullish -// ? zBar.open > box.upper -// : zBar.open < box.lower) && -// IsValidIndex(selectedBoxIDX); -// if (result) -// { -// appliedBox = supResBoxes[selectedBoxIDX]; -// } - -// // -// zBar.Clean(); -// cBar.Clean(); -// pBar.Clean(); -// ppBar.Clean(); -// Clean(supports); -// Clean(resistances); -// Clean(supResBoxes); - -// // -// return result; -// } +/** + * Detect Nearest Price Out of Specified Box ... + * + * @param box: XBoxZone instance Reference ... + * @param outSideBar: XOHCL instance Reference which Represents Out Side Bar if Exists ... + * @param forPeriod: ENUM_TIMEFRAMES member which provides time frame of Out Bar, if not Provides used box Period as Default ... + * @param forDir: ENUM_X_DIRECTION member which Specified outSide Direction, use Box Dir as Default ... + * @param forceBodyIn: bool value which Specifyed Body Breakes or not, Default is false ... + * @param barIndex: integer value which Specified Start Bar Index, Default is 0 ... + * + * @return ( bool ) + */ +bool DetectBoxNearestPriceOut( + XBoxZone &box, + XOHCL &outSideBar, + ENUM_TIMEFRAMES forPeriod = NULL, + ENUM_X_DIRECTION forDir = X_DIRECTION_NONE, + bool forceBodyIn = false, + int barIndex = 0 // +) +{ + // + bool result = false; + + // + outSideBar.Clean(); + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + result = box.IsValid(); + if (!result) + { + return result; + } + + // + if (!IsValid(forPeriod)) + { + forPeriod = box.period; + } + + // + if (!HasDirection(forDir)) + { + forDir = box.dir; + } + + // + bool isBullish = IsBullish(forDir); + + // + int fromIndex = iBarShift( + box.symbol, + box.period, + box.from // + ); + result = IsValidIndex(fromIndex); + if (!result) + { + return result; + } + + // + XOHCL iBar; + XOHCL iPBar; + bool has = false; + for (int i = barIndex; i < fromIndex; i++) + { + // + has = iBar.Init( + box.symbol, + forPeriod, + i // + ); + if (!has) + { + continue; + } + + // + has = iBar.GetPreviousBar(iPBar); + if (!has) + { + continue; + } + + // + bool isInsideFromLower = + iBar.high < box.lower && + iPBar.high > box.lower; + + // + bool isInsideFromUpper = + iBar.low > box.upper && + iPBar.low < box.upper; + + // + bool isInsideBodyFromLower = + iPBar.GetUp() > box.lower; + + // + bool isInsideBodyFromUpper = + iPBar.GetDown() < box.upper; + + // + result = + isBullish + ? (!forceBodyIn + ? isInsideFromLower + : isInsideFromLower && + isInsideBodyFromLower) + : (!forceBodyIn + ? isInsideFromUpper + : isInsideFromUpper && + isInsideBodyFromUpper); + if (result) + { + // + outSideBar = iBar; + break; + } + } + + // + iBar.Clean(); + iPBar.Clean(); + + // + return result; +} + +// \ No newline at end of file diff --git a/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 b/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 index 97d4cd47..b0339133 100644 --- a/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 @@ -329,6 +329,7 @@ class XCX121SMCXWZSignalDetector : public XCBase // // Setup Conditions ... double sls[]; + double sl = 0; double pivot = 0; double point = 0; double targets[]; @@ -339,10 +340,16 @@ class XCX121SMCXWZSignalDetector : public XCBase bool hasSignalBox = false; bool hasRewardAmount = false; bool isSignalBoxReversal = false; + bool hasWorkingZoneOveralDirection = false; + ENUM_X_DIRECTION wzOveralDir = X_DIRECTION_NONE; ENUM_X_DIRECTION signalBoxDir = X_DIRECTION_NONE; ENUM_X121SMC_XWZ_PRIORITY priority = X121SMC_XWZ_PRIORITY_NONE; ENUM_X121SMC_XWZ_PROVIDERS provider = X121SMC_XWZ_PROVIDER_NONE; + // + // + // + // // First We Have to Has Working Zone ... bool hasWorkingZone = workingZone.IsValid(); @@ -361,21 +368,25 @@ class XCX121SMCXWZSignalDetector : public XCBase } // + // Update Working Zone ... if (hasWorkingZone) { // + // Reset POI Detector Required POI(s) ... visionCycleHelper.mPOIDetector.MaxRequiredPOIs(50); analyseCycleHelper.mPOIDetector.MaxRequiredPOIs(50); decisionCycleHelper.mPOIDetector.MaxRequiredPOIs(50); consolidationCycleHelper.mPOIDetector.MaxRequiredPOIs(50); // + // Reset POI Detector Allowed Loopback ... visionCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(578); analyseCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(578); decisionCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(578); consolidationCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(578); // + // Update Working Zone ... workingZone.Update( zIndex, visionState, @@ -385,16 +396,63 @@ class XCX121SMCXWZSignalDetector : public XCBase ); // - bool isDestroyed = workingZone.IsDestroyed( + // Check Working Zone Overal Direction ... + hasWorkingZoneOveralDirection = workingZone + .DetectOveralDirection(wzOveralDir); + + // + // Checking Working Zone Destory or not ... + bool isWorkingZoneDestroyed = workingZone.IsDestroyed( zIndex, period // ); - if (isDestroyed) + + // + // Cleanup WorkingZone and ignore all conditions ... + if (isWorkingZoneDestroyed) { // result = false; workingZone.Clean(); hasWorkingZone = false; + + // + // Cleanup Resources ... + Clean(visionPoiEvents); + Clean(analysePoiEvents); + Clean(decisionPoiEvents); + Clean(consolidationPoiEvents); + + // + Clean(visionCycleEvents); + Clean(analyseCycleEvents); + Clean(decisionCycleEvents); + Clean(consolidationCycleEvents); + + // + visionState.Clean(); + analyseState.Clean(); + decisionState.Clean(); + consolidationState.Clean(); + + // + visionConditions.Clean(); + analyseConditions.Clean(); + decisionConditions.Clean(); + consolidationConditions.Clean(); + + // + visionXConditions.Clean(); + analyseXConditions.Clean(); + decisionXConditions.Clean(); + consolidationXConditions.Clean(); + + // + mConditions.Clean(); + consolidationZBar.Clean(); + + // + return result; } } @@ -513,17 +571,24 @@ class XCX121SMCXWZSignalDetector : public XCBase // // Remove Signal Box from Waiting Boxes of // Working Zone ... - if (hasSignalBox && - IsValidIndex(idx)) + if (hasSignalBox) { // - ArrayRemove( - workingZone.waitingBoxes, - idx, - 1 // - ); + if (IsValidIndex(idx)) + { + // + ArrayRemove( + workingZone.waitingBoxes, + idx, + 1 // + ); + } } + // + // Ignore Zone's Signals ... + hasSignalBox = false; + // // Cleanup Resources ... @@ -555,8 +620,6 @@ class XCX121SMCXWZSignalDetector : public XCBase { // // Senari A ... - - // hasSignalBox = hasWorkingZone && workingZone.DetectSenarioASignalBox( signalBox, @@ -574,6 +637,55 @@ class XCX121SMCXWZSignalDetector : public XCBase isSignalBoxReversal = false; provider = X121SMC_XWZ_PROVIDER_PV_ZONE; } + + // + // Validating Signal Box if Exists ... + if (hasSignalBox) + { + // + // Validate Signal Boxes using Inside Box ... + if (hasInsideBoxes) + { + // + int idx = -1; + bool has = false; + + // + idx = + IsBullish(signalBoxDir) + ? GetLowest(workingZone.insideBoxes) + : GetHighest(workingZone.insideBoxes); + has = IsValidIndex(idx); + if (has) + { + // + hasSignalBox = + signalBoxDir == workingZone.insideBoxes[idx].dir; + } + } + + // + // Validate Signal Box Using Overal Trend ... + if (hasWorkingZoneOveralDirection) + { + // + hasSignalBox = + signalBoxDir == wzOveralDir; + } + } + } + + // + // + // + + // + // Cleanup Signal if UnApproved ... + if (!hasSignalBox) + { + // + signalBox.Clean(); + signalBoxDir = X_DIRECTION_NONE; } // @@ -646,15 +758,54 @@ class XCX121SMCXWZSignalDetector : public XCBase iSL = signalBox.lower + (signalBox.upper - signalBox.lower) / 2; } + // + if (provider == X121SMC_XWZ_PROVIDER_PV_ZONE) + { + } + // Add( iSL, sls // ); + // + // Select Condition SL ... + + // + double entry = GetEntry( + signalBox.symbol, + signalBoxDir // + ); + + // + double slsMin = GetMin(sls); + double slsMax = GetMax(sls); + + // + double longSL = slsMin; + double shortSL = slsMax; + + // + sl = isBullish + ? longSL + : shortSL; + // // Targets ... + // + // Force Add TP 2 as Target ... + double risk = MathAbs(entry - sl); + double reward2 = 2 * risk; + double iTP2 = isBullish + ? entry + reward2 + : entry - reward2; + Add( + iTP2, + targets // + ); + // // Based On Priority ... has = priority != X121SMC_XWZ_PRIORITY_NONE; @@ -979,6 +1130,7 @@ class XCX121SMCXWZSignalDetector : public XCBase } // + // Summarize Results ... result = hasPriority && hasSignalBox && hasRewardAmount; @@ -997,6 +1149,7 @@ class XCX121SMCXWZSignalDetector : public XCBase ); // + mConditions.sl = sl; mConditions.pivot = pivot; mConditions.point = point; mConditions.reward = reward; @@ -1032,6 +1185,10 @@ class XCX121SMCXWZSignalDetector : public XCBase ); } + // + // + // + // // Cleanup Resources ... @@ -1222,42 +1379,6 @@ class XCX121SMCXWZSignalDetector : public XCBase if (result) { // - // Retrieve Entry Price ... - double entry = GetEntry( - conditions.symbol, - setupDir // - ); - - // - // Select and Apply SL ... - - // - double slsMin = GetMin(conditions.sls); - double slsMax = GetMax(conditions.sls); - - // - double longSL = slsMin; - double shortSL = slsMax; - - // - double sl = isBullish - ? longSL - : shortSL; - - // - // Add TP 2 as Target ... - double risk = MathAbs(entry - sl); - double reward2 = 2 * risk; - double iTP2 = isBullish - ? entry + reward2 - : entry - reward2; - Add( - iTP2, - conditions.targets // - ); - - // - conditions.sl = sl; conditions.triggerTime = cTime; conditions.type = isBullish ? X_POSITION_TYPE_LONG diff --git a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 index de239e7a..d70385e2 100644 --- a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 @@ -47,6 +47,9 @@ enum ENUM_X121SMC_XWZ_PRIORITY X121SMC_XWZ_PRIORITY_STRONG_HIGH, }; +// +// Definitions ... + // struct X121SMCStrategyXWZWorkingZone { @@ -78,6 +81,7 @@ struct X121SMCStrategyXWZWorkingZone XBoxZone insideBoxes[]; XBoxZone breakedBoxes[]; XBoxZone waitingBoxes[]; + XBoxZone breakedInsideBoxes[]; XConsolidationZone consolidationZones[]; // @@ -85,8 +89,10 @@ struct X121SMCStrategyXWZWorkingZone CArrayObj mBreakedZoneObjects; CArrayObj mWaitingZoneObjects; CArrayObj mWorkingZoneObjects; + CArrayObj mBreakedInsideZoneObjects; // + bool mUseSupDems; bool mUseOrderBlocks; bool mUseFairValueGaps; @@ -134,10 +140,12 @@ struct X121SMCStrategyXWZWorkingZone mBreakedZoneObjects.Clear(); mWaitingZoneObjects.Clear(); mWorkingZoneObjects.Clear(); + mBreakedInsideZoneObjects.Clear(); // + mUseSupDems = false; mUseOrderBlocks = true; - mUseFairValueGaps = false; + mUseFairValueGaps = true; } // @@ -271,6 +279,10 @@ struct X121SMCStrategyXWZWorkingZone } } + // + // + // + // // Supply Zones ... has = HasSupplyZones(); @@ -581,6 +593,102 @@ struct X121SMCStrategyXWZWorkingZone // // Update Exists Zones ... + // // + // // Supply Zones ... + // has = mtfState.HasSupplyZones(); + // if (has) + // { + // // + // XCSupplyZone *tmpZones[]; + // count = mtfState.FilterSupplyZones( + // tmpZones, + // period, + // XZONE_STATE_PASSED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_IGNORED, + // false // + // ); + // has = IsValidSize(count); + // if (has) + // { + // // + // for (int i = 0; i < count; i++) + // { + // // + // // Try to Validate Indexes ... + + // // + // XCSupplyZone *iZone = tmpZones[i]; + // has = IsSupplyExists(iZone); + // if (!has) + // { + // // + // Add( + // iZone, + // supplyZones // + // ); + // } + // } + // } + + // // + // Clean(tmpZones); + // } + + // // + // // Demand Zones ... + // has = mtfState.HasDemandZones(); + // if (has) + // { + // // + // XCDemandZone *tmpZones[]; + // count = mtfState.FilterDemandZones( + // tmpZones, + // period, + // XZONE_STATE_PASSED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_IGNORED, + // false // + // ); + // has = IsValidSize(count); + // if (has) + // { + // // + // for (int i = 0; i < count; i++) + // { + // // + // // Try to Validate Indexes ... + + // // + // XCDemandZone *iZone = tmpZones[i]; + // has = IsDemandExists(iZone); + // if (!has) + // { + // // + // Add( + // iZone, + // demandZones // + // ); + // } + // } + // } + + // // + // Clean(tmpZones); + // } + + // + // + // + // // Supply Zones ... has = HasSupplyZones(); @@ -1647,7 +1755,7 @@ struct X121SMCStrategyXWZWorkingZone { // XCBoxObject *iObj; - bool isCreated= drawer.DrawBox( + bool isCreated = drawer.DrawBox( signalBox, iObj // ); @@ -1763,6 +1871,120 @@ struct X121SMCStrategyXWZWorkingZone return result; } + // + bool DetectOveralDirection( + ENUM_X_DIRECTION &dir // + ) + { + // + bool result = false; + + // + dir = X_DIRECTION_NONE; + + // + result = IsValid() && + HasSupplyZone() && + HasDemandZone(); + if (!result) + { + return result; + } + + // + XBoxZone demBox; + XBoxZone supBox; + result = ToBox( + demBox, + demandZone // + ); + if (!result) + { + // + supBox.Clean(); + demBox.Clean(); + + // + return result; + } + result = ToBox( + supBox, + supplyZone // + ); + if (!result) + { + // + supBox.Clean(); + demBox.Clean(); + + // + return result; + } + + // + XOHCL supPriceOutBar; + XOHCL demPriceOutBar; + result = DetectBoxNearestPriceOut( + supBox, + supPriceOutBar, + period // + ); + if (!result) + { + // + demBox.Clean(); + supBox.Clean(); + supPriceOutBar.Clean(); + demPriceOutBar.Clean(); + + // + return result; + } + result = DetectBoxNearestPriceOut( + demBox, + demPriceOutBar, + period // + ); + if (!result) + { + // + demBox.Clean(); + supBox.Clean(); + supPriceOutBar.Clean(); + demPriceOutBar.Clean(); + + // + return result; + } + + // + // Specified Direction ... + dir = + (supPriceOutBar.IsValid() && + demPriceOutBar.IsValid()) + ? supPriceOutBar.time > demPriceOutBar.time + ? X_DIRECTION_BEARISH + : demPriceOutBar.time > supPriceOutBar.time + ? X_DIRECTION_BULLISH + : X_DIRECTION_NONE + : X_DIRECTION_NONE; + + // + result = HasDirection(dir); + + // + // Clean Up Resources ... + + // + demBox.Clean(); + supBox.Clean(); + supPriceOutBar.Clean(); + demPriceOutBar.Clean(); + + // + return result; + } + // bool HasInsideBox( XBoxZone &box // @@ -1868,6 +2090,199 @@ struct X121SMCStrategyXWZWorkingZone return result; } + // + bool IsExists(XBoxZone &box) + { + // + bool result = false; + + // + result = box.IsValid(); + if (!result) + { + return result; + } + + // + int idx = -1; + bool has = false; + + // + // Checking Index Waiting Box ... + has = HasWaitingBoxes(); + if (has) + { + // + idx = FindIndex( + box, + waitingBoxes // + ); + result = !IsValidIndex(idx); + if (!result) + { + return result; + } + } + + // + // Checking Index Inside Boxes ... + has = HasInsideBoxes(); + if (has) + { + // + idx = FindIndex( + box, + insideBoxes // + ); + result = !IsValidIndex(idx); + if (!result) + { + return result; + } + } + + // + // Checking Index Breaked Boxes ... + has = HasBreakedBoxes(); + if (has) + { + // + idx = FindIndex( + box, + breakedBoxes // + ); + result = !IsValidIndex(idx); + if (!result) + { + return result; + } + } + + // + // Checking Index BreakedInside Boxes ... + has = HasBreakedInsideBoxes(); + if (has) + { + // + idx = FindIndex( + box, + breakedInsideBoxes // + ); + result = !IsValidIndex(idx); + if (!result) + { + return result; + } + } + + // + return result; + } + + // + bool IsSupplyExists(XCSupplyZone *zone) + { + // + bool result = false; + + // + result = zone != NULL && + zone.IsValid(); + if (!result) + { + return result; + } + + // + // Converts Zone to Box ... + XBoxZone box; + result = ToBox( + box, + zone // + ); + if (!result) + { + // + box.Clean(); + return result; + } + + // + // Checking Index in SupplyZones ... + int idx = FindIndex( + zone, + supplyZones // + ); + result = !IsValidIndex(idx); + if (!result) + { + // + box.Clean(); + return result; + } + + // + result = IsExists(box); + + // + box.Clean(); + + // + return result; + } + + // + bool IsDemandExists(XCDemandZone *zone) + { + // + bool result = false; + + // + result = zone != NULL && + zone.IsValid(); + if (!result) + { + return result; + } + + // + // Converts Zone to Box ... + XBoxZone box; + result = ToBox( + box, + zone // + ); + if (!result) + { + // + box.Clean(); + return result; + } + + // + // Checking Index in SupplyZones ... + int idx = FindIndex( + zone, + demandZones // + ); + result = !IsValidIndex(idx); + if (!result) + { + // + box.Clean(); + return result; + } + + // + result = IsExists(box); + + // + box.Clean(); + + // + return result; + } + // void UpdateTo(datetime value = NULL) { @@ -2486,11 +2901,22 @@ struct X121SMCStrategyXWZWorkingZone return ArraySize(breakedBoxes); } + // + bool HasBreakedInsideBoxes() + { + return HasChild(breakedInsideBoxes); + } + + // + int CountBreakedInsideBoxes() + { + return ArraySize(breakedInsideBoxes); + } + // }; // -// Definitions ... struct X121SMCStrategyXWZSignalConditions { // diff --git a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 index 2f19ea79..21e1e2c7 100644 --- a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 @@ -763,38 +763,38 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // XTREND ... x121Inputs.xtrendInputs.showUpTrend = showAll || false; x121Inputs.xtrendInputs.showDownTrend = showAll || false; - x121Inputs.xtrendInputs.showOnlyTrendStart = showAll || true; + x121Inputs.xtrendInputs.showOnlyTrendStart = showAll || false; // // XPV ... - x121Inputs.xpvInputs.showSar = showAll || true; - x121Inputs.xpvInputs.showPeaks = showAll || true; - x121Inputs.xpvInputs.showVales = showAll || true; + x121Inputs.xpvInputs.showSar = showAll || false; + x121Inputs.xpvInputs.showPeaks = showAll || false; + x121Inputs.xpvInputs.showVales = showAll || false; // // XHK ... // - x121Inputs.xhkInputs.drawRawXHKCandles = showAll || true; - x121Inputs.xhkInputs.drawSmoothedXHKCandles = showAll || true; + x121Inputs.xhkInputs.drawRawXHKCandles = showAll || false; + x121Inputs.xhkInputs.drawSmoothedXHKCandles = showAll || false; // // XATR ... - x121Inputs.xatrInputs.showATRUpper = showAll || true; - x121Inputs.xatrInputs.showATRLower = showAll || true; + x121Inputs.xatrInputs.showATRUpper = showAll || false; + x121Inputs.xatrInputs.showATRLower = showAll || false; // // XSTR ... - x121Inputs.xstrInputs.showStr = showAll || true; + x121Inputs.xstrInputs.showStr = showAll || false; x121Inputs.xstrInputs.showStrUpper = showAll || false; x121Inputs.xstrInputs.showStrLower = showAll || false; // // XCHE ... - x121Inputs.xcheInputs.showLE1 = showAll || true; - x121Inputs.xcheInputs.showLE2 = showAll || true; - x121Inputs.xcheInputs.showSE1 = showAll || true; - x121Inputs.xcheInputs.showSE2 = showAll || true; + x121Inputs.xcheInputs.showLE1 = showAll || false; + x121Inputs.xcheInputs.showLE2 = showAll || false; + x121Inputs.xcheInputs.showSE1 = showAll || false; + x121Inputs.xcheInputs.showSE2 = showAll || false; // // XDON ... @@ -805,15 +805,15 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // // XVWAP ... - x121Inputs.xvwapInputs.showVWapFast = showAll || true; - x121Inputs.xvwapInputs.showVWapMedium = showAll || true; - x121Inputs.xvwapInputs.showVWapSlow = showAll || true; + x121Inputs.xvwapInputs.showVWapFast = showAll || false; + x121Inputs.xvwapInputs.showVWapMedium = showAll || false; + x121Inputs.xvwapInputs.showVWapSlow = showAll || false; // // X3MA ... - x121Inputs.x3maInputs.showX3MaFast = showAll || true; - x121Inputs.x3maInputs.showX3MaMid = showAll || true; - x121Inputs.x3maInputs.showX3MaSlow = showAll || true; + x121Inputs.x3maInputs.showX3MaFast = showAll || false; + x121Inputs.x3maInputs.showX3MaMid = showAll || false; + x121Inputs.x3maInputs.showX3MaSlow = showAll || false; // // Initialize Cycle Helpers ...