From 18685876080a006b85f1afcb6eab5a1db6b8cab8 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Mon, 30 Dec 2024 05:11:11 +0330 Subject: [PATCH] last ... --- .../Signals/x-121.smc.xtwpv.signal.lib.mq5 | 422 ++++++++++++++---- .../Strategy/x-121.smc.strategy.class.mq5 | 88 ++-- 2 files changed, 388 insertions(+), 122 deletions(-) diff --git a/X121SMCEA/Signals/x-121.smc.xtwpv.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xtwpv.signal.lib.mq5 index 75f035da..0410829a 100644 --- a/X121SMCEA/Signals/x-121.smc.xtwpv.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xtwpv.signal.lib.mq5 @@ -27,6 +27,7 @@ // const string X121SMCXTWPV_Method_1_Token = "X121SMCXTWPV_1"; const string X121SMCXTWPV_Method_2_Token = "X121SMCXTWPV_2"; +const string X121SMCXTWPV_Method_3_Token = "X121SMCXTWPV_3"; // enum ENUM_X_X121SMC_XTWPV_METHODS @@ -34,6 +35,7 @@ enum ENUM_X_X121SMC_XTWPV_METHODS X_X121SMC_XTWPV_METHOD_UNKNOWN, X_X121SMC_XTWPV_METHOD_1, X_X121SMC_XTWPV_METHOD_2, + X_X121SMC_XTWPV_METHOD_3, }; // @@ -488,6 +490,18 @@ bool DetectX121SMCXTWPVSiganlSetup( return result; } + // + XOHCL pBar; + result = pBar.Init( + symbol, + period, + pIndex // + ); + if (!result) + { + return result; + } + // double ask = GetAsk(symbol); double bid = GetBid(symbol); @@ -626,6 +640,40 @@ bool DetectX121SMCXTWPVSiganlSetup( // // Setup Conditions ... + // + // Select Sources ... + XC121SMCCycleHelper *helper = analyseCycleHelper; + X121SMCCycleConditions helperConditions = analyseConditions; + XPOIState helperState = analyseState; + + // + // Instance Helper CBar ... + XOHCL helperCBar; + result = helper.GetBar( + cBar, + helperCBar // + ); + if (!result) + { + return result; + } + + // + double bullishFib = GetFibonacciLevel( + helperCBar.high, + helperCBar.low, + GetFiboLevelValue(X_FIBO_LEVEL_382), + -1 // + ); + + // + double bearishFib = GetFibonacciLevel( + helperCBar.high, + helperCBar.low, + GetFiboLevelValue(X_FIBO_LEVEL_382), + 1 // + ); + // // Detect Market Trend ... // ENUM_X_DIRECTION trend; @@ -655,21 +703,6 @@ bool DetectX121SMCXTWPVSiganlSetup( // // Retrieve Active Pivots ... - // - // Select Source Cycle Helper ... - XC121SMCCycleHelper *helper = analyseCycleHelper; - X121SMCCycleConditions helperConditions = analyseConditions; - XPOIState helperState = analyseState; - XOHCL helperCBar; - result = helper.GetBar( - cBar, - helperCBar // - ); - if (!result) - { - return result; - } - // XPVPivot peakPivot; bool hasPeakPivot = helper @@ -725,6 +758,7 @@ bool DetectX121SMCXTWPVSiganlSetup( helper.FillPivotState(conditions.pivot); // + // Check Pivot Renewation ... bool hasNewPivot = // (hasPeakPivot && @@ -743,7 +777,113 @@ bool DetectX121SMCXTWPVSiganlSetup( } // - // Waits for new Peaks or Vales ... + // XOHCL Conditions ... + + // + // Fibo Pressure ... + ENUM_X_DIRECTION pBarFiboPressureDir; + bool pBarHasFiboPressure = triggerCycleHelper + .mBarAnalyser + .HasFiboPressure( + pBar, + pBarFiboPressureDir // + ); + bool isPBarHasBullishFiboPressure = + pBarHasFiboPressure && + IsBullish(pBarFiboPressureDir); + bool isPBarHasBearishFiboPressure = + pBarHasFiboPressure && + IsBearish(pBarFiboPressureDir); + + // + // Rejection ... + ENUM_X_DIRECTION pBarRejectionDir; + bool isPBarRejected = triggerCycleHelper + .mBarAnalyser + .IsRejectionBar( + pBar, + pBarRejectionDir, + 0 // + ); + bool isPBarBullishRejected = + isPBarRejected && + IsBullish(pBarRejectionDir); + bool isPBarBearishRejected = + isPBarRejected && + IsBearish(pBarRejectionDir); + + // + // Momentum ... + ENUM_X_DIRECTION cBarMomentumDir; + bool isCBarMomentumBar = triggerCycleHelper + .mBarAnalyser + .IsMomentumBar( + cBar, + cBarMomentumDir, + 0 // + ); + bool isCBarBullishMomentumBar = + isCBarMomentumBar && + IsBullish(cBarMomentumDir); + bool isCBarBearishMomentumBar = + isCBarMomentumBar && + IsBearish(cBarMomentumDir); + + // + // Engulfing ... + ENUM_X_DIRECTION cBarEngulfDir; + bool isCBarEngulfed = triggerCycleHelper + .mBarAnalyser + .IsEngulfBar( + cBar, + cBarEngulfDir, + 0 // + ); + bool isCBarBullishEngulfed = + isCBarEngulfed && + IsBullish(cBarEngulfDir); + bool isCBarBearishEngulfed = + isCBarEngulfed && + IsBearish(cBarEngulfDir); + + // + // Helper cBar Conditions ... + bool isBearishFiboPassed = bullishFib <= conditions.pivot.lower; + bool isBullishFiboPassed = bearishFib >= conditions.pivot.upper; + + // + // Detect a Zone Which Price Inside it ... + // Helper (Optional) ... + conditions.CleanPriceInsideZones(); + bool hasPriceInsideZones = conditions.HasPriceInsideZones(); + int priceInsideZonesCount = conditions.CountPriceInsideZones(); + if (!hasPriceInsideZones) + { + // + hasPriceInsideZones = DetectPriceInsideZones( + verificationState, + cBar, + priceInsideZonesCount, + conditions.hasSupportZone, + conditions.supportZone, + conditions.hasResistanceZone, + conditions.resistanceZone, + conditions.hasSupplyZone, + conditions.supplyZone, + conditions.hasDemandZone, + conditions.demandZone, + conditions.hasOrderBlock, + conditions.orderBlock, + conditions.hasFairValueGap, + conditions.fairValueGap // + ); + + // + priceInsideZonesCount = conditions.CountPriceInsideZones(); + } + + // + // PV Conditions ... // double peak = helperConditions.x121Conditions.peaksBuffer[1]; @@ -766,35 +906,166 @@ bool DetectX121SMCXTWPVSiganlSetup( bool isNewValeUnderLast = helperConditions.x121Conditions.isNewValeUnderLast; // - result = isNewPeak || - isNewVale; - if (!result) + double triggerPeak = triggerConditions.x121Conditions.peaksBuffer[1]; + double triggerVale = triggerConditions.x121Conditions.valesBuffer[1]; + + // + int condition2MinPVDiffPoint = 30; + bool isPeakDiffPointPassed = peakDiff >= (condition2MinPVDiffPoint * points); + bool isValeDiffPointPassed = valeDiff >= (condition2MinPVDiffPoint * points); + + // + // DONCHAIN Conditions ... + + // + double donCloseUpper = helperConditions.x121Conditions.donCloseUpperBuffer[1]; + double donCloseLower = helperConditions.x121Conditions.donCloseLowerBuffer[1]; + + // + double donOpenUpper = helperConditions.x121Conditions.donOpenUpperBuffer[1]; + double donOpenLower = helperConditions.x121Conditions.donOpenLowerBuffer[1]; + + // + // OPEN ... + double triggerDonOpenUpper = triggerConditions.x121Conditions.donOpenUpperBuffer[1]; + double triggerDonOpenLower = triggerConditions.x121Conditions.donOpenLowerBuffer[1]; + double triggerDonOpenUpperPrev = triggerConditions.x121Conditions.donOpenUpperBuffer[2]; + double triggerDonOpenLowerPrev = triggerConditions.x121Conditions.donOpenLowerBuffer[2]; + + // + // HIGH ... + double triggerDonHighUpper = triggerConditions.x121Conditions.donHighUpperBuffer[1]; + double triggerDonHighLower = triggerConditions.x121Conditions.donHighLowerBuffer[1]; + double triggerDonHighUpperPrev = triggerConditions.x121Conditions.donHighUpperBuffer[2]; + double triggerDonHighLowerPrev = triggerConditions.x121Conditions.donHighLowerBuffer[2]; + + // + // CLOSE ... + double triggerDonCloseUpper = triggerConditions.x121Conditions.donCloseUpperBuffer[1]; + double triggerDonCloseLower = triggerConditions.x121Conditions.donCloseLowerBuffer[1]; + double triggerDonCloseUpperPrev = triggerConditions.x121Conditions.donCloseUpperBuffer[2]; + double triggerDonCloseLowerPrev = triggerConditions.x121Conditions.donCloseLowerBuffer[2]; + + // + // LOW ... + double triggerDonLowUpper = triggerConditions.x121Conditions.donLowUpperBuffer[1]; + double triggerDonLowLower = triggerConditions.x121Conditions.donLowLowerBuffer[1]; + double triggerDonLowUpperPrev = triggerConditions.x121Conditions.donLowUpperBuffer[2]; + double triggerDonLowLowerPrev = triggerConditions.x121Conditions.donLowLowerBuffer[2]; + + // + // Calculate PBar Rejected Don Upper and Lower ... + + // + bool isPBarRejectDonLowUpper = pBar.high > triggerDonLowUpperPrev; + bool isPBarRejectDonOpenUpper = pBar.high > triggerDonOpenUpperPrev; + bool isPBarRejectDonCloseUpper = pBar.high > triggerDonCloseUpperPrev; + bool isPBarRejectedDonUpper = isPBarRejectDonLowUpper || + isPBarRejectDonOpenUpper || + isPBarRejectDonCloseUpper; + + // + bool isPBarRejectDonHighLower = pBar.low < triggerDonHighLowerPrev; + bool isPBarRejectDonOpenLower = pBar.low < triggerDonOpenLowerPrev; + bool isPBarRejectDonCloseLower = pBar.low < triggerDonCloseLowerPrev; + bool isPBarRejectedDonLower = isPBarRejectDonHighLower || + isPBarRejectDonOpenLower || + isPBarRejectDonCloseLower; + + // + // Calculate PBar Breaked Don Upper and Lower ... + + // + bool isPBarBreakdDonLowUpper = pBar.GetUp() > triggerDonLowUpperPrev && + pBar.GetDown() < triggerDonLowUpperPrev; + bool isPBarBreakdDonOpenUpper = pBar.GetUp() > triggerDonOpenUpperPrev && + pBar.GetDown() < triggerDonOpenUpperPrev; + bool isPBarBreakdDonCloseUpper = pBar.GetUp() > triggerDonCloseUpperPrev && + pBar.GetDown() < triggerDonCloseUpperPrev; + bool isPBarBreakedDonUpper = isPBarBreakdDonLowUpper || + isPBarBreakdDonOpenUpper || + isPBarBreakdDonCloseUpper; + + // + bool isPBarBreakdDonHighLower = pBar.GetUp() > triggerDonHighLowerPrev && + pBar.GetDown() < triggerDonHighLowerPrev; + bool isPBarBreakdDonOpenLower = pBar.GetUp() > triggerDonOpenLowerPrev && + pBar.GetDown() < triggerDonOpenLowerPrev; + bool isPBarBreakdDonCloseLower = pBar.GetUp() > triggerDonCloseLowerPrev && + pBar.GetDown() < triggerDonCloseLowerPrev; + bool isPBarBreakedDonLower = isPBarBreakdDonHighLower || + isPBarBreakdDonOpenLower || + isPBarBreakdDonCloseLower; + + // + bool isRejectDonUpper = + // + // PBar ... + isPBarBearishRejected && + isPBarRejectedDonUpper && + // + // CBar ... + isCBarBearishMomentumBar && + cBar.close < triggerDonLowUpper && + // + triggerPeak == triggerDonHighUpper && + true + // + ; + + // + bool isRejectDonLower = + // + // PBar ... + isPBarBullishRejected && + isPBarRejectedDonLower && + // + // CBar ... + isCBarBullishMomentumBar && + cBar.close > triggerDonHighLower && + // + triggerVale == triggerDonLowLower && + true + // + ; + + // + if (isRejectDonUpper || + isRejectDonLower) { - return result; + Print("Don Rejected ..."); } // - // Calculate Conditions ... + bool isBreakedDonUpper = + // + false + // + ; // - double bullishFib = GetFibonacciLevel( - helperCBar.high, - helperCBar.low, - GetFiboLevelValue(X_FIBO_LEVEL_382), - -1 // - ); + bool isBreakedDonLower = + // + false + // + ; // - double bearishFib = GetFibonacciLevel( - helperCBar.high, - helperCBar.low, - GetFiboLevelValue(X_FIBO_LEVEL_382), - 1 // - ); + bool isEngulfedDonUpper = + // + false + // + ; // - bool isBearishFiboPassed = bullishFib <= conditions.pivot.lower; - bool isBullishFiboPassed = bearishFib >= conditions.pivot.upper; + bool isEngulfedDonLower = + // + false + // + ; + + // + // Method 1 ... // // Bullish Conditions 1 ... @@ -839,49 +1110,10 @@ bool DetectX121SMCXTWPVSiganlSetup( } // - // Detect a Zone Which Price Inside it ... - conditions.CleanPriceInsideZones(); - bool hasPriceInsideZones = conditions.HasPriceInsideZones(); - int priceInsideZonesCount = conditions.CountPriceInsideZones(); - if (!hasPriceInsideZones) - { - // - hasPriceInsideZones = DetectPriceInsideZones( - verificationState, - cBar, - priceInsideZonesCount, - conditions.hasSupportZone, - conditions.supportZone, - conditions.hasResistanceZone, - conditions.resistanceZone, - conditions.hasSupplyZone, - conditions.supplyZone, - conditions.hasDemandZone, - conditions.demandZone, - conditions.hasOrderBlock, - conditions.orderBlock, - conditions.hasFairValueGap, - conditions.fairValueGap // - ); - - // - priceInsideZonesCount = conditions.CountPriceInsideZones(); - } - - // - double donCloseUpper = helperConditions.x121Conditions.donCloseUpperBuffer[1]; - double donCloseLower = helperConditions.x121Conditions.donCloseLowerBuffer[1]; - - // - double donOpenUpper = helperConditions.x121Conditions.donOpenUpperBuffer[1]; - double donOpenLower = helperConditions.x121Conditions.donOpenLowerBuffer[1]; - - // - int condition2MinPVDiffPoint = 30; - bool isPeakDiffPointPassed = peakDiff >= (condition2MinPVDiffPoint * points); - bool isValeDiffPointPassed = valeDiff >= (condition2MinPVDiffPoint * points); + // Method 2 ... // + // Bullish Conditions 2 ... bool bullishConditions2 = // false @@ -899,6 +1131,7 @@ bool DetectX121SMCXTWPVSiganlSetup( } // + // Bearish Conditions 2 ... bool bearishConditions2 = // false @@ -915,6 +1148,37 @@ bool DetectX121SMCXTWPVSiganlSetup( conditions.method = ToString(X_X121SMC_XTWPV_METHOD_2); } + // + // Method 3 ... + + // + // Bullish Conditions 3 ... + bool bullishConditions3 = + // + false + // + ; + if (bullishConditions3) + { + // + conditions.point = vale; + conditions.method = ToString(X_X121SMC_XTWPV_METHOD_3); + } + + // + // Bearish Conditions 3 ... + bool bearishConditions3 = + // + false + // + ; + if (bearishConditions3) + { + // + conditions.point = peak; + conditions.method = ToString(X_X121SMC_XTWPV_METHOD_3); + } + // // Summary Conditions ... @@ -922,7 +1186,8 @@ bool DetectX121SMCXTWPVSiganlSetup( isBullish = // bullishConditions1 || - bullishConditions2 + bullishConditions2 || + bullishConditions3 // ; @@ -930,7 +1195,8 @@ bool DetectX121SMCXTWPVSiganlSetup( isBearish = // bearishConditions1 || - bearishConditions2 + bearishConditions2 || + bearishConditions3 // ; diff --git a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 index 5faba0d0..2416acf3 100644 --- a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 @@ -716,52 +716,52 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy hasPriceInsideZone; if (canDraw) { - // - ClearDraws(); + // // + // ClearDraws(); - // - // Draw Pivot Zone ... - if (hasPivot) - { - // - XCBaseObject *drawnObjects[]; - int drawnObjectsCount = DrawXTWPVPivotZone( - mXTWPVConditions, - mPOIDrawer, - drawnObjects, - true, // Draw State ... - true, // Draw Ticks Zone ... - true, // Ignore SwingHighs ... - true, // Ignore SwingLows ... - true, // Ignore SupportZones ... - true, // Ignore ResistanceZones ... - true, // Ignore SupplyZones ... - true, // Ignore DemandZones ... - true, // Ignore BullishOrderBlocks ... - true, // Ignore BearishOrderBlocks ... - true, // Ignore BullishFairValueGaps ... - true, // Ignore BearishFairValueGaps ... - true, // Ignore BullishRejectionBars ... - true, // Ignore BearishRejectionBars ... - true, // Ignore BullishMomentumBars ... - true // Ignore BearishMomentumBars ... - ); - AddObjectsIfNotExists(drawnObjects); - } + // // + // // Draw Pivot Zone ... + // if (hasPivot) + // { + // // + // XCBaseObject *drawnObjects[]; + // int drawnObjectsCount = DrawXTWPVPivotZone( + // mXTWPVConditions, + // mPOIDrawer, + // drawnObjects, + // true, // Draw State ... + // true, // Draw Ticks Zone ... + // true, // Ignore SwingHighs ... + // true, // Ignore SwingLows ... + // true, // Ignore SupportZones ... + // true, // Ignore ResistanceZones ... + // true, // Ignore SupplyZones ... + // true, // Ignore DemandZones ... + // true, // Ignore BullishOrderBlocks ... + // true, // Ignore BearishOrderBlocks ... + // true, // Ignore BullishFairValueGaps ... + // true, // Ignore BearishFairValueGaps ... + // true, // Ignore BullishRejectionBars ... + // true, // Ignore BearishRejectionBars ... + // true, // Ignore BullishMomentumBars ... + // true // Ignore BearishMomentumBars ... + // ); + // AddObjectsIfNotExists(drawnObjects); + // } - // - // Draw Price Inside Zones ... - if (hasPriceInsideZone) - { - // - XCBaseObject *drawnObjects[]; - int drawnObjectsCount = DrawTWPVPriceInsideZones( - mXTWPVConditions, - mPOIDrawer, - drawnObjects // - ); - AddObjectsIfNotExists(drawnObjects); - } + // // + // // Draw Price Inside Zones ... + // if (hasPriceInsideZone) + // { + // // + // XCBaseObject *drawnObjects[]; + // int drawnObjectsCount = DrawTWPVPriceInsideZones( + // mXTWPVConditions, + // mPOIDrawer, + // drawnObjects // + // ); + // AddObjectsIfNotExists(drawnObjects); + // } } //