/////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 X121 SMC Signal Class // ------------------------------------------------- // Name: // Description: provide all Global Guarding functions ... // // // Maintainer: // ------------ // Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) // ////////////////////////////////////////////////////// // // Global Properties ... #property library #property copyright "Copyright 2023, SaherElm IT Center" #property link "https://www.saherelm.ir" #property version "1.00" #property strict // // Imports ... #include "../Classes/x-121.smc.market.cycle.helper.class.mq5" #include "../Libraries/x-121.smc.lib.mq5" // XPriceZones x121SMCDecisionPriceZone; XPriceZones x121SMCAnalysePriceZone; XPriceZones x121SMCVerificationPriceZone; XConsolidationZone x121SMCConsolidationZone; bool DetectX121SMCGuards( string provider, // Provider ... X121SMCGuard &guards[], const XPosition &positions[], XC121SMCCycleHelper *triggerCycleHelper, XC121SMCCycleHelper *decisionCycleHelper, XC121SMCCycleHelper *analyseCycleHelper, XC121SMCCycleHelper *verificationCycleHelper, XC121SMCCycleHelper *consolidationCycleHelper, 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); if (!result) { return result; } // string symbol = triggerCycleHelper.GetSymbol(); ENUM_TIMEFRAMES period = triggerCycleHelper.GetPeriod(); // XPosition ownPositions[]; XPosition ownLongPositions[]; XPosition ownShortPositions[]; for (int i = 0; i < count; i++) { // XPosition iPosition = positions[i]; bool isOwn = iPosition .IsFiltersPassed( symbol, provider, NULL, X_POSITION_TYPE_ALL, iPosition.magic // ); if (isOwn) { // AddRef( iPosition, ownPositions // ); // bool isLong = IsLong(positions[i].type); if (isLong) { // AddRef( iPosition, ownLongPositions // ); } else { // AddRef( iPosition, ownShortPositions // ); } } } // count = ArraySize(ownPositions); // int longsCount = ArraySize(ownLongPositions); bool hasLongs = IsValidSize(longsCount); // int shortsCount = ArraySize(ownShortPositions); bool hasShorts = IsValidSize(shortsCount); // result = IsValidSize(count); if (!result) { // Clean(ownPositions); Clean(ownLongPositions); Clean(ownShortPositions); // x121SMCAnalysePriceZone.Clean(); x121SMCDecisionPriceZone.Clean(); x121SMCConsolidationZone.Clean(); x121SMCVerificationPriceZone.Clean(); // return result; } // // Here we Are Sure there is Positions to Guard ... // based on Current Provider ... // // Detect Required Data for Analyse Market to Guard Positions ... // int zIndex = 0; int cIndex = zIndex + 1; int pIndex = cIndex + 1; int ppIndex = pIndex + 1; // int loopback = 10; // XOHCL zBar; result = zBar.Init( symbol, period, zIndex // ); if (!result) { return result; } // XOHCL cBar; result = cBar.Init( symbol, period, cIndex // ); if (!result) { return result; } // XOHCL pBar; result = pBar.Init( symbol, period, pIndex // ); if (!result) { return result; } // double ask = GetAsk(symbol); double bid = GetBid(symbol); datetime cTime = TimeCurrent(); double points = GetPoints(symbol); // int swingLoopback = 3; double ll = cBar.FindLowest(swingLoopback, MODE_LOW); double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); double llDown = cBar.FindLowesttDown(swingLoopback); double hhUp = cBar.FindHighestUp(swingLoopback); // // Cycles Conditions ... // // Trigger ... ENUM_XPOI_EVENTS triggerPoiEvents[]; ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; X121SMCCycleConditions triggerConditions; result = triggerCycleHelper.GetConditions( triggerCycleEvents, triggerPoiEvents, triggerConditions, zIndex, loopback // ); if (!result) { return result; } // // Decision ... ENUM_XPOI_EVENTS decisionPoiEvents[]; ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; X121SMCCycleConditions decisionConditions; result = decisionCycleHelper.GetConditions( decisionCycleEvents, decisionPoiEvents, decisionConditions, zIndex, loopback // ); if (!result) { return result; } // // Analyse ... ENUM_XPOI_EVENTS analysePoiEvents[]; ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; X121SMCCycleConditions analyseConditions; result = analyseCycleHelper.GetConditions( analyseCycleEvents, analysePoiEvents, analyseConditions, zIndex, loopback // ); if (!result) { return result; } // // Verification ... ENUM_XPOI_EVENTS verificationPoiEvents[]; ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; X121SMCCycleConditions verificationConditions; result = verificationCycleHelper.GetConditions( verificationCycleEvents, verificationPoiEvents, verificationConditions, zIndex, loopback // ); if (!result) { return result; } // // Consolidation ... ENUM_XPOI_EVENTS consolidationPoiEvents[]; ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; X121SMCCycleConditions consolidationConditions; result = consolidationCycleHelper.GetConditions( consolidationCycleEvents, consolidationPoiEvents, consolidationConditions, zIndex, loopback // ); if (!result) { return result; } // // Vision ... ENUM_XPOI_EVENTS visionPoiEvents[]; ENUM_X_CYCLE_EVENTS visionCycleEvents[]; X121SMCCycleConditions visionConditions; result = visionCycleHelper.GetConditions( visionCycleEvents, visionPoiEvents, visionConditions, zIndex, loopback // ); if (!result) { return result; } // // Cycles POI States ... XPOIState triggerState = triggerConditions.state; XPOIState decisionState = decisionConditions.state; XPOIState analyseState = analyseConditions.state; XPOIState verificationState = verificationConditions.state; XPOIState consolidationState = consolidationConditions.state; XPOIState visionState = visionConditions.state; // // Cycle X121Conditions ... X121Conditions triggerXConditions = triggerConditions.x121Conditions; X121Conditions decisionXConditions = decisionConditions.x121Conditions; X121Conditions analyseXConditions = analyseConditions.x121Conditions; X121Conditions verificationXConditions = verificationConditions.x121Conditions; X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; X121Conditions visionXConditions = visionConditions.x121Conditions; // // Trigger ... ENUM_X_DIRECTION triggerTrendDir; bool hasTriggerTrend = triggerCycleHelper .DetectMarketStructure( triggerTrendDir // ); bool hasTriggerBullishTrend = hasTriggerTrend && IsBullish(triggerTrendDir); bool hasTriggerBearishTrend = hasTriggerTrend && IsBearish(triggerTrendDir); // // Decision ... ENUM_X_DIRECTION decisionTrendDir; bool hasDecisionTrend = decisionCycleHelper .DetectMarketStructure( decisionTrendDir // ); bool hasDecisionBullishTrend = hasDecisionTrend && IsBullish(decisionTrendDir); bool hasDecisionBearishTrend = hasDecisionTrend && IsBearish(decisionTrendDir); // // Analyse ... ENUM_X_DIRECTION analyseTrendDir; bool hasAnalyseTrend = analyseCycleHelper .DetectMarketStructure( analyseTrendDir // ); bool hasAnalyseBullishTrend = hasAnalyseTrend && IsBullish(analyseTrendDir); bool hasAnalyseBearishTrend = hasAnalyseTrend && IsBearish(analyseTrendDir); // // // // // Detect Consolidation Zone ... // int consolidationLoopback = 7; double consolidationZoneLower = 0; double consolidationZoneUpper = 0; bool isConsolidationZoneBreaked = false; bool isConsolidationZoneBreakedUp = false; bool isConsolidationZoneBreakedDown = false; bool hasConsolidationZone = x121SMCConsolidationZone.IsValid(); // if (!hasConsolidationZone) { // double upper = 0; double lower = 0; hasConsolidationZone = triggerCycleHelper .mBarAnalyser .IsConsolidate( cBar, upper, lower, consolidationLoopback // ); // if (hasConsolidationZone) { // hasConsolidationZone = x121SMCConsolidationZone.Init( cBar.symbol, cBar.period, upper, lower, consolidationLoopback // ); } } // if (hasConsolidationZone) { // x121SMCConsolidationZone.Update(); // consolidationZoneUpper = x121SMCConsolidationZone.upper; consolidationZoneLower = x121SMCConsolidationZone.lower; // isConsolidationZoneBreaked = x121SMCConsolidationZone.IsBreaked(); isConsolidationZoneBreakedUp = isConsolidationZoneBreaked && IsBullish(x121SMCConsolidationZone.breakDirection); isConsolidationZoneBreakedDown = isConsolidationZoneBreaked && IsBearish(x121SMCConsolidationZone.breakDirection); // consolidationZoneUpper = triggerXConditions.peaksBuffer[1]; consolidationZoneLower = triggerXConditions.valesBuffer[1]; // if (isConsolidationZoneBreaked) { x121SMCConsolidationZone.Clean(); } } // // Detect Price Zones ... // // Decision ... double decisionPriceZoneUpper = 0; double decisionPriceZoneLower = 0; bool isDecisionPriceZoneBearish = false; bool isDecisionPriceZoneBullish = false; bool isDecisionPriceZoneValidForPeak = false; bool isDecisionPriceZoneValidForVale = false; bool isDecisionPriceZoneLowerRejected = false; bool isDecisionPriceZoneUpperRejected = false; bool isDecisionPriceZoneUpperBreakedUp = false; bool isDecisionPriceZoneLowerBreakedDown = false; bool hasDecisionPriceZone = x121SMCDecisionPriceZone.IsValid(); // if (!hasDecisionPriceZone) { // hasDecisionPriceZone = CalculatePriceInsideZones( x121SMCDecisionPriceZone, decisionState, cBar // ); } // if (hasDecisionPriceZone) { // bool hasBoundary = x121SMCDecisionPriceZone.GetBoundary( X_DIRECTION_ALL, decisionPriceZoneUpper, decisionPriceZoneLower // ); // isDecisionPriceZoneBearish = x121SMCDecisionPriceZone.IsBearish(); isDecisionPriceZoneBullish = x121SMCDecisionPriceZone.IsBullish(); // XOHCL iBar; bool isInited = iBar.Init( symbol, decisionXConditions.period, cIndex // ); // if (hasBoundary) { // isDecisionPriceZoneValidForPeak = decisionXConditions.peaksBuffer[1] <= decisionPriceZoneUpper && decisionXConditions.peaksBuffer[1] >= decisionPriceZoneLower; // isDecisionPriceZoneValidForVale = decisionXConditions.valesBuffer[1] <= decisionPriceZoneUpper && decisionXConditions.valesBuffer[1] >= decisionPriceZoneLower; // isDecisionPriceZoneLowerRejected = isInited && IsBarReject( decisionPriceZoneLower, X_DIRECTION_BULLISH, iBar // ); // isDecisionPriceZoneUpperRejected = isInited && IsBarReject( decisionPriceZoneUpper, X_DIRECTION_BEARISH, iBar // ); // isDecisionPriceZoneUpperBreakedUp = isInited && IsBarBreak( decisionPriceZoneUpper, X_DIRECTION_BULLISH, iBar // ); // isDecisionPriceZoneLowerBreakedDown = isInited && IsBarBreak( decisionPriceZoneUpper, X_DIRECTION_BEARISH, iBar // ); } // // Clear Price Zone ... bool canReset = // (!isInited || !hasBoundary) // || // (isInited && hasBoundary && (iBar.high < decisionPriceZoneLower || iBar.low > decisionPriceZoneUpper)) // ; if (canReset) { // x121SMCDecisionPriceZone.Clean(); // decisionPriceZoneUpper = 0; decisionPriceZoneLower = 0; isDecisionPriceZoneBearish = false; isDecisionPriceZoneBullish = false; isDecisionPriceZoneValidForPeak = false; isDecisionPriceZoneValidForVale = false; isDecisionPriceZoneLowerRejected = false; isDecisionPriceZoneUpperRejected = false; isDecisionPriceZoneUpperBreakedUp = false; isDecisionPriceZoneLowerBreakedDown = false; } } // // Analyse ... double analysePriceZoneUpper = 0; double analysePriceZoneLower = 0; bool isAnalysePriceZoneBearish = false; bool isAnalysePriceZoneBullish = false; bool isAnalysePriceZoneValidForPeak = false; bool isAnalysePriceZoneValidForVale = false; bool isAnalysePriceZoneLowerRejected = false; bool isAnalysePriceZoneUpperRejected = false; bool isAnalysePriceZoneUpperBreakedUp = false; bool isAnalysePriceZoneLowerBreakedDown = false; bool hasAnalysePriceZone = x121SMCAnalysePriceZone.IsValid(); // if (!hasAnalysePriceZone) { // hasAnalysePriceZone = CalculatePriceInsideZones( x121SMCAnalysePriceZone, analyseState, cBar // ); } // if (hasAnalysePriceZone) { // bool hasBoundary = x121SMCAnalysePriceZone.GetBoundary( X_DIRECTION_ALL, analysePriceZoneUpper, analysePriceZoneLower // ); // isAnalysePriceZoneBearish = x121SMCAnalysePriceZone.IsBearish(); isAnalysePriceZoneBullish = x121SMCAnalysePriceZone.IsBullish(); // XOHCL iBar; bool isInited = iBar.Init( symbol, analyseXConditions.period, cIndex // ); // if (hasBoundary) { // isAnalysePriceZoneValidForPeak = analyseXConditions.peaksBuffer[1] <= analysePriceZoneUpper && analyseXConditions.peaksBuffer[1] >= analysePriceZoneLower; // isAnalysePriceZoneValidForVale = analyseXConditions.valesBuffer[1] <= analysePriceZoneUpper && analyseXConditions.valesBuffer[1] >= analysePriceZoneLower; // isAnalysePriceZoneLowerRejected = isInited && IsBarReject( analysePriceZoneLower, X_DIRECTION_BULLISH, iBar // ); // isAnalysePriceZoneUpperRejected = isInited && IsBarReject( analysePriceZoneUpper, X_DIRECTION_BEARISH, iBar // ); // isAnalysePriceZoneUpperBreakedUp = isInited && IsBarBreak( analysePriceZoneUpper, X_DIRECTION_BULLISH, iBar // ); // isAnalysePriceZoneLowerBreakedDown = isInited && IsBarBreak( analysePriceZoneUpper, X_DIRECTION_BEARISH, iBar // ); } // // Clear Price Zone ... bool canReset = // (!isInited || !hasBoundary) // || // (isInited && hasBoundary && (iBar.high < analysePriceZoneLower || iBar.low > analysePriceZoneUpper)) // ; if (canReset) { // x121SMCAnalysePriceZone.Clean(); // analysePriceZoneUpper = 0; analysePriceZoneLower = 0; isAnalysePriceZoneBearish = false; isAnalysePriceZoneBullish = false; isAnalysePriceZoneValidForPeak = false; isAnalysePriceZoneValidForVale = false; isAnalysePriceZoneLowerRejected = false; isAnalysePriceZoneUpperRejected = false; isAnalysePriceZoneUpperBreakedUp = false; isAnalysePriceZoneLowerBreakedDown = false; } } // // Verification ... double verificationPriceZoneUpper = 0; double verificationPriceZoneLower = 0; bool isVerificationPriceZoneBearish = false; bool isVerificationPriceZoneBullish = false; bool isVerificationPriceZoneValidForPeak = false; bool isVerificationPriceZoneValidForVale = false; bool isVerificationPriceZoneLowerRejected = false; bool isVerificationPriceZoneUpperRejected = false; bool isVerificationPriceZoneUpperBreakedUp = false; bool isVerificationPriceZoneLowerBreakedDown = false; bool hasVerificationPriceZone = x121SMCVerificationPriceZone.IsValid(); // if (!hasVerificationPriceZone) { // hasVerificationPriceZone = CalculatePriceInsideZones( x121SMCVerificationPriceZone, verificationState, cBar // ); } // if (hasVerificationPriceZone) { // bool hasBoundary = x121SMCVerificationPriceZone.GetBoundary( X_DIRECTION_ALL, verificationPriceZoneUpper, verificationPriceZoneLower // ); // isVerificationPriceZoneBearish = x121SMCVerificationPriceZone.IsBearish(); isVerificationPriceZoneBullish = x121SMCVerificationPriceZone.IsBullish(); // XOHCL iBar; bool isInited = iBar.Init( symbol, verificationXConditions.period, cIndex // ); // if (hasBoundary) { // isVerificationPriceZoneValidForPeak = verificationXConditions.peaksBuffer[1] <= verificationPriceZoneUpper && verificationXConditions.peaksBuffer[1] >= verificationPriceZoneLower; // isVerificationPriceZoneValidForVale = verificationXConditions.valesBuffer[1] <= verificationPriceZoneUpper && verificationXConditions.valesBuffer[1] >= verificationPriceZoneLower; // isVerificationPriceZoneLowerRejected = isInited && IsBarReject( verificationPriceZoneLower, X_DIRECTION_BULLISH, iBar // ); // isVerificationPriceZoneUpperRejected = isInited && IsBarReject( verificationPriceZoneUpper, X_DIRECTION_BEARISH, iBar // ); // isVerificationPriceZoneUpperBreakedUp = isInited && IsBarBreak( verificationPriceZoneUpper, X_DIRECTION_BULLISH, iBar // ); // isVerificationPriceZoneLowerBreakedDown = isInited && IsBarBreak( verificationPriceZoneUpper, X_DIRECTION_BEARISH, iBar // ); } // // Clear Price Zone ... bool canReset = // (!isInited || !hasBoundary) // || // (isInited && hasBoundary && (iBar.high < verificationPriceZoneLower || iBar.low > verificationPriceZoneUpper)) // ; if (canReset) { // x121SMCVerificationPriceZone.Clean(); // verificationPriceZoneUpper = 0; verificationPriceZoneLower = 0; isVerificationPriceZoneBearish = false; isVerificationPriceZoneBullish = false; isVerificationPriceZoneValidForPeak = false; isVerificationPriceZoneValidForVale = false; isVerificationPriceZoneLowerRejected = false; isVerificationPriceZoneUpperRejected = false; isVerificationPriceZoneUpperBreakedUp = false; isVerificationPriceZoneLowerBreakedDown = false; } } // // Here We Have all Requirements for Guarding Positions ... // // // // // Close ... if (!ignoreCloseOnTPNearGuard) { // double tpCloseDiff = (15 * points); for (int i = 0; i < count; i++) { // 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) { // 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 (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) { // if (!ignoreCloseShortsOnBullishTrendGuard) { // bool hasGuard = hasDecisionBullishTrend; // if (hasGuard) { // for (int i = 0; i < shortsCount; i++) { // 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 // ); } } } } // // Close All ... // // Close All Weekend ... if (!ignoreCloseAllWeekendGuard) { // MqlDateTime mDate; bool hasDate = TimeCurrent(mDate); if (hasDate) { // ENUM_X_WEEK_DAYS dayOfWeek = GetDayOfWeek(); // bool isWeekend = dayOfWeek == X_WEEK_DAY_FRIDAY; if (isWeekend && mDate.hour == 23 && mDate.min == 30) { // X121SMCGuard guard; // guard.time = cTime; guard.symbol = symbol; guard.provider = provider; guard.action = X_121_SMC_GUARD_ACTION_CLOSE_ALL; // AddGuard( guard, guards // ); } } } // // Close Longs ... if (hasLongs) { // bool hasGuard = // hasAnalyseBearishTrend && hasDecisionBearishTrend // ; // if (hasGuard) { // X121SMCGuard guard; // guard.time = cTime; guard.symbol = symbol; guard.provider = provider; guard.action = X_121_SMC_GUARD_ACTION_CLOSE_LONGS; // AddGuard( guard, guards // ); } } // // Close Shorts ... if (hasShorts) { // bool hasGuard = // hasAnalyseBullishTrend && hasDecisionBullishTrend // ; // if (hasGuard) { // X121SMCGuard guard; // guard.time = cTime; guard.symbol = symbol; guard.provider = provider; guard.action = X_121_SMC_GUARD_ACTION_CLOSE_SHORTS; // AddGuard( guard, guards // ); } } // // Partial Close ... // if (!ignorePartialCloseOnTrendChangeGuard) { // if (hasLongs) { // bool hasGuard = // hasTriggerBearishTrend || !hasDecisionBullishTrend // ; // if (hasGuard) { // for (int i = 0; i < longsCount; i++) { // XPosition iPosition = ownLongPositions[i]; // X121SMCGuard iGuard; // 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; // AddGuard( iGuard, guards // ); } } } // if (hasShorts) { // bool hasGuard = // hasTriggerBullishTrend || !hasDecisionBearishTrend // ; // if (hasGuard) { // for (int i = 0; i < shortsCount; i++) { // XPosition iPosition = ownShortPositions[i]; // X121SMCGuard iGuard; // 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; // AddGuard( iGuard, guards // ); } } } } // // Trail Stop ... if (!ignoreTrailStopGuard) { // if (hasLongs) { // 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) { // for (int i = 0; i < longsCount; i++) { // 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 (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) { // for (int i = 0; i < shortsCount; i++) { // 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 // ); } } } } // // Trail Target ... if (!ignoreTrailTargetGuard) { // if (hasLongs) { // bool hasAnalyseGuard = // (hasAnalysePriceZone && isAnalysePriceZoneValidForPeak && isAnalysePriceZoneUpperRejected) // ; // bool hasVerificationGuard = // (hasVerificationPriceZone && isVerificationPriceZoneValidForPeak && isVerificationPriceZoneUpperRejected) // ; // bool hasGuard = // hasAnalyseGuard || hasVerificationGuard // ; // double guardTP = hasAnalyseGuard ? analysePriceZoneUpper : hasVerificationGuard ? verificationPriceZoneUpper : 0; // if (hasGuard) { // for (int i = 0; i < longsCount; i++) { // 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 // ); } } } // 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) { // for (int i = 0; i < shortsCount; i++) { // 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 // ); } } } } // // Hedge ... if (!ignoreHedgeGuard) { } // // Cleanup Collections ... // Clean(ownPositions); Clean(ownLongPositions); Clean(ownShortPositions); // x121SMCAnalysePriceZone.Clean(); x121SMCDecisionPriceZone.Clean(); x121SMCConsolidationZone.Clean(); x121SMCVerificationPriceZone.Clean(); // // Release Arrays ... Clean(ownPositions); Clean(ownLongPositions); Clean(ownShortPositions); Clean(triggerPoiEvents); Clean(triggerCycleEvents); Clean(decisionPoiEvents); Clean(decisionCycleEvents); Clean(analysePoiEvents); Clean(analyseCycleEvents); Clean(verificationPoiEvents); Clean(verificationCycleEvents); Clean(consolidationPoiEvents); Clean(consolidationCycleEvents); Clean(visionPoiEvents); Clean(visionCycleEvents); // count = ArraySize(guards); result = IsValidSize(count); // return result; }