From ec006cd6b7a119cd10644f66a07f373f4d4bd9ab Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Tue, 4 Mar 2025 03:05:25 +0330 Subject: [PATCH] last ... --- Experts/x-saherelm.x-121.smc.ea.mq5 | 32 +- Libraries/x-saherelm.x-poi.extensions.lib.mq5 | 2 +- .../x-121.smc.market.cycle.helper.class.mq5 | 136 ++- .../Signals/x-121.smc.xwz.signal.class.mq5 | 523 +++++++--- .../Signals/x-121.smc.xwz.signal.lib.mq5 | 916 ++++++++++++++---- .../Strategy/x-121.smc.strategy.class.mq5 | 26 +- 6 files changed, 1278 insertions(+), 357 deletions(-) diff --git a/Experts/x-saherelm.x-121.smc.ea.mq5 b/Experts/x-saherelm.x-121.smc.ea.mq5 index 2ca32bc4..6f2518a6 100644 --- a/Experts/x-saherelm.x-121.smc.ea.mq5 +++ b/Experts/x-saherelm.x-121.smc.ea.mq5 @@ -44,23 +44,23 @@ input string eaSymbols = "EURUSDb,GBPUSDb,USDCHFb,USDJPYb,XAUUSDb"; // Trading S // // Signalling ... input group "Signalling"; -input bool eaAllowLong = true; // Allow Long Signals -input bool eaAllowShort = true; // Allow Short Signals -input int eaMaxAllowedLongs = 5; // Max Allowed Long Signals -input int eaMaxAllowedShorts = 5; // Max Allowed Short Signals -input bool eaUseMaxAllowedSignalsPerSymbol = true; // Use Max Allowed Signal Types Per Symbol -input double eaLastPositionProfitForAcceptNextInPoint = 0; // Last Position Profit In Points for Accept new Signal -input int eaDelaysBetweenTwoSignalsInBar = 0; // Delay between two Signals in Bars -input double eaMaxAllowedSpread = 25; // Max Allowed Spread for Signalling -input int eaMinRequiredVerificationForSpreadPass = 20; // Minimum Spread Verification for Signalling +input bool eaAllowLong = true; // Allow Long Signals +input bool eaAllowShort = true; // Allow Short Signals +input int eaMaxAllowedLongs = 5; // Max Allowed Long Signals +input int eaMaxAllowedShorts = 5; // Max Allowed Short Signals +input bool eaUseMaxAllowedSignalsPerSymbol = true; // Use Max Allowed Signal Types Per Symbol +input double eaLastPositionProfitForAcceptNextInPoint = 30; // Last Position Profit In Points for Accept new Signal +input int eaDelaysBetweenTwoSignalsInBar = 12; // Delay between two Signals in Bars +input double eaMaxAllowedSpread = 25; // Max Allowed Spread for Signalling +input int eaMinRequiredVerificationForSpreadPass = 20; // Minimum Spread Verification for Signalling // // Trade ... input group "Trade"; -input bool eaAllowTrade = true; // Allow Open Trade On Signals -input string eaStartTradeAt = ""; // Enable Trade on Signals on Time -input string eaStopTradeAt = ""; // Enable Trade on Signals on Time -input string eaCloseAllTradesAt = ""; // Enable Close All Trades on Signals on Time +input bool eaAllowTrade = true; // Allow Open Trade On Signals +input string eaStartTradeAt = "02:30"; // Enable Trade on Signals on Time +input string eaStopTradeAt = "23:30"; // Enable Trade on Signals on Time +input string eaCloseAllTradesAt = ""; // Enable Close All Trades on Signals on Time // // Risk Management ... @@ -82,9 +82,9 @@ input int eaPauseSignallingAfterReachesMaxAllowedSLInSecconds = 10800; // Pause // Protection ... input group "Protection"; input bool eaAllowHedging = true; // Allow Hedge Positions -input int eaMinOpenTradesFroHedging = 4; // Minimum Open Positions for Hedging +input int eaMinOpenTradesFroHedging = 3; // Minimum Open Positions for Hedging input double eaHedgingMinVolumeStep = 0.01; // Minimum Volume Step for Hedging -input double eaHedgeingMinRequiredProfitPerVolumeStep = 4.0; // Minimum Required Profit Per Volume Step for Hedging +input double eaHedgeingMinRequiredProfitPerVolumeStep = 1.0; // Minimum Required Profit Per Volume Step for Hedging // // Alert ... @@ -233,7 +233,7 @@ void OnDeinit(const int reason) { // // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function - // REASON_REMOVE 1 Program removed from a chart + // REASON_REMOVE 1 Program removed from a chart // REASON_RECOMPILE 2 Program recompiled // REASON_CHARTCHANGE 3 A symbol or a chart period is changed // REASON_CHARTCLOSE 4 Chart closed diff --git a/Libraries/x-saherelm.x-poi.extensions.lib.mq5 b/Libraries/x-saherelm.x-poi.extensions.lib.mq5 index 053de36d..757bb9d7 100644 --- a/Libraries/x-saherelm.x-poi.extensions.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.extensions.lib.mq5 @@ -1299,7 +1299,7 @@ bool HasInsideBox( // bool isInside = !iBox.IsSameAs(source) && - IsBoxInside( + IsBoxInsideOr( iBox, source // ); diff --git a/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 b/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 index 1f5a5ee8..e013813e 100644 --- a/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 @@ -169,15 +169,17 @@ class XC121SMCCycleHelper : public XCBase // int maxLoopbackBars = mPOIDetector.MaxAllowedLoopbackForInit(); int periodSeconds = PeriodSeconds(period); - if (periodSeconds > PeriodSeconds(PERIOD_M15)) { + if (periodSeconds > PeriodSeconds(PERIOD_M15)) + { // int multiplier = periodSeconds / PeriodSeconds(PERIOD_M15); // - if (multiplier >= 1) { + if (multiplier >= 1) + { maxLoopbackBars *= 2; } - } + } mPOIDetector.MaxAllowedLoopbackForInit(maxLoopbackBars); mPOIDetector.Init(); @@ -450,6 +452,134 @@ class XC121SMCCycleHelper : public XCBase return result; } + bool GeneratePVBox( + XBoxZone &box, + int barIndex = 0 // + ) + { + // + bool result = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + box.Clean(); + box.symbol = GetSymbol(); + box.period = GetPeriod(); + + // + int index = barIndex; + + // + // Peak ... + datetime peaksSameFrom = NULL; + double peak = mX121Helper.xpvHelper.GetPeak(index); + double prevPeak = mX121Helper.xpvHelper.GetPeak(index + 1); + bool startsByPeak = peak == prevPeak; + + // + // Vale ... + datetime valesSameFrom = NULL; + double vale = mX121Helper.xpvHelper.GetVale(index); + double prevVale = mX121Helper.xpvHelper.GetVale(index + 1); + bool startsByVale = vale == prevVale; + + // + bool canBreak = false; + while (!canBreak) + { + // + index++; + + // + datetime cTime = iTime( + box.symbol, + box.period, + index // + ); + + // + // Peak ... + double iPeak = mX121Helper.xpvHelper.GetPeak(index); + + // + // Vale ... + double iVale = mX121Helper.xpvHelper.GetVale(index); + + // + // Start By Peak or Value ... + bool isSame = false; + if (startsByPeak) + { + // + isSame = iPeak == peak; + bool canSetVale = vale == 0 + ? true + : iVale > vale; + if (canSetVale) + { + vale = iVale; + } + } + else if (startsByVale) + { + // + isSame = iVale == vale; + bool canSetPeak = peak == 0 + ? true + : iPeak < peak; + if (canSetPeak) + { + peak = iPeak; + } + } + + // + if (isSame) + { + // + box.from = cTime; + box.upper = peak; + box.lower = vale; + } + else if (IsValid(box.from)) + { + // + // Complete Box ... + box.to = iTime( + box.symbol, + box.period, + barIndex // + ); + + // + box.type = "XPVBox"; + box.dir = startsByPeak + ? X_DIRECTION_BEARISH + : startsByVale + ? X_DIRECTION_BULLISH + : X_DIRECTION_NONE; + } + + // + canBreak = !isSame; + } + + // + result = box.IsValid(); + if (!result) + { + box.Clean(); + } + + // + return result; + } + // // Virtuals ... diff --git a/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 b/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 index 29230fe0..97d4cd47 100644 --- a/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 @@ -500,6 +500,7 @@ class XCX121SMCXWZSignalDetector : public XCBase idx = i; signalBox = iBox; hasSignalBox = has; + signalBox.to = cTime; signalBoxDir = iBox.dir; isSignalBoxReversal = false; provider = X121SMC_XWZ_PROVIDER_ACTIVATED_ZONE; @@ -553,119 +554,25 @@ class XCX121SMCXWZSignalDetector : public XCBase if (!hasSignalBox) { // - // Score Conditions ... - double scoreMultiplier = 3; - bool isBullishScorePassed = - // - analyseBullishScore > (analyseBearishScore * scoreMultiplier) && - decisionBullishScore > (decisionBearishScore * scoreMultiplier) - // - ; - bool isBearishScorePassed = - // - analyseBearishScore > (analyseBullishScore * scoreMultiplier) && - decisionBearishScore > (decisionBullishScore * scoreMultiplier) - // - ; + // Senari A ... // - // X3Ma ... - - // - // X3Ma Bullish ... - bool isX3MaBullish = - // - decisionXConditions.isX3MaBullishState && - decisionXConditions.isX3MaSwitchedToBullishOrdered && - decisionXConditions.x3maMidBuffer[1] > decisionXConditions.x3maSlowBuffer[1] - // - ; - - // - // X3Ma Bearish ... - bool isX3MaBearish = - // - decisionXConditions.isX3MaBearishState && - decisionXConditions.isX3MaSwitchedToBearishOrdered && - decisionXConditions.x3maMidBuffer[1] < decisionXConditions.x3maSlowBuffer[1] - // - ; - - // - bool isX3MaHasCondition = - (isX3MaBullish && - isBullishScorePassed) || - (isX3MaBearish && - isBearishScorePassed); - - // - // VWap ... - - // - // VWap Bullish ... - bool isVWapBullish = - // - decisionXConditions.isVWapBullishState && - decisionXConditions.isVWapSwitchedToBullishOrdered && - decisionXConditions.vwapMidBuffer[1] > decisionXConditions.vwapSlowBuffer[1] - // - ; - - // - // VWap Bearish ... - bool isVWapBearish = - // - decisionXConditions.isVWapBearishState && - decisionXConditions.isVWapSwitchedToBearishOrdered && - decisionXConditions.vwapMidBuffer[1] < decisionXConditions.vwapSlowBuffer[1] - // - ; - - // - bool isVWapHasCondition = - (isVWapBullish && - isBullishScorePassed) || - (isVWapBearish && - isBearishScorePassed); - - // - // Checking Other Conditions XWZ Reject on EMA 20 ... - - // - // Check Has Conditions ... - bool hasXConditions = - (isX3MaHasCondition || - isVWapHasCondition); - - // - if (hasXConditions) + hasSignalBox = hasWorkingZone && + workingZone.DetectSenarioASignalBox( + signalBox, + signalBoxDir, + decisionXConditions, + analyseXConditions, + decisionCycleHelper, + drawer, + zIndex // + ); + if (hasSignalBox) { // - if (isX3MaHasCondition) - { - // - signalBoxDir = - isX3MaBullish - ? X_DIRECTION_BULLISH - : isX3MaBearish - ? X_DIRECTION_BEARISH - : X_DIRECTION_NONE; - } - - // - if (isVWapHasCondition) - { - // - signalBoxDir = - isVWapBullish - ? X_DIRECTION_BULLISH - : isVWapBearish - ? X_DIRECTION_BEARISH - : X_DIRECTION_NONE; - } - - // - Print("X Conditions ..."); + signalBox.to = cTime; + isSignalBoxReversal = false; + provider = X121SMC_XWZ_PROVIDER_PV_ZONE; } } @@ -711,10 +618,394 @@ class XCX121SMCXWZSignalDetector : public XCBase iObj.BoxWidth(1); iObj.BoxColor(clrYellow); iObj.BoxStyle(STYLE_SOLID); + } + + // + isBullish = IsBullish(signalBoxDir); + isBearish = IsBearish(signalBoxDir); + + // + pivot = isBullish + ? signalBox.lower + : signalBox.upper; + + // + point = isBullish + ? signalBox.upper + : signalBox.lower; + + // + double iSL = 0; + double signalBoxRange = (signalBox.upper - signalBox.lower); + if (signalBoxRange < points * 100) + { + iSL = pivot; + } + else + { + iSL = signalBox.lower + (signalBox.upper - signalBox.lower) / 2; + } + + // + Add( + iSL, + sls // + ); + + // + // Targets ... + + // + // Based On Priority ... + has = priority != X121SMC_XWZ_PRIORITY_NONE; + if (has) + { + // + switch (priority) + { + // + case X121SMC_XWZ_PRIORITY_WEAK: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + } + break; // - Print("Signal Box Exists ..."); + case X121SMC_XWZ_PRIORITY_LOW: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + } + break; + + // + case X121SMC_XWZ_PRIORITY_REGULAR: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + } + break; + + // + case X121SMC_XWZ_PRIORITY_HIGH: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter3, + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter1, + targets // + ); + } + break; + + // + case X121SMC_XWZ_PRIORITY_STRONG_HIGH: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Strong High ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Strong High ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + } + break; + } } + + // + XBoxZone waitingBoxes[]; + has = workingZone.HasWaitingBoxes(); + if (has) + { + // + Copy( + workingZone.waitingBoxes, + waitingBoxes // + ); + + // + while (HasChild(waitingBoxes)) + { + // + XBoxZone iBox; + idx = GetYoungest(waitingBoxes); + has = IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + iBox = waitingBoxes[idx]; + ArrayRemove( + waitingBoxes, + idx, + 1 // + ); + + // + bool hasInside = workingZone.HasInsideBox(iBox); + if (!hasInside) + { + continue; + } + + // + double iTarget = + IsBullish(signalBoxDir) + ? iBox.lower + : iBox.upper; + + // + Add( + iTarget, + targets // + ); + + // + iBox.Clean(); + } + } + } + + // + result = hasPriority && + hasSignalBox && + hasRewardAmount; + + // + if (result) + { + // + Copy( + sls, + mConditions.sls // + ); + Copy( + targets, + mConditions.targets // + ); + + // + mConditions.pivot = pivot; + mConditions.point = point; + mConditions.reward = reward; + mConditions.setupTime = cTime; + mConditions.dir = signalBoxDir; + mConditions.priority = priority; + mConditions.provider = provider; + mConditions.signalBox = signalBox; + mConditions.amountPercent = amountPercent; } // @@ -953,6 +1244,18 @@ class XCX121SMCXWZSignalDetector : public XCBase ? 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; diff --git a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 index cb16b1fd..de239e7a 100644 --- a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 @@ -30,6 +30,7 @@ enum ENUM_X121SMC_XWZ_PROVIDERS { X121SMC_XWZ_PROVIDER_NONE, + X121SMC_XWZ_PROVIDER_PV_ZONE, X121SMC_XWZ_PROVIDER_ACTIVATED_ZONE, X121SMC_XWZ_PROVIDER_ACTIVATED_CHOCH, X121SMC_XWZ_PROVIDER_PRICE_INSIDE_ZONE, @@ -85,6 +86,10 @@ struct X121SMCStrategyXWZWorkingZone CArrayObj mWaitingZoneObjects; CArrayObj mWorkingZoneObjects; + // + bool mUseOrderBlocks; + bool mUseFairValueGaps; + // // Constructor ... X121SMCStrategyXWZWorkingZone() @@ -129,6 +134,10 @@ struct X121SMCStrategyXWZWorkingZone mBreakedZoneObjects.Clear(); mWaitingZoneObjects.Clear(); mWorkingZoneObjects.Clear(); + + // + mUseOrderBlocks = true; + mUseFairValueGaps = false; } // @@ -385,99 +394,107 @@ struct X121SMCStrategyXWZWorkingZone // // Using Order Blocks ... - has = iState.HasOrderBlocks(); - if (has) + if (mUseOrderBlocks) { // - XCOrderBlock *obs[]; - count = iState.FilterOrderBlocks( - obs, - period, - XZONE_STATE_PASSED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_IGNORED, - false // - ); - - // - has = IsValidSize(count); + has = iState.HasOrderBlocks(); if (has) { // - ToBox( + XCOrderBlock *obs[]; + count = iState.FilterOrderBlocks( obs, - waitingBoxes // + period, + XZONE_STATE_PASSED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_IGNORED, + false // ); - } - // - Clean(obs); + // + has = IsValidSize(count); + if (has) + { + // + ToBox( + obs, + waitingBoxes // + ); + } + + // + Clean(obs); + } } // // Using Fair Value Gaps ... - has = iState.HasFairValueGaps(); - if (has) + if (mUseFairValueGaps) { // - XBoxZone boxes[]; - XCFVG *fvgs[]; - count = iState.FilterFairValueGaps( - fvgs, - period, - XZONE_STATE_PASSED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_IGNORED, - false // - ); - - // - has = IsValidSize(count); + has = iState.HasFairValueGaps(); if (has) { // - count = ToBox( + XBoxZone boxes[]; + XCFVG *fvgs[]; + count = iState.FilterFairValueGaps( fvgs, - boxes // + period, + XZONE_STATE_PASSED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_IGNORED, + false // ); // - for (int i = 0; i < count; i++) + has = IsValidSize(count); + if (has) { // - XBoxZone iBox = boxes[i]; + count = ToBox( + fvgs, + boxes // + ); // - int idx = FindIndex( - iBox, - waitingBoxes // - ); - has = !IsValidIndex(idx); - if (has) + for (int i = 0; i < count; i++) { // - AddRef( + XBoxZone iBox = boxes[i]; + + // + int idx = FindIndex( iBox, waitingBoxes // ); + has = !IsValidIndex(idx); + if (has) + { + // + AddRef( + iBox, + waitingBoxes // + ); + } + + // + iBox.Clean(); } - - // - iBox.Clean(); } - } - // - Clean(fvgs); - Clean(boxes); + // + Clean(fvgs); + Clean(boxes); + } } // @@ -976,196 +993,204 @@ struct X121SMCStrategyXWZWorkingZone XPOIState iState = mtfState; // - // Detect Waiting Zones ... - has = iState.HasOrderBlocks(); - if (has) + // Use Order Blocks ... + if (mUseOrderBlocks) { // - XCOrderBlock *obs[]; - count = iState.FilterOrderBlocks( - obs, - period, - XZONE_STATE_PASSED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_IGNORED, - false // - ); - - // - has = IsValidSize(count); + has = iState.HasOrderBlocks(); if (has) { // - // Try to Add new OBs into Waiting Zones ... - // if it's not exists ... - for (int i = 0; i < count; i++) + XCOrderBlock *obs[]; + count = iState.FilterOrderBlocks( + obs, + period, + XZONE_STATE_PASSED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_IGNORED, + false // + ); + + // + has = IsValidSize(count); + if (has) { // - XBoxZone iBox; - bool hasBox = ToBox( - iBox, - obs[i] // - ); - if (!hasBox) + // Try to Add new OBs into Waiting Zones ... + // if it's not exists ... + for (int i = 0; i < count; i++) { // - iBox.Clean(); - continue; - } + XBoxZone iBox; + bool hasBox = ToBox( + iBox, + obs[i] // + ); + if (!hasBox) + { + // + iBox.Clean(); + continue; + } - // - // Check Index in Waiting Boxes ... - idx = FindIndex( - iBox, - waitingBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { // - iBox.Clean(); - continue; - } + // Check Index in Waiting Boxes ... + idx = FindIndex( + iBox, + waitingBoxes // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } - // - // Check Index in Inside Boxes ... - idx = FindIndex( - iBox, - insideBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { // - iBox.Clean(); - continue; - } + // Check Index in Inside Boxes ... + idx = FindIndex( + iBox, + insideBoxes // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } - // - // Check Index in Breaked Boxes ... - idx = FindIndex( - iBox, - breakedBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { // - iBox.Clean(); - continue; - } + // Check Index in Breaked Boxes ... + idx = FindIndex( + iBox, + breakedBoxes // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } - // - AddRef( - iBox, - waitingBoxes // - ); + // + AddRef( + iBox, + waitingBoxes // + ); + } } + + // + Clean(obs); } - - // - Clean(obs); } // - // Using Fair Value Gaps ... - has = iState.HasFairValueGaps(); - if (has) + // Use Fair Value Gaps ... + if (mUseFairValueGaps) { // - XCFVG *fvgs[]; - count = iState.FilterFairValueGaps( - fvgs, - period, - XZONE_STATE_PASSED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_IGNORED, - false // - ); - - // - has = IsValidSize(count); + has = iState.HasFairValueGaps(); if (has) { // - for (int i = 0; i < count; i++) + XCFVG *fvgs[]; + count = iState.FilterFairValueGaps( + fvgs, + period, + XZONE_STATE_PASSED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_IGNORED, + false // + ); + + // + has = IsValidSize(count); + if (has) { // - XBoxZone iBox; - bool hasBox = ToBox( - iBox, - fvgs[i] // - ); - if (!hasBox) + for (int i = 0; i < count; i++) { // - iBox.Clean(); - continue; - } + XBoxZone iBox; + bool hasBox = ToBox( + iBox, + fvgs[i] // + ); + if (!hasBox) + { + // + iBox.Clean(); + continue; + } + + // + // Check Index in Waiting Boxes ... + idx = FindIndex( + iBox, + waitingBoxes // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + // Check Index in Inside Boxes ... + idx = FindIndex( + iBox, + insideBoxes // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + // Check Index in Breaked Boxes ... + idx = FindIndex( + iBox, + breakedBoxes // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + AddRef( + iBox, + waitingBoxes // + ); - // - // Check Index in Waiting Boxes ... - idx = FindIndex( - iBox, - waitingBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { // iBox.Clean(); - continue; } - - // - // Check Index in Inside Boxes ... - idx = FindIndex( - iBox, - insideBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - // Check Index in Breaked Boxes ... - idx = FindIndex( - iBox, - breakedBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - AddRef( - iBox, - waitingBoxes // - ); - - // - iBox.Clean(); } - } - // - Clean(fvgs); + // + Clean(fvgs); + } } // @@ -1380,6 +1405,469 @@ struct X121SMCStrategyXWZWorkingZone return result; } + // + bool DetectSenarioASignalBox( + XBoxZone &signalBox, + ENUM_X_DIRECTION &signalDir, + X121Conditions &decisionXConditions, + X121Conditions &analyseXConditions, + XC121SMCCycleHelper *decisionCycleHelper, + XCPOIDrawer *drawer = NULL, + int barIndex = 0 // + ) + { + // + bool result = false; + + // + signalBox.Clean(); + signalDir = X_DIRECTION_NONE; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + result = decisionCycleHelper != NULL; + if (!result) + { + return result; + } + + // + // Decision ... + double decisionBullishScore = 0; + double decisionBearishScore = 0; + decisionXConditions.GenerateScore( + decisionBullishScore, + decisionBearishScore // + ); + + // + // Analyse ... + double analyseBullishScore = 0; + double analyseBearishScore = 0; + analyseXConditions.GenerateScore( + analyseBullishScore, + analyseBearishScore // + ); + + // + // Score Conditions ... + double scoreMultiplier = 3; + bool isBullishScorePassed = + // + analyseBullishScore > (analyseBearishScore * scoreMultiplier) && + decisionBullishScore > (decisionBearishScore * scoreMultiplier) + // + ; + bool isBearishScorePassed = + // + analyseBearishScore > (analyseBullishScore * scoreMultiplier) && + decisionBearishScore > (decisionBullishScore * scoreMultiplier) + // + ; + + // + // Checking Other Conditions + + // + bool isCommonBullish = + // + decisionXConditions.isSarBullish && + decisionXConditions.isStrBullish && + decisionXConditions.isCheBullish && + decisionXConditions.isSMHKBullish && + decisionXConditions.isRawHKBullish && + decisionXConditions.isRawHKClosedOverSMHK + // + ; + + // + bool isCommonBearish = + // + decisionXConditions.isSarBearish && + decisionXConditions.isStrBearish && + decisionXConditions.isCheBearish && + decisionXConditions.isSMHKBearish && + decisionXConditions.isRawHKBearish && + decisionXConditions.isRawHKClosedUnderSMHK + // + ; + + // + // X3Ma ... + + // + // X3Ma Bullish ... + bool isX3MaBullish = + // + decisionXConditions.isX3MaBullishState && + decisionXConditions.isX3MaSwitchedToBullishOrdered && + decisionXConditions.x3maMidBuffer[1] > decisionXConditions.x3maSlowBuffer[1] + // + ; + + // + // X3Ma Bearish ... + bool isX3MaBearish = + // + decisionXConditions.isX3MaBearishState && + decisionXConditions.isX3MaSwitchedToBearishOrdered && + decisionXConditions.x3maMidBuffer[1] < decisionXConditions.x3maSlowBuffer[1] + // + ; + + // + bool isX3MaHasCondition = + (isX3MaBullish && + isCommonBullish && + isBullishScorePassed) || + (isX3MaBearish && + isCommonBearish && + isBearishScorePassed); + + // + // VWap ... + + // + // VWap Bullish ... + bool isVWapBullish = + // + decisionXConditions.isVWapBullishState && + decisionXConditions.isVWapSwitchedToBullishOrdered && + decisionXConditions.vwapMidBuffer[1] > decisionXConditions.vwapSlowBuffer[1] + // + ; + + // + // VWap Bearish ... + bool isVWapBearish = + // + decisionXConditions.isVWapBearishState && + decisionXConditions.isVWapSwitchedToBearishOrdered && + decisionXConditions.vwapMidBuffer[1] < decisionXConditions.vwapSlowBuffer[1] + // + ; + + // + bool isVWapHasCondition = + (isVWapBullish && + isBullishScorePassed) || + (isVWapBearish && + isBearishScorePassed); + + // + // Senario .... + // - a vale Under X3MA Slow when X3MA Bullish Ordered ... + + // + bool isX3MASenarioBBullish = + // + decisionXConditions.isX3MaBullishOrdered && + decisionXConditions.valesBuffer[1] < decisionXConditions.x3maSlowBuffer[1] && + decisionXConditions.valesBuffer[2] >= decisionXConditions.x3maSlowBuffer[2] + // + ; + if (isX3MASenarioBBullish) + { + } + + // + bool isX3MASenarioBBearish = + // + decisionXConditions.isX3MaBearishOrdered && + decisionXConditions.peaksBuffer[1] > decisionXConditions.x3maSlowBuffer[1] && + decisionXConditions.peaksBuffer[2] <= decisionXConditions.x3maSlowBuffer[2] + // + ; + if (isX3MASenarioBBearish) + { + } + + // + // Checking Other Conditions XWZ Reject on EMA 20 ... + + // + // Check Has Conditions ... + bool hasXConditions = + (isX3MaHasCondition || + isVWapHasCondition); + + // + result = hasXConditions; + if (!result) + { + return result; + } + + // + if (isX3MaHasCondition) + { + // + signalDir = + isX3MaBullish + ? X_DIRECTION_BULLISH + : isX3MaBearish + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + } + + // + if (isVWapHasCondition) + { + // + signalDir = + isVWapBullish + ? X_DIRECTION_BULLISH + : isVWapBearish + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + } + + // + // Creating SignalBox ... + + // + // Detect Box based on PV ... + bool hasSignalBox = decisionCycleHelper.GeneratePVBox( + signalBox, + barIndex // + ); + + // + result = + hasSignalBox && + signalDir == signalBox.dir; + + // + if (result) + { + // + XCBoxObject *iObj; + bool isCreated= drawer.DrawBox( + signalBox, + iObj // + ); + if (isCreated) + { + // + iObj.BoxWidth(1); + iObj.BoxColor(clrYellow); + iObj.BoxStyle(STYLE_SOLID); + } + + // + Print("Senario A ..."); + } + + // + return result; + } + + // + bool DetetctSenarioBSignalBox( + XBoxZone &signalBox, + ENUM_X_DIRECTION &signalDir, + X121Conditions &decisionXConditions, + X121Conditions &analyseXConditions, + XC121SMCCycleHelper *decisionCycleHelper, + int barIndex = 0 // + ) + { + // + bool result = false; + + // + signalBox.Clean(); + signalDir = X_DIRECTION_NONE; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + result = decisionCycleHelper != NULL; + if (!result) + { + return result; + } + + // + // Decision ... + double decisionBullishScore = 0; + double decisionBearishScore = 0; + decisionXConditions.GenerateScore( + decisionBullishScore, + decisionBearishScore // + ); + + // + // Analyse ... + double analyseBullishScore = 0; + double analyseBearishScore = 0; + analyseXConditions.GenerateScore( + analyseBullishScore, + analyseBearishScore // + ); + + // + // Score Conditions ... + double scoreMultiplier = 3; + bool isBullishScorePassed = + // + analyseBullishScore > (analyseBearishScore * scoreMultiplier) && + decisionBullishScore > (decisionBearishScore * scoreMultiplier) + // + ; + bool isBearishScorePassed = + // + analyseBearishScore > (analyseBullishScore * scoreMultiplier) && + decisionBearishScore > (decisionBullishScore * scoreMultiplier) + // + ; + + // + // Senario .... + // - a vale Under X3MA Slow when X3MA Bullish Ordered ... + + // + bool isX3MASenarioBBullish = + // + decisionXConditions.isX3MaBullishOrdered && + decisionXConditions.valesBuffer[1] < decisionXConditions.x3maSlowBuffer[1] && + decisionXConditions.valesBuffer[2] >= decisionXConditions.x3maSlowBuffer[2] + // + ; + if (isX3MASenarioBBullish) + { + } + + // + bool isX3MASenarioBBearish = + // + decisionXConditions.isX3MaBearishOrdered && + decisionXConditions.peaksBuffer[1] > decisionXConditions.x3maSlowBuffer[1] && + decisionXConditions.peaksBuffer[2] <= decisionXConditions.x3maSlowBuffer[2] + // + ; + if (isX3MASenarioBBearish) + { + } + + // + return result; + } + + // + bool HasInsideBox( + XBoxZone &box // + ) + { + // + bool result = false; + + // + int index = -1; + + // + result = box.IsValid(); + if (!result) + { + return result; + } + + // + int count = 0; + bool has = false; + + // + has = HasWaitingBoxes(); + if (has) + { + // + result = HasInsideBox( + index, + box, + waitingBoxes // + ); + } + + // + // Supply Zones ... + if (!result) + { + // + has = HasSupplyZones(); + if (has) + { + // + XBoxZone tmpBoxes[]; + count = ToBox( + supplyZones, + tmpBoxes // + ); + + // + has = IsValidSize(count); + if (has) + { + // + result = HasInsideBox( + index, + box, + tmpBoxes // + ); + } + + // + Clean(tmpBoxes); + } + } + + // + // Demand Zones ... + if (!result) + { + // + has = HasDemandZones(); + if (has) + { + // + XBoxZone tmpBoxes[]; + count = ToBox( + demandZones, + tmpBoxes // + ); + + // + has = IsValidSize(count); + if (has) + { + // + result = HasInsideBox( + index, + box, + tmpBoxes // + ); + } + + // + Clean(tmpBoxes); + } + } + + // + result = IsValidIndex(index); + + // + return result; + } + // void UpdateTo(datetime value = NULL) { diff --git a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 index 749cfda9..2f19ea79 100644 --- a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 @@ -763,7 +763,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // XTREND ... x121Inputs.xtrendInputs.showUpTrend = showAll || false; x121Inputs.xtrendInputs.showDownTrend = showAll || false; - x121Inputs.xtrendInputs.showOnlyTrendStart = showAll || false; + x121Inputs.xtrendInputs.showOnlyTrendStart = showAll || true; // // XPV ... @@ -775,26 +775,26 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // XHK ... // - x121Inputs.xhkInputs.drawRawXHKCandles = showAll || false; - x121Inputs.xhkInputs.drawSmoothedXHKCandles = showAll || false; + x121Inputs.xhkInputs.drawRawXHKCandles = showAll || true; + x121Inputs.xhkInputs.drawSmoothedXHKCandles = showAll || true; // // XATR ... - x121Inputs.xatrInputs.showATRUpper = showAll || false; - x121Inputs.xatrInputs.showATRLower = showAll || false; + x121Inputs.xatrInputs.showATRUpper = showAll || true; + x121Inputs.xatrInputs.showATRLower = showAll || true; // // XSTR ... - x121Inputs.xstrInputs.showStr = showAll || false; + x121Inputs.xstrInputs.showStr = showAll || true; x121Inputs.xstrInputs.showStrUpper = showAll || false; x121Inputs.xstrInputs.showStrLower = showAll || false; // // XCHE ... - x121Inputs.xcheInputs.showLE1 = showAll || false; - x121Inputs.xcheInputs.showLE2 = showAll || false; - x121Inputs.xcheInputs.showSE1 = showAll || false; - x121Inputs.xcheInputs.showSE2 = showAll || false; + x121Inputs.xcheInputs.showLE1 = showAll || true; + x121Inputs.xcheInputs.showLE2 = showAll || true; + x121Inputs.xcheInputs.showSE1 = showAll || true; + x121Inputs.xcheInputs.showSE2 = showAll || true; // // XDON ... @@ -805,9 +805,9 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // // XVWAP ... - x121Inputs.xvwapInputs.showVWapFast = showAll || false; - x121Inputs.xvwapInputs.showVWapMedium = showAll || false; - x121Inputs.xvwapInputs.showVWapSlow = showAll || false; + x121Inputs.xvwapInputs.showVWapFast = showAll || true; + x121Inputs.xvwapInputs.showVWapMedium = showAll || true; + x121Inputs.xvwapInputs.showVWapSlow = showAll || true; // // X3MA ...