From 6363320cc24e9c212f16e507e425b16153770453 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Sun, 19 Jan 2025 10:23:20 +0330 Subject: [PATCH] last ... --- .../Signals/x-121.smc.xpz.signal.lib.mq5 | 337 +++++++++++++++++- .../Signals/x-121.smc.xrspvi.signal.lib.mq5 | 6 +- .../Signals/x-121.smc.xstrpv.signal.lib.mq5 | 327 +++++++++++++++++ 3 files changed, 655 insertions(+), 15 deletions(-) diff --git a/X121SMCEA/Signals/x-121.smc.xpz.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xpz.signal.lib.mq5 index 4a386201..8feb3f32 100644 --- a/X121SMCEA/Signals/x-121.smc.xpz.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xpz.signal.lib.mq5 @@ -58,6 +58,9 @@ struct X121SMCStrategyXPZSignalConditions bool isPriceZoneValidForPeak; bool isPriceZoneValidForVale; + // + XPVPivot pivotZone; + // // Constructor ... X121SMCStrategyXPZSignalConditions() @@ -178,6 +181,7 @@ struct X121SMCStrategyXPZSignalConditions // priceZone.Clean(); + pivotZone.Clean(); isPriceZoneValidForPeak = false; isPriceZoneValidForVale = false; } @@ -190,6 +194,13 @@ struct X121SMCStrategyXPZSignalConditions X121SMCStrategyXPZSignalConditions mXPZConditions; X121SMCStrategyXPZSignalConditions mXPZConditionsCollection[]; +// +double X121SMCXPZPivotPeak; +double X121SMCXPZPivotVale; +datetime X121SMCXPZPivotEnd; +datetime X121SMCXPZPivotStart; +ENUM_XPV_PIVOTS X121SMCXPZPivotType = XPV_NONE; + // // Extension Functions ... @@ -415,12 +426,6 @@ bool DetectX121SMCXPZSiganlSetup( // // Consolidation ... - // - if (decisionXConditions.isTrendSwirchedToBearish) - { - Print("Trend Switced To Bearish ..."); - } - // bool hasConsolidationBullishTrend = consolidationXConditions.isTrendBullish; bool hasConsolidationBearishTrend = consolidationXConditions.isTrendBearish; @@ -536,6 +541,314 @@ bool DetectX121SMCXPZSiganlSetup( // ; + // + // Detect PV Pivot ... + + // + bool isPivotPeakZoneRejected = false; + bool isPivotPeakZoneBreakedUp = false; + bool isPivotPeakZoneBreakedDown = false; + bool isPivotValeZoneRejected = false; + bool isPivotValeZoneBreakedUp = false; + bool isPivotValeZoneBreakedDown = false; + bool hasPivot = conditions.pivotZone.IsValid(); + if (!hasPivot) + { + // + hasPivot = IsValid(X121SMCXPZPivotStart); + if (!hasPivot) + { + // + bool isNewVale = decisionXConditions.isNewVale; + bool isNewValeOverLast = decisionXConditions.isNewValeOverLast; + bool isNewValeUnderLast = decisionXConditions.isNewValeUnderLast; + bool isSameVales = decisionXConditions.valesBuffer[1] == + decisionXConditions.valesBuffer[2] && + decisionXConditions.valesBuffer[2] == + decisionXConditions.valesBuffer[3]; + bool isSameCycleVales = decisionXConditions.valesBuffer[1] == + analyseXConditions.valesBuffer[1] && + analyseXConditions.valesBuffer[1] == + verificationXConditions.valesBuffer[1]; + + // + bool isNewPeak = decisionXConditions.isNewPeak; + bool isNewPeakOverLast = decisionXConditions.isNewPeakOverLast; + bool isNewPeakUnderLast = decisionXConditions.isNewPeakUnderLast; + bool isSamePeaks = decisionXConditions.peaksBuffer[1] == + decisionXConditions.peaksBuffer[2] && + decisionXConditions.peaksBuffer[2] == + decisionXConditions.peaksBuffer[3]; + bool isSameCyclePeaks = decisionXConditions.peaksBuffer[1] == + analyseXConditions.peaksBuffer[1] && + analyseXConditions.peaksBuffer[1] == + verificationXConditions.peaksBuffer[1]; + + // + bool isValeStart = + // isSameVales; + isSameVales && + isSameCycleVales; + bool isPeakStart = + // isSamePeaks; + isSamePeaks && + isSameCyclePeaks; + + // + bool isStart = isPeakStart || + isValeStart; + if (isStart) + { + // + X121SMCXPZPivotStart = cTime; + X121SMCXPZPivotType = + isPeakStart + ? XPV_PEAK + : XPV_VALE; + + // + X121SMCXPZPivotPeak = decisionXConditions.peaksBuffer[1]; + X121SMCXPZPivotVale = decisionXConditions.valesBuffer[1]; + } + + // + hasPivot = IsValid(X121SMCXPZPivotStart); + + // + // Create XPVPivot instance ... + if (hasPivot) + { + // + conditions.pivotZone.symbol = symbol; + conditions.pivotZone.period = period; + + // + conditions.pivotZone.to = cTime; + conditions.pivotZone.repetition = 3; + + // + conditions.pivotZone.upper = X121SMCXPZPivotPeak; + conditions.pivotZone.lower = X121SMCXPZPivotVale; + + // + conditions.pivotZone.type = X121SMCXPZPivotType; + conditions.pivotZone.from = X121SMCXPZPivotStart; + } + } + } + + // + if (hasPivot) + { + // + bool isBreaked = X121SMCXPZPivotType == XPV_PEAK + ? decisionXConditions.isBreakedUpPrevPeak + : decisionXConditions.isBreakedDownPrevVale; + + // + if (!isBreaked) + { + // + X121SMCXPZPivotPeak = decisionXConditions.peaksBuffer[1]; + X121SMCXPZPivotVale = decisionXConditions.valesBuffer[1]; + + // + conditions.pivotZone.to = cTime; + conditions.pivotZone.repetition++; + conditions.pivotZone.upper = X121SMCXPZPivotPeak; + conditions.pivotZone.lower = X121SMCXPZPivotVale; + } + else + { + // + X121SMCXPZPivotEnd = cTime; + conditions.pivotZone.to = cTime; + } + + // + // Fill Pivot State ... + + // + XPOIState analysePivotState; + DetectPivotPOIs( + conditions.pivotZone, + analyseState, + analysePivotState // + ); + + // + XPOIState decisionPivotState; + DetectPivotPOIs( + conditions.pivotZone, + decisionState, + decisionPivotState // + ); + + // + // Combine two State ... + XPOIState combinedPivotState; + XPOIState iStates[]; + AddRef( + analysePivotState, + iStates // + ); + AddRef( + decisionPivotState, + iStates // + ); + CombineStates( + combinedPivotState, + iStates // + ); + combinedPivotState = decisionPivotState; + + // + ArrayFree(iStates); + + // + combinedPivotState.time = decisionPivotState.time; + combinedPivotState.symbol = decisionPivotState.symbol; + combinedPivotState.period = decisionPivotState.period; + + // + // Hold Only Areas Which on Upper or Lower bondary of Pivot Zone ... + FilterPivotState( + conditions.pivotZone, + combinedPivotState // + ); + + // + conditions.pivotZone.state = combinedPivotState; + + // + double peakUpper = 0; + double peakLower = 0; + double valeUpper = 0; + double valeLower = 0; + + // + datetime peakTo = NULL; + datetime valeTo = NULL; + datetime peakFrom = NULL; + datetime valeFrom = NULL; + + // + bool hasBoxData = DetectPivotStateBoxData( + conditions.pivotZone, + peakUpper, + peakLower, + peakFrom, + peakTo, + valeUpper, + valeLower, + valeFrom, + valeTo // + ); + + // + // Calculate Pivot Tick Zones ... + + // + int ticksLevels = decisionCycleHelper + .mPOIDetector + .TicksRangeZoneLevel(); + int ticksRange = decisionCycleHelper + .mPOIDetector + .TicksRangeZoneRange(); + + // + CalculatePivotTickZone( + conditions.pivotZone, + ticksLevels, + ticksRange // + ); + + // + isPivotPeakZoneRejected = + hasBoxData && + ( + // + IsBarReject( + peakLower, + X_DIRECTION_BEARISH, + cBar // + ) + // + || + // + IsBarReject( + peakUpper, + X_DIRECTION_BEARISH, + cBar // + ) + // + ); + isPivotPeakZoneBreakedUp = + hasBoxData && + IsBarBreak( + peakUpper, + X_DIRECTION_BULLISH, + cBar // + ); + isPivotPeakZoneBreakedDown = + hasBoxData && + IsBarBreak( + peakLower, + X_DIRECTION_BEARISH, + cBar // + ); + + // + isPivotValeZoneRejected = + hasBoxData && + ( + // + IsBarReject( + valeLower, + X_DIRECTION_BULLISH, + cBar // + ) + // + || + // + IsBarReject( + valeUpper, + X_DIRECTION_BULLISH, + cBar // + ) + // + ); + isPivotValeZoneBreakedUp = + hasBoxData && + IsBarBreak( + valeUpper, + X_DIRECTION_BULLISH, + cBar // + ); + isPivotValeZoneBreakedDown = + hasBoxData && + IsBarBreak( + valeLower, + X_DIRECTION_BEARISH, + cBar // + ); + } + + // + bool isPivotEnded = IsValid(X121SMCXPZPivotEnd); + if (isPivotEnded) + { + // + X121SMCXPZPivotPeak = 0; + X121SMCXPZPivotVale = 0; + X121SMCXPZPivotEnd = NULL; + X121SMCXPZPivotStart = NULL; + X121SMCXPZPivotType = XPV_NONE; + + // + conditions.pivotZone.Clean(); + } + // // Detect Price Zone ... @@ -676,6 +989,8 @@ bool DetectX121SMCXPZSiganlSetup( // bool isPriceZoneBullish = + // + hasPivot && // hasVerificationBullishTrend && hasAnalyseBullishTrend && @@ -688,14 +1003,14 @@ bool DetectX121SMCXPZSiganlSetup( isCBarBullishFormed && isInDecisionDiscount && decisionXConditions.isAtrLowerUnderVale && - decisionXConditions.isAtrLowerSlopeBullish && - // - true + decisionXConditions.isAtrLowerSlopeBullish // ; // bool isPriceZoneBearish = + // + hasPivot && // hasVerificationBearishTrend && hasAnalyseBearishTrend && @@ -708,9 +1023,7 @@ bool DetectX121SMCXPZSiganlSetup( isInDecisionPremium && isCBarBearishFormed && decisionXConditions.isAtrUpperOverPeak && - decisionXConditions.isAtrUpperSlopeBearish && - // - true + decisionXConditions.isAtrUpperSlopeBearish // ; diff --git a/X121SMCEA/Signals/x-121.smc.xrspvi.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xrspvi.signal.lib.mq5 index 1339ceb1..8c83cdb4 100644 --- a/X121SMCEA/Signals/x-121.smc.xrspvi.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xrspvi.signal.lib.mq5 @@ -214,9 +214,6 @@ struct X121SMCStrategyXRSPVISignalConditions X121SMCStrategyXRSPVISignalConditions mXRSPVIConditions; X121SMCStrategyXRSPVISignalConditions mXRSPVIConditionsCollection[]; -// -// Extension Functions ... - // double X121SMCXRSPVIPivotPeak; double X121SMCXRSPVIPivotVale; @@ -224,6 +221,9 @@ datetime X121SMCXRSPVIPivotEnd; datetime X121SMCXRSPVIPivotStart; ENUM_XPV_PIVOTS X121SMCXRSPVIPivotType = XPV_NONE; +// +// Extension Functions ... + // // Detect Setup Conditions ... bool DetectX121SMCXRSPVISiganlSetup( diff --git a/X121SMCEA/Signals/x-121.smc.xstrpv.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xstrpv.signal.lib.mq5 index 9611e159..19c749b6 100644 --- a/X121SMCEA/Signals/x-121.smc.xstrpv.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xstrpv.signal.lib.mq5 @@ -56,6 +56,9 @@ struct X121SMCStrategyXSTRPVSignalConditions bool isPriceZoneValidForPeak; bool isPriceZoneValidForVale; + // + XPVPivot pivotZone; + // // Constructor ... X121SMCStrategyXSTRPVSignalConditions() @@ -176,6 +179,7 @@ struct X121SMCStrategyXSTRPVSignalConditions // priceZone.Clean(); + pivotZone.Clean(); isPriceZoneValidForPeak = false; isPriceZoneValidForVale = false; } @@ -188,6 +192,13 @@ struct X121SMCStrategyXSTRPVSignalConditions X121SMCStrategyXSTRPVSignalConditions mXSTRPVConditions; X121SMCStrategyXSTRPVSignalConditions mXSTRPVConditionsCollection[]; +// +double X121SMCXSTRPVPivotPeak; +double X121SMCXSTRPVPivotVale; +datetime X121SMCXSTRPVPivotEnd; +datetime X121SMCXSTRPVPivotStart; +ENUM_XPV_PIVOTS X121SMCXSTRPVPivotType = XPV_NONE; + // // Extension Functions ... @@ -528,6 +539,314 @@ bool DetectX121SMCXSTRPVSiganlSetup( // ; + // + // Detect PV Pivot ... + + // + bool isPivotPeakZoneRejected = false; + bool isPivotPeakZoneBreakedUp = false; + bool isPivotPeakZoneBreakedDown = false; + bool isPivotValeZoneRejected = false; + bool isPivotValeZoneBreakedUp = false; + bool isPivotValeZoneBreakedDown = false; + bool hasPivot = conditions.pivotZone.IsValid(); + if (!hasPivot) + { + // + hasPivot = IsValid(X121SMCXSTRPVPivotStart); + if (!hasPivot) + { + // + bool isNewVale = decisionXConditions.isNewVale; + bool isNewValeOverLast = decisionXConditions.isNewValeOverLast; + bool isNewValeUnderLast = decisionXConditions.isNewValeUnderLast; + bool isSameVales = decisionXConditions.valesBuffer[1] == + decisionXConditions.valesBuffer[2] && + decisionXConditions.valesBuffer[2] == + decisionXConditions.valesBuffer[3]; + bool isSameCycleVales = decisionXConditions.valesBuffer[1] == + analyseXConditions.valesBuffer[1] && + analyseXConditions.valesBuffer[1] == + verificationXConditions.valesBuffer[1]; + + // + bool isNewPeak = decisionXConditions.isNewPeak; + bool isNewPeakOverLast = decisionXConditions.isNewPeakOverLast; + bool isNewPeakUnderLast = decisionXConditions.isNewPeakUnderLast; + bool isSamePeaks = decisionXConditions.peaksBuffer[1] == + decisionXConditions.peaksBuffer[2] && + decisionXConditions.peaksBuffer[2] == + decisionXConditions.peaksBuffer[3]; + bool isSameCyclePeaks = decisionXConditions.peaksBuffer[1] == + analyseXConditions.peaksBuffer[1] && + analyseXConditions.peaksBuffer[1] == + verificationXConditions.peaksBuffer[1]; + + // + bool isValeStart = + // isSameVales; + isSameVales && + isSameCycleVales; + bool isPeakStart = + // isSamePeaks; + isSamePeaks && + isSameCyclePeaks; + + // + bool isStart = isPeakStart || + isValeStart; + if (isStart) + { + // + X121SMCXSTRPVPivotStart = cTime; + X121SMCXSTRPVPivotType = + isPeakStart + ? XPV_PEAK + : XPV_VALE; + + // + X121SMCXSTRPVPivotPeak = decisionXConditions.peaksBuffer[1]; + X121SMCXSTRPVPivotVale = decisionXConditions.valesBuffer[1]; + } + + // + hasPivot = IsValid(X121SMCXSTRPVPivotStart); + + // + // Create XPVPivot instance ... + if (hasPivot) + { + // + conditions.pivotZone.symbol = symbol; + conditions.pivotZone.period = period; + + // + conditions.pivotZone.to = cTime; + conditions.pivotZone.repetition = 3; + + // + conditions.pivotZone.upper = X121SMCXSTRPVPivotPeak; + conditions.pivotZone.lower = X121SMCXSTRPVPivotVale; + + // + conditions.pivotZone.type = X121SMCXSTRPVPivotType; + conditions.pivotZone.from = X121SMCXSTRPVPivotStart; + } + } + } + + // + if (hasPivot) + { + // + bool isBreaked = X121SMCXSTRPVPivotType == XPV_PEAK + ? decisionXConditions.isBreakedUpPrevPeak + : decisionXConditions.isBreakedDownPrevVale; + + // + if (!isBreaked) + { + // + X121SMCXSTRPVPivotPeak = decisionXConditions.peaksBuffer[1]; + X121SMCXSTRPVPivotVale = decisionXConditions.valesBuffer[1]; + + // + conditions.pivotZone.to = cTime; + conditions.pivotZone.repetition++; + conditions.pivotZone.upper = X121SMCXSTRPVPivotPeak; + conditions.pivotZone.lower = X121SMCXSTRPVPivotVale; + } + else + { + // + X121SMCXSTRPVPivotEnd = cTime; + conditions.pivotZone.to = cTime; + } + + // + // Fill Pivot State ... + + // + XPOIState analysePivotState; + DetectPivotPOIs( + conditions.pivotZone, + analyseState, + analysePivotState // + ); + + // + XPOIState decisionPivotState; + DetectPivotPOIs( + conditions.pivotZone, + decisionState, + decisionPivotState // + ); + + // + // Combine two State ... + XPOIState combinedPivotState; + XPOIState iStates[]; + AddRef( + analysePivotState, + iStates // + ); + AddRef( + decisionPivotState, + iStates // + ); + CombineStates( + combinedPivotState, + iStates // + ); + combinedPivotState = decisionPivotState; + + // + ArrayFree(iStates); + + // + combinedPivotState.time = decisionPivotState.time; + combinedPivotState.symbol = decisionPivotState.symbol; + combinedPivotState.period = decisionPivotState.period; + + // + // Hold Only Areas Which on Upper or Lower bondary of Pivot Zone ... + FilterPivotState( + conditions.pivotZone, + combinedPivotState // + ); + + // + conditions.pivotZone.state = combinedPivotState; + + // + double peakUpper = 0; + double peakLower = 0; + double valeUpper = 0; + double valeLower = 0; + + // + datetime peakTo = NULL; + datetime valeTo = NULL; + datetime peakFrom = NULL; + datetime valeFrom = NULL; + + // + bool hasBoxData = DetectPivotStateBoxData( + conditions.pivotZone, + peakUpper, + peakLower, + peakFrom, + peakTo, + valeUpper, + valeLower, + valeFrom, + valeTo // + ); + + // + // Calculate Pivot Tick Zones ... + + // + int ticksLevels = decisionCycleHelper + .mPOIDetector + .TicksRangeZoneLevel(); + int ticksRange = decisionCycleHelper + .mPOIDetector + .TicksRangeZoneRange(); + + // + CalculatePivotTickZone( + conditions.pivotZone, + ticksLevels, + ticksRange // + ); + + // + isPivotPeakZoneRejected = + hasBoxData && + ( + // + IsBarReject( + peakLower, + X_DIRECTION_BEARISH, + cBar // + ) + // + || + // + IsBarReject( + peakUpper, + X_DIRECTION_BEARISH, + cBar // + ) + // + ); + isPivotPeakZoneBreakedUp = + hasBoxData && + IsBarBreak( + peakUpper, + X_DIRECTION_BULLISH, + cBar // + ); + isPivotPeakZoneBreakedDown = + hasBoxData && + IsBarBreak( + peakLower, + X_DIRECTION_BEARISH, + cBar // + ); + + // + isPivotValeZoneRejected = + hasBoxData && + ( + // + IsBarReject( + valeLower, + X_DIRECTION_BULLISH, + cBar // + ) + // + || + // + IsBarReject( + valeUpper, + X_DIRECTION_BULLISH, + cBar // + ) + // + ); + isPivotValeZoneBreakedUp = + hasBoxData && + IsBarBreak( + valeUpper, + X_DIRECTION_BULLISH, + cBar // + ); + isPivotValeZoneBreakedDown = + hasBoxData && + IsBarBreak( + valeLower, + X_DIRECTION_BEARISH, + cBar // + ); + } + + // + bool isPivotEnded = IsValid(X121SMCXSTRPVPivotEnd); + if (isPivotEnded) + { + // + X121SMCXSTRPVPivotPeak = 0; + X121SMCXSTRPVPivotVale = 0; + X121SMCXSTRPVPivotEnd = NULL; + X121SMCXSTRPVPivotStart = NULL; + X121SMCXSTRPVPivotType = XPV_NONE; + + // + conditions.pivotZone.Clean(); + } + // // Detect Price Zone ... @@ -615,6 +934,8 @@ bool DetectX121SMCXSTRPVSiganlSetup( // bool isDecisionBullish = + // + hasPivot && // hasAnalysePriceZone && analysePriceZone.IsBullish() && @@ -646,6 +967,8 @@ bool DetectX121SMCXSTRPVSiganlSetup( // bool isDecisionBearish = + // + hasPivot && // hasAnalysePriceZone && analysePriceZone.IsBearish() && @@ -719,6 +1042,8 @@ bool DetectX121SMCXSTRPVSiganlSetup( // bool isAnalyseBullish = + // + hasPivot && // !hasDecisionCondition && // @@ -752,6 +1077,8 @@ bool DetectX121SMCXSTRPVSiganlSetup( // bool isAnalyseBearish = + // + hasPivot && // !hasDecisionCondition && //