diff --git a/X121SMCEA/Libraries/x-121.smc.guard.lib.mq5 b/X121SMCEA/Libraries/x-121.smc.guard.lib.mq5 index 1050ca61..61495260 100644 --- a/X121SMCEA/Libraries/x-121.smc.guard.lib.mq5 +++ b/X121SMCEA/Libraries/x-121.smc.guard.lib.mq5 @@ -38,12 +38,42 @@ bool DetectX121SMCGuards( XC121SMCCycleHelper *analyseCycleHelper, XC121SMCCycleHelper *verificationCycleHelper, XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper // + XC121SMCCycleHelper *visionCycleHelper, + // + // Guard Types ... + bool ignoreCloseOnTPNearGuard = false, + bool ignoreCloseLongsOnBearishTrendGuard = false, + bool ignoreCloseShortsOnBullishTrendGuard = false, + bool ignoreCloseAllWeekendGuard = false, + bool ignorePartialCloseOnTrendChangeGuard = false, + bool ignoreTrailStopGuard = false, + bool ignoreTrailTargetGuard = false, + bool ignoreHedgeGuard = false + // ) { // bool result = false; + // + bool isAllIgnore = + // + ignoreCloseOnTPNearGuard && + ignoreCloseLongsOnBearishTrendGuard && + ignoreCloseShortsOnBullishTrendGuard && + ignoreCloseAllWeekendGuard && + ignorePartialCloseOnTrendChangeGuard && + ignoreTrailStopGuard && + ignoreTrailTargetGuard && + ignoreHedgeGuard + // + ; + result = !isAllIgnore; + if (!result) + { + return result; + } + // int count = ArraySize(positions); result = IsValidSize(count); @@ -116,6 +146,18 @@ bool DetectX121SMCGuards( result = IsValidSize(count); if (!result) { + // + Clean(ownPositions); + Clean(ownLongPositions); + Clean(ownShortPositions); + + // + x121SMCAnalysePriceZone.Clean(); + x121SMCDecisionPriceZone.Clean(); + x121SMCConsolidationZone.Clean(); + x121SMCVerificationPriceZone.Clean(); + + // return result; } @@ -353,7 +395,13 @@ bool DetectX121SMCGuards( IsBearish(analyseTrendDir); // - // Consolidation Zone ... + // + // + + // + // Detect Consolidation Zone ... + + // int consolidationLoopback = 7; double consolidationZoneLower = 0; double consolidationZoneUpper = 0; @@ -821,115 +869,78 @@ bool DetectX121SMCGuards( // // Here We Have all Requirements for Guarding Positions ... + // + // + // + // // Close ... - - // - double tpCloseDiff = (15 * points); - for (int i = 0; i < count; i++) + if (!ignoreCloseOnTPNearGuard) { // - XPosition iPosition = ownPositions[i]; - - // - // Position Must be In Profit ... - if (iPosition.profit <= 0) - { - continue; - } - - // - bool isPricePassed = MathAbs(iPosition.tp - iPosition.price) <= tpCloseDiff; - if (!isPricePassed) - { - continue; - } - - // - bool isLong = IsLong(iPosition.type); - - // - bool iHasGuard = - // - isLong - ? // - (hasDecisionPriceZone && - isDecisionPriceZoneBearish && - isDecisionPriceZoneValidForPeak) - // - || - // - (hasAnalysePriceZone && - isAnalysePriceZoneBearish && - isAnalysePriceZoneValidForPeak) - // - || - // - (hasVerificationPriceZone && - isVerificationPriceZoneBearish && - isVerificationPriceZoneValidForPeak) - : // - (hasDecisionPriceZone && - isDecisionPriceZoneBullish && - isDecisionPriceZoneValidForVale) - // - || - // - (hasAnalysePriceZone && - isAnalysePriceZoneBullish && - isAnalysePriceZoneValidForVale) - // - || - // - (hasVerificationPriceZone && - isVerificationPriceZoneBullish && - isVerificationPriceZoneValidForVale) - // - ; - if (iHasGuard) + double tpCloseDiff = (15 * points); + for (int i = 0; i < count; i++) { // - X121SMCGuard iGuard; + XPosition iPosition = ownPositions[i]; // - iGuard.time = cTime; - iGuard.symbol = symbol; - iGuard.provider = provider; - iGuard.action = X_121_SMC_GUARD_ACTION_CLOSE; - - // - iGuard.ticket = iPosition.ticket; - - // - AddGuard( - iGuard, - guards // - ); - } - } - - // - if (hasLongs) - { - // - bool hasGuard = hasDecisionBearishTrend; - - // - if (hasGuard) - { - // - for (int i = 0; i < longsCount; i++) + // Position Must be In Profit ... + if (iPosition.profit <= 0) { - // - XPosition iPosition = ownLongPositions[i]; + continue; + } - // - // Position must be in Draw Down ... - if (iPosition.profit > 0) - { - continue; - } + // + bool isPricePassed = MathAbs(iPosition.tp - iPosition.price) <= tpCloseDiff; + if (!isPricePassed) + { + continue; + } + // + bool isLong = IsLong(iPosition.type); + + // + bool iHasGuard = + // + isLong + ? // + (hasDecisionPriceZone && + isDecisionPriceZoneBearish && + isDecisionPriceZoneValidForPeak) + // + || + // + (hasAnalysePriceZone && + isAnalysePriceZoneBearish && + isAnalysePriceZoneValidForPeak) + // + || + // + (hasVerificationPriceZone && + isVerificationPriceZoneBearish && + isVerificationPriceZoneValidForPeak) + : // + (hasDecisionPriceZone && + isDecisionPriceZoneBullish && + isDecisionPriceZoneValidForVale) + // + || + // + (hasAnalysePriceZone && + isAnalysePriceZoneBullish && + isAnalysePriceZoneValidForVale) + // + || + // + (hasVerificationPriceZone && + isVerificationPriceZoneBullish && + isVerificationPriceZoneValidForVale) + // + ; + if (iHasGuard) + { // X121SMCGuard iGuard; @@ -951,45 +962,96 @@ bool DetectX121SMCGuards( } } + // + if (hasLongs) + { + // + if (!ignoreCloseLongsOnBearishTrendGuard) + { + // + bool hasGuard = hasDecisionBearishTrend; + + // + if (hasGuard) + { + // + for (int i = 0; i < longsCount; i++) + { + // + XPosition iPosition = ownLongPositions[i]; + + // + // Position must be in Draw Down ... + if (iPosition.profit > 0) + { + continue; + } + + // + X121SMCGuard iGuard; + + // + iGuard.time = cTime; + iGuard.symbol = symbol; + iGuard.provider = provider; + iGuard.action = X_121_SMC_GUARD_ACTION_CLOSE; + + // + iGuard.ticket = iPosition.ticket; + + // + AddGuard( + iGuard, + guards // + ); + } + } + } + } + // if (hasShorts) { // - bool hasGuard = hasDecisionBullishTrend; - - // - if (hasGuard) + if (!ignoreCloseShortsOnBullishTrendGuard) { // - for (int i = 0; i < shortsCount; i++) + bool hasGuard = hasDecisionBullishTrend; + + // + if (hasGuard) { // - XPosition iPosition = ownShortPositions[i]; - - // - // Position must be in Draw Down ... - if (iPosition.profit > 0) + for (int i = 0; i < shortsCount; i++) { - continue; + // + XPosition iPosition = ownShortPositions[i]; + + // + // Position must be in Draw Down ... + if (iPosition.profit > 0) + { + continue; + } + + // + X121SMCGuard iGuard; + + // + iGuard.time = cTime; + iGuard.symbol = symbol; + iGuard.provider = provider; + iGuard.action = X_121_SMC_GUARD_ACTION_CLOSE; + + // + iGuard.ticket = iPosition.ticket; + + // + AddGuard( + iGuard, + guards // + ); } - - // - X121SMCGuard iGuard; - - // - iGuard.time = cTime; - iGuard.symbol = symbol; - iGuard.provider = provider; - iGuard.action = X_121_SMC_GUARD_ACTION_CLOSE; - - // - iGuard.ticket = iPosition.ticket; - - // - AddGuard( - iGuard, - guards // - ); } } } @@ -998,31 +1060,36 @@ bool DetectX121SMCGuards( // Close All ... // - MqlDateTime mDate; - bool hasDate = TimeCurrent(mDate); - if (hasDate) + // Close All Weekend ... + if (!ignoreCloseAllWeekendGuard) { // - ENUM_X_WEEK_DAYS dayOfWeek = GetDayOfWeek(); - - // - bool isWeekend = dayOfWeek == X_WEEK_DAY_FRIDAY; - if (isWeekend && mDate.hour == 23 && mDate.min == 30) + MqlDateTime mDate; + bool hasDate = TimeCurrent(mDate); + if (hasDate) { // - X121SMCGuard guard; + ENUM_X_WEEK_DAYS dayOfWeek = GetDayOfWeek(); // - guard.time = cTime; - guard.symbol = symbol; - guard.provider = provider; - guard.action = X_121_SMC_GUARD_ACTION_CLOSE_ALL; + bool isWeekend = dayOfWeek == X_WEEK_DAY_FRIDAY; + if (isWeekend && mDate.hour == 23 && mDate.min == 30) + { + // + X121SMCGuard guard; - // - AddGuard( - guard, - guards // - ); + // + guard.time = cTime; + guard.symbol = symbol; + guard.provider = provider; + guard.action = X_121_SMC_GUARD_ACTION_CLOSE_ALL; + + // + AddGuard( + guard, + guards // + ); + } } } @@ -1094,492 +1161,516 @@ bool DetectX121SMCGuards( // Partial Close ... // - if (hasLongs) + if (!ignorePartialCloseOnTrendChangeGuard) { // - bool hasGuard = - // - hasTriggerBearishTrend || - !hasDecisionBullishTrend - // - ; - - // - if (hasGuard) + if (hasLongs) { // - for (int i = 0; i < longsCount; i++) + bool hasGuard = + // + hasTriggerBearishTrend || + !hasDecisionBullishTrend + // + ; + + // + if (hasGuard) { // - XPosition iPosition = ownLongPositions[i]; + for (int i = 0; i < longsCount; i++) + { + // + XPosition iPosition = ownLongPositions[i]; - // - X121SMCGuard iGuard; + // + X121SMCGuard iGuard; - // - iGuard.time = cTime; - iGuard.symbol = symbol; - iGuard.provider = provider; - iGuard.action = X_121_SMC_GUARD_ACTION_PARTIAL_CLOSE; + // + iGuard.time = cTime; + iGuard.symbol = symbol; + iGuard.provider = provider; + iGuard.action = X_121_SMC_GUARD_ACTION_PARTIAL_CLOSE; - // - iGuard.ticket = iPosition.ticket; - iGuard.volumeMultiplier = 0.5; + // + iGuard.ticket = iPosition.ticket; + iGuard.volumeMultiplier = 0.5; - // - AddGuard( - iGuard, - guards // - ); + // + AddGuard( + iGuard, + guards // + ); + } } } - } - - // - if (hasShorts) - { - // - bool hasGuard = - // - hasTriggerBullishTrend || - !hasDecisionBearishTrend - // - ; // - if (hasGuard) + if (hasShorts) { // - for (int i = 0; i < shortsCount; i++) + bool hasGuard = + // + hasTriggerBullishTrend || + !hasDecisionBearishTrend + // + ; + + // + if (hasGuard) { // - XPosition iPosition = ownShortPositions[i]; + for (int i = 0; i < shortsCount; i++) + { + // + XPosition iPosition = ownShortPositions[i]; - // - X121SMCGuard iGuard; + // + X121SMCGuard iGuard; - // - iGuard.time = cTime; - iGuard.symbol = symbol; - iGuard.provider = provider; - iGuard.action = X_121_SMC_GUARD_ACTION_PARTIAL_CLOSE; + // + iGuard.time = cTime; + iGuard.symbol = symbol; + iGuard.provider = provider; + iGuard.action = X_121_SMC_GUARD_ACTION_PARTIAL_CLOSE; - // - iGuard.ticket = iPosition.ticket; - iGuard.volumeMultiplier = 0.5; + // + iGuard.ticket = iPosition.ticket; + iGuard.volumeMultiplier = 0.5; - // - AddGuard( - iGuard, - guards // - ); + // + AddGuard( + iGuard, + guards // + ); + } } } } // // Trail Stop ... - - // - if (hasLongs) + if (!ignoreTrailStopGuard) { // - bool hasTrendGuard = hasDecisionBearishTrend; - - // - bool hasConsolidationGuard = - (hasConsolidationZone && - isConsolidationZoneBreaked && - isConsolidationZoneBreakedUp); - - // - bool hasDecisionPriceZoneGuard = - (hasDecisionPriceZone && - isDecisionPriceZoneBullish && - isDecisionPriceZoneValidForVale && - isDecisionPriceZoneUpperBreakedUp); - - // - bool hasAnalysePriceZoneGuard = - (hasAnalysePriceZone && - isAnalysePriceZoneBullish && - isAnalysePriceZoneValidForVale && - isAnalysePriceZoneUpperBreakedUp); - - // - bool hasVerificationPriceZoneGuard = - (hasVerificationPriceZone && - isVerificationPriceZoneBullish && - isVerificationPriceZoneValidForVale && - isVerificationPriceZoneUpperBreakedUp); - - // - bool hasGuard = - // - hasTrendGuard || - hasConsolidationGuard || - hasDecisionPriceZoneGuard || - hasAnalysePriceZoneGuard || - hasVerificationPriceZoneGuard - // - ; - - // - double guardStop = - hasConsolidationGuard - ? consolidationZoneLower - : hasDecisionPriceZoneGuard - ? decisionPriceZoneLower - : hasAnalysePriceZoneGuard - ? analysePriceZoneLower - : hasVerificationPriceZoneGuard - ? verificationPriceZoneLower - : 0; - - // - if (hasGuard) + if (hasLongs) { // - for (int i = 0; i < longsCount; i++) + bool hasTrendGuard = hasDecisionBearishTrend; + + // + bool hasConsolidationGuard = + (hasConsolidationZone && + isConsolidationZoneBreaked && + isConsolidationZoneBreakedUp); + + // + bool hasDecisionPriceZoneGuard = + (hasDecisionPriceZone && + isDecisionPriceZoneBullish && + isDecisionPriceZoneValidForVale && + isDecisionPriceZoneUpperBreakedUp); + + // + bool hasAnalysePriceZoneGuard = + (hasAnalysePriceZone && + isAnalysePriceZoneBullish && + isAnalysePriceZoneValidForVale && + isAnalysePriceZoneUpperBreakedUp); + + // + bool hasVerificationPriceZoneGuard = + (hasVerificationPriceZone && + isVerificationPriceZoneBullish && + isVerificationPriceZoneValidForVale && + isVerificationPriceZoneUpperBreakedUp); + + // + bool hasGuard = + // + hasTrendGuard || + hasConsolidationGuard || + hasDecisionPriceZoneGuard || + hasAnalysePriceZoneGuard || + hasVerificationPriceZoneGuard + // + ; + + // + double guardStop = + hasConsolidationGuard + ? consolidationZoneLower + : hasDecisionPriceZoneGuard + ? decisionPriceZoneLower + : hasAnalysePriceZoneGuard + ? analysePriceZoneLower + : hasVerificationPriceZoneGuard + ? verificationPriceZoneLower + : 0; + + // + if (hasGuard) { // - XPosition iPosition = ownLongPositions[i]; - - // - // Position Must Be In Profit ... - if (iPosition.profit <= 0) + for (int i = 0; i < longsCount; i++) { - continue; + // + XPosition iPosition = ownLongPositions[i]; + + // + // Position Must Be In Profit ... + if (iPosition.profit <= 0) + { + continue; + } + + // + if (hasTrendGuard) + { + guardStop = decisionXConditions.strBuffer[1] - decisionXConditions.atrBuffer[1]; + } + + // + // Price Must Greater than Zone Lower ... + if (iPosition.price < guardStop) + { + continue; + } + + // + // Position Entry Must Lesser than Zone Lower ... + if (iPosition.entry > guardStop) + { + continue; + } + + // + // Position SL must be Zero or Lesser than Zone Lower ... + if (iPosition.sl != 0 && + iPosition.sl > guardStop) + { + continue; + } + + // + X121SMCGuard iGuard; + + // + iGuard.time = cTime; + iGuard.symbol = symbol; + iGuard.provider = provider; + iGuard.action = X_121_SMC_GUARD_ACTION_TRAIL_STOP; + + // + iGuard.sl = guardStop; + iGuard.ticket = iPosition.ticket; + + // + AddGuard( + iGuard, + guards // + ); } - - // - if (hasTrendGuard) - { - guardStop = decisionXConditions.strBuffer[1] - decisionXConditions.atrBuffer[1]; - } - - // - // Price Must Greater than Zone Lower ... - if (iPosition.price < guardStop) - { - continue; - } - - // - // Position Entry Must Lesser than Zone Lower ... - if (iPosition.entry > guardStop) - { - continue; - } - - // - // Position SL must be Zero or Lesser than Zone Lower ... - if (iPosition.sl != 0 && - iPosition.sl > guardStop) - { - continue; - } - - // - X121SMCGuard iGuard; - - // - iGuard.time = cTime; - iGuard.symbol = symbol; - iGuard.provider = provider; - iGuard.action = X_121_SMC_GUARD_ACTION_TRAIL_STOP; - - // - iGuard.sl = guardStop; - iGuard.ticket = iPosition.ticket; - - // - AddGuard( - iGuard, - guards // - ); } } - } - - // - if (hasShorts) - { - // - bool hasTrendGuard = hasDecisionBullishTrend; // - bool hasConsolidationGuard = - (hasConsolidationZone && - isConsolidationZoneBreaked && - isConsolidationZoneBreakedDown); - - // - bool hasDecisionPriceZoneGuard = - (hasDecisionPriceZone && - isDecisionPriceZoneBearish && - isDecisionPriceZoneValidForPeak && - isDecisionPriceZoneLowerBreakedDown); - - // - bool hasAnalysePriceZoneGuard = - (hasAnalysePriceZone && - isAnalysePriceZoneBearish && - isAnalysePriceZoneValidForPeak && - isAnalysePriceZoneLowerBreakedDown); - - // - bool hasVerificationPriceZoneGuard = - (hasVerificationPriceZone && - isVerificationPriceZoneBearish && - isVerificationPriceZoneValidForPeak && - isVerificationPriceZoneLowerBreakedDown); - - // - bool hasGuard = - // - hasTrendGuard || - hasConsolidationGuard || - hasDecisionPriceZoneGuard || - hasAnalysePriceZoneGuard || - hasVerificationPriceZoneGuard - // - ; - - // - double guardStop = - hasConsolidationGuard - ? consolidationZoneUpper - : hasDecisionPriceZoneGuard - ? decisionPriceZoneUpper - : hasAnalysePriceZoneGuard - ? analysePriceZoneUpper - : hasVerificationPriceZoneGuard - ? verificationPriceZoneUpper - : 0; - - // - if (hasGuard) + if (hasShorts) { // - for (int i = 0; i < shortsCount; i++) + bool hasTrendGuard = hasDecisionBullishTrend; + + // + bool hasConsolidationGuard = + (hasConsolidationZone && + isConsolidationZoneBreaked && + isConsolidationZoneBreakedDown); + + // + bool hasDecisionPriceZoneGuard = + (hasDecisionPriceZone && + isDecisionPriceZoneBearish && + isDecisionPriceZoneValidForPeak && + isDecisionPriceZoneLowerBreakedDown); + + // + bool hasAnalysePriceZoneGuard = + (hasAnalysePriceZone && + isAnalysePriceZoneBearish && + isAnalysePriceZoneValidForPeak && + isAnalysePriceZoneLowerBreakedDown); + + // + bool hasVerificationPriceZoneGuard = + (hasVerificationPriceZone && + isVerificationPriceZoneBearish && + isVerificationPriceZoneValidForPeak && + isVerificationPriceZoneLowerBreakedDown); + + // + bool hasGuard = + // + hasTrendGuard || + hasConsolidationGuard || + hasDecisionPriceZoneGuard || + hasAnalysePriceZoneGuard || + hasVerificationPriceZoneGuard + // + ; + + // + double guardStop = + hasConsolidationGuard + ? consolidationZoneUpper + : hasDecisionPriceZoneGuard + ? decisionPriceZoneUpper + : hasAnalysePriceZoneGuard + ? analysePriceZoneUpper + : hasVerificationPriceZoneGuard + ? verificationPriceZoneUpper + : 0; + + // + if (hasGuard) { // - XPosition iPosition = ownShortPositions[i]; - - // - // Position Must Be In Profit ... - if (iPosition.profit <= 0) + for (int i = 0; i < shortsCount; i++) { - continue; + // + XPosition iPosition = ownShortPositions[i]; + + // + // Position Must Be In Profit ... + if (iPosition.profit <= 0) + { + continue; + } + + // + if (hasTrendGuard) + { + guardStop = decisionXConditions.strBuffer[1] + decisionXConditions.atrBuffer[1]; + } + + // + // Price Must Lesser than Zone Upper ... + if (iPosition.price > guardStop) + { + continue; + } + + // + // Position Entry Must Greater than Zone Upper ... + if (iPosition.entry < guardStop) + { + continue; + } + + // + // Position SL must be Zero or Greater than Zone Upper ... + if (iPosition.sl != 0 && + iPosition.sl < guardStop) + { + continue; + } + + // + X121SMCGuard iGuard; + + // + iGuard.time = cTime; + iGuard.symbol = symbol; + iGuard.provider = provider; + iGuard.action = X_121_SMC_GUARD_ACTION_TRAIL_STOP; + + // + iGuard.sl = guardStop; + iGuard.ticket = iPosition.ticket; + + // + AddGuard( + iGuard, + guards // + ); } - - // - if (hasTrendGuard) - { - guardStop = decisionXConditions.strBuffer[1] + decisionXConditions.atrBuffer[1]; - } - - // - // Price Must Lesser than Zone Upper ... - if (iPosition.price > guardStop) - { - continue; - } - - // - // Position Entry Must Greater than Zone Upper ... - if (iPosition.entry < guardStop) - { - continue; - } - - // - // Position SL must be Zero or Greater than Zone Upper ... - if (iPosition.sl != 0 && - iPosition.sl < guardStop) - { - continue; - } - - // - X121SMCGuard iGuard; - - // - iGuard.time = cTime; - iGuard.symbol = symbol; - iGuard.provider = provider; - iGuard.action = X_121_SMC_GUARD_ACTION_TRAIL_STOP; - - // - iGuard.sl = guardStop; - iGuard.ticket = iPosition.ticket; - - // - AddGuard( - iGuard, - guards // - ); } } } // // Trail Target ... - - // - if (hasLongs) + if (!ignoreTrailTargetGuard) { // - bool hasAnalyseGuard = - // - (hasAnalysePriceZone && - isAnalysePriceZoneValidForPeak && - isAnalysePriceZoneUpperRejected) - // - ; - - // - bool hasVerificationGuard = - // - (hasVerificationPriceZone && - isVerificationPriceZoneValidForPeak && - isVerificationPriceZoneUpperRejected) - // - ; - - // - bool hasGuard = - // - hasAnalyseGuard || - hasVerificationGuard - // - ; - - // - double guardTP = - hasAnalyseGuard - ? analysePriceZoneUpper - : hasVerificationGuard - ? verificationPriceZoneUpper - : 0; - - // - if (hasGuard) + if (hasLongs) { // - for (int i = 0; i < longsCount; i++) + bool hasAnalyseGuard = + // + (hasAnalysePriceZone && + isAnalysePriceZoneValidForPeak && + isAnalysePriceZoneUpperRejected) + // + ; + + // + bool hasVerificationGuard = + // + (hasVerificationPriceZone && + isVerificationPriceZoneValidForPeak && + isVerificationPriceZoneUpperRejected) + // + ; + + // + bool hasGuard = + // + hasAnalyseGuard || + hasVerificationGuard + // + ; + + // + double guardTP = + hasAnalyseGuard + ? analysePriceZoneUpper + : hasVerificationGuard + ? verificationPriceZoneUpper + : 0; + + // + if (hasGuard) { // - XPosition iPosition = ownLongPositions[i]; - - // - // Position Must Be In Profit ... - if (iPosition.profit <= 0) + for (int i = 0; i < longsCount; i++) { - continue; + // + XPosition iPosition = ownLongPositions[i]; + + // + // Position Must Be In Profit ... + if (iPosition.profit <= 0) + { + continue; + } + + // + X121SMCGuard iGuard; + + // + iGuard.time = cTime; + iGuard.symbol = symbol; + iGuard.provider = provider; + iGuard.action = X_121_SMC_GUARD_ACTION_TRAIL_TARGET; + + // + iGuard.tp = guardTP; + iGuard.ticket = iPosition.ticket; + + // + AddGuard( + iGuard, + guards // + ); } - - // - X121SMCGuard iGuard; - - // - iGuard.time = cTime; - iGuard.symbol = symbol; - iGuard.provider = provider; - iGuard.action = X_121_SMC_GUARD_ACTION_TRAIL_TARGET; - - // - iGuard.tp = guardTP; - iGuard.ticket = iPosition.ticket; - - // - AddGuard( - iGuard, - guards // - ); } } - } - - // - if (hasShorts) - { - // - bool hasAnalyseGuard = - // - (hasAnalysePriceZone && - isAnalysePriceZoneValidForVale && - isAnalysePriceZoneLowerRejected) - // - ; // - bool hasVerificationGuard = - // - (hasVerificationPriceZone && - isVerificationPriceZoneValidForVale && - isVerificationPriceZoneLowerRejected) - // - ; - - // - bool hasGuard = - // - hasAnalyseGuard || - hasVerificationGuard - // - ; - - // - double guardTP = - hasAnalyseGuard - ? analysePriceZoneLower - : hasVerificationGuard - ? verificationPriceZoneLower - : 0; - - // - if (hasGuard) + if (hasShorts) { // - for (int i = 0; i < shortsCount; i++) + bool hasAnalyseGuard = + // + (hasAnalysePriceZone && + isAnalysePriceZoneValidForVale && + isAnalysePriceZoneLowerRejected) + // + ; + + // + bool hasVerificationGuard = + // + (hasVerificationPriceZone && + isVerificationPriceZoneValidForVale && + isVerificationPriceZoneLowerRejected) + // + ; + + // + bool hasGuard = + // + hasAnalyseGuard || + hasVerificationGuard + // + ; + + // + double guardTP = + hasAnalyseGuard + ? analysePriceZoneLower + : hasVerificationGuard + ? verificationPriceZoneLower + : 0; + + // + if (hasGuard) { // - XPosition iPosition = ownShortPositions[i]; - - // - // Position Must Be In Profit ... - if (iPosition.profit <= 0) + for (int i = 0; i < shortsCount; i++) { - continue; + // + XPosition iPosition = ownShortPositions[i]; + + // + // Position Must Be In Profit ... + if (iPosition.profit <= 0) + { + continue; + } + + // + X121SMCGuard iGuard; + + // + iGuard.time = cTime; + iGuard.symbol = symbol; + iGuard.provider = provider; + iGuard.action = X_121_SMC_GUARD_ACTION_TRAIL_TARGET; + + // + iGuard.tp = guardTP; + iGuard.ticket = iPosition.ticket; + + // + AddGuard( + iGuard, + guards // + ); } - - // - X121SMCGuard iGuard; - - // - iGuard.time = cTime; - iGuard.symbol = symbol; - iGuard.provider = provider; - iGuard.action = X_121_SMC_GUARD_ACTION_TRAIL_TARGET; - - // - iGuard.tp = guardTP; - iGuard.ticket = iPosition.ticket; - - // - AddGuard( - iGuard, - guards // - ); } } } // // Hedge ... - // TODO: Implement Hedge ... + if (!ignoreHedgeGuard) + { + } + + // + // Cleanup Collections ... + + // + Clean(ownPositions); + Clean(ownLongPositions); + Clean(ownShortPositions); + + // + x121SMCAnalysePriceZone.Clean(); + x121SMCDecisionPriceZone.Clean(); + x121SMCConsolidationZone.Clean(); + x121SMCVerificationPriceZone.Clean(); // // Release Arrays ... diff --git a/X121SMCEA/Signals/x-121.smc.x.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.x.signal.lib.mq5 index 7bf44dc1..cb1c6af3 100644 --- a/X121SMCEA/Signals/x-121.smc.x.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.x.signal.lib.mq5 @@ -1573,7 +1573,7 @@ bool DetectX121SMCXSignalTrigger( // Cleanup Arrays ... ArrayFree(decisionPoiEvents); ArrayFree(decisionCycleEvents); - + // return result; } @@ -1597,17 +1597,27 @@ bool DetectX121SMCXGuards( string provider = ToString(X_121_SMC_PROVIDER_X); // - // result = DetectX121SMCGuards( - // provider, - // guards, - // positions, - // triggerCycleHelper, - // decisionCycleHelper, - // analyseCycleHelper, - // verificationCycleHelper, - // consolidationCycleHelper, - // visionCycleHelper // - // ); + result = DetectX121SMCGuards( + provider, + guards, + positions, + triggerCycleHelper, + decisionCycleHelper, + analyseCycleHelper, + verificationCycleHelper, + consolidationCycleHelper, + visionCycleHelper, + // + true, // CloseOnTPNear Guard ... + true, // CloseLongsOnBearishTrend Guard ... + true, // CloseShortsOnBullishTrend Guard ... + true, // CloseAllWeekend Guard ... + true, // PartialCloseOnTrendChange Guard ... + true, // TrailStop Guard ... + true, // TrailTarget Guard ... + true // Hedge Guard ... + // + ); // return result; diff --git a/X121SMCEA/Signals/x-121.smc.xobpv.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xobpv.signal.lib.mq5 index 8bf0d0c5..0fdf1c01 100644 --- a/X121SMCEA/Signals/x-121.smc.xobpv.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xobpv.signal.lib.mq5 @@ -1359,7 +1359,7 @@ bool DetectX121SMCXOBPVSignalTrigger( // Cleanup Arrays ... ArrayFree(decisionPoiEvents); ArrayFree(decisionCycleEvents); - + // return result; } @@ -1383,17 +1383,27 @@ bool DetectX121SMCXOBPVGuards( string provider = ToString(X_121_SMC_PROVIDER_X); // - // result = DetectX121SMCGuards( - // provider, - // guards, - // positions, - // triggerCycleHelper, - // decisionCycleHelper, - // analyseCycleHelper, - // verificationCycleHelper, - // consolidationCycleHelper, - // visionCycleHelper // - // ); + result = DetectX121SMCGuards( + provider, + guards, + positions, + triggerCycleHelper, + decisionCycleHelper, + analyseCycleHelper, + verificationCycleHelper, + consolidationCycleHelper, + visionCycleHelper, + // + true, // CloseOnTPNear Guard ... + true, // CloseLongsOnBearishTrend Guard ... + true, // CloseShortsOnBullishTrend Guard ... + true, // CloseAllWeekend Guard ... + true, // PartialCloseOnTrendChange Guard ... + true, // TrailStop Guard ... + true, // TrailTarget Guard ... + true // Hedge Guard ... + // + ); // return result;