From 1c1e1c8365fa0a64537bf0765f8d5618440a2ea7 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Tue, 31 Dec 2024 18:45:16 +0330 Subject: [PATCH] Apply Last Fixes on TWPV Strategy Method 1 ... --- Libraries/x-saherelm.x-poi.lib.mq5 | 52 ++++++ Libraries/x-saherelm.x-trade.lib.mq5 | 26 +-- .../x-121.smc.market.cycle.helper.class.mq5 | 34 +++- .../x-121.smc.x-tradehandler.class.mq5 | 2 +- .../Signals/x-121.smc.xtwpv.signal.lib.mq5 | 166 +++++++++++------- 5 files changed, 194 insertions(+), 86 deletions(-) diff --git a/Libraries/x-saherelm.x-poi.lib.mq5 b/Libraries/x-saherelm.x-poi.lib.mq5 index 3e5aadb5..14b36a25 100644 --- a/Libraries/x-saherelm.x-poi.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.lib.mq5 @@ -265,6 +265,14 @@ class XCZone : public XCBasePOI return mUpper; } + /** + * Set Zone Upper Boundary ... + */ + void Upper(double value) + { + mUpper = value; + } + /** * Get Zone Lower Boundary ... * @@ -275,6 +283,14 @@ class XCZone : public XCBasePOI return mLower; } + /** + * Set Zone Lower Boundary ... + */ + void Lower(double value) + { + mLower = value; + } + /** * Retrieve Zone Range ... * @@ -4763,6 +4779,42 @@ struct XConsolidationZone // }; +/** + * Converts a Consolidation Zone ... + * + * @param zone: XConsolidationZone instance Reference ... + * @param dest: XCZone pointer Reference ... + * + * @return ( bool ) + */ +bool ToZone( + XConsolidationZone &zone, + XCZone *&dest // +) +{ + // + bool result = false; + + // + dest = NULL; + + // + result = zone.IsValid(); + if (!result) + { + return result; + } + + // + dest = new XCZone(); + dest.Upper(zone.upper); + dest.Lower(zone.lower); + result = dest.IsValidBoundary(); + + // + return result; +} + // // Model Value Changed ... struct XValueChange diff --git a/Libraries/x-saherelm.x-trade.lib.mq5 b/Libraries/x-saherelm.x-trade.lib.mq5 index 810ea2f0..e3bd0fe0 100644 --- a/Libraries/x-saherelm.x-trade.lib.mq5 +++ b/Libraries/x-saherelm.x-trade.lib.mq5 @@ -129,15 +129,16 @@ enum ENUM_X_POSITION_SELECT_METHODS enum ENUM_X_SIGNAL_EXECUTION_RESULT { // - X_SIGNAL_EXECUTION_UNKNOWN, // Unknown - X_SIGNAL_EXECUTION_SUCCEED, // Succed - X_SIGNAL_EXECUTION_FAILED_SPREAD, // Spread more than Max Allowed - X_SIGNAL_EXECUTION_FAILED_NOT_ALLOWED, // Not Allowed Trade Type - X_SIGNAL_EXECUTION_FAILED_NO_EQUITY, // No Equity for Trade - X_SIGNAL_EXECUTION_FAILED_PRICE_ERROR, // Price Error - X_SIGNAL_EXECUTION_FAILED_MAX_REACHED, // Max Allowed Positions Reached - X_SIGNAL_EXECUTION_FAILED_DELAY_NOT_PASSED, // Same Positions Delay Not Passed - X_SIGNAL_EXECUTION_FAILED_INVALID_PARAMS, // Invalid Params + X_SIGNAL_EXECUTION_UNKNOWN, // Unknown + X_SIGNAL_EXECUTION_SUCCEED, // Succed + X_SIGNAL_EXECUTION_FAILED_SPREAD, // Spread more than Max Allowed + X_SIGNAL_EXECUTION_FAILED_NOT_ALLOWED, // Not Allowed Trade Type + X_SIGNAL_EXECUTION_FAILED_NO_EQUITY, // No Equity for Trade + X_SIGNAL_EXECUTION_FAILED_PRICE_ERROR, // Price Error + X_SIGNAL_EXECUTION_FAILED_PREV_PROFIT_ERROR, // Prev Profit Error + X_SIGNAL_EXECUTION_FAILED_MAX_REACHED, // Max Allowed Positions Reached + X_SIGNAL_EXECUTION_FAILED_DELAY_NOT_PASSED, // Same Positions Delay Not Passed + X_SIGNAL_EXECUTION_FAILED_INVALID_PARAMS, // Invalid Params }; // @@ -5328,6 +5329,11 @@ string ToString(ENUM_X_SIGNAL_EXECUTION_RESULT value) result = "Price Error"; break; + // + case X_SIGNAL_EXECUTION_FAILED_PREV_PROFIT_ERROR: + result = "Previous Position Profit not Passed for Accept Next"; + break; + // case X_SIGNAL_EXECUTION_FAILED_MAX_REACHED: result = "Max Allowed Positions Reached"; @@ -5337,7 +5343,7 @@ string ToString(ENUM_X_SIGNAL_EXECUTION_RESULT value) case X_SIGNAL_EXECUTION_FAILED_DELAY_NOT_PASSED: result = "Min Delay Between to Signal not Passed"; break; - + // case X_SIGNAL_EXECUTION_FAILED_INVALID_PARAMS: result = "Invalid Params"; 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 b1d57505..cc6e596f 100644 --- a/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 @@ -2637,11 +2637,11 @@ class XC121SMCCycleHelper : public XCBase // if (hasConsolidation && - !mActioveConsolidationZone.IsValid()) + !mActiveConsolidationZone.IsValid()) { // // Initialize Consolidation Zone ... - bool isInited = mActioveConsolidationZone.Init( + bool isInited = mActiveConsolidationZone.Init( changeBar.symbol, changeBar.period, upper, @@ -2652,23 +2652,23 @@ class XC121SMCCycleHelper : public XCBase // if (!hasConsolidation && - mActioveConsolidationZone.IsValid()) + mActiveConsolidationZone.IsValid()) { // - mActioveConsolidationZone.Update(); - bool isBreaked = mActioveConsolidationZone.IsBreaked(); + mActiveConsolidationZone.Update(); + bool isBreaked = mActiveConsolidationZone.IsBreaked(); // if (isBreaked) { // // Add Active to List ... - bool isInited = AddConsolidationZone(mActioveConsolidationZone); + bool isInited = AddConsolidationZone(mActiveConsolidationZone); if (isInited) { // // Clean Active Zone ... - mActioveConsolidationZone.Clean(); + mActiveConsolidationZone.Clean(); // Add( @@ -2678,6 +2678,23 @@ class XC121SMCCycleHelper : public XCBase } } } + + // + // Draw ... + // if (mActiveConsolidationZone.IsValid()) + // { + // // + // if (mActiveConsolidationZoneObj != NULL) + // { + // mActiveConsolidationZoneObj.Delete(); + // } + + // // + // bool isCreated = mPOIDetector.mDrawer.CreateConsolidationZone( + // mActiveConsolidationZone, + // mActiveConsolidationZoneObj // + // ); + // } } // @@ -3128,7 +3145,8 @@ class XC121SMCCycleHelper : public XCBase // int mConsolidationLoopback; // Consolidation Loopback Length ... XConsolidationZone mConsolidationZones[]; // Holds Consolidation Zones ... - XConsolidationZone mActioveConsolidationZone; // Holds Actiove Consolidation Zone ... + XConsolidationZone mActiveConsolidationZone; // Holds Actiove Consolidation Zone ... + // XCConsolidationZoneObject *mActiveConsolidationZoneObj; // int mValidPivotRepetition; // Valid Pivot Point's Repetition ... diff --git a/X121SMCEA/Classes/x-121.smc.x-tradehandler.class.mq5 b/X121SMCEA/Classes/x-121.smc.x-tradehandler.class.mq5 index 77817950..ab3f42cf 100644 --- a/X121SMCEA/Classes/x-121.smc.x-tradehandler.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.x-tradehandler.class.mq5 @@ -2914,7 +2914,7 @@ class XC121SMCTradeHandler : public XCBaseAlert if (!result) { // - state = X_SIGNAL_EXECUTION_FAILED_PRICE_ERROR; + state = X_SIGNAL_EXECUTION_FAILED_PREV_PROFIT_ERROR; return result; } diff --git a/X121SMCEA/Signals/x-121.smc.xtwpv.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xtwpv.signal.lib.mq5 index 88a415d5..19d09533 100644 --- a/X121SMCEA/Signals/x-121.smc.xtwpv.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xtwpv.signal.lib.mq5 @@ -646,12 +646,6 @@ bool DetectX121SMCXTWPVSiganlSetup( // // Setup Conditions ... - // // - // // Select Sources ... - // XC121SMCCycleHelper *helper = analyseCycleHelper; - // X121SMCCycleConditions helperConditions = analyseConditions; - // XPOIState helperState = analyseState; - // XOHCL analyseCBar; result = analyseCycleHelper.GetBar( @@ -895,6 +889,62 @@ bool DetectX121SMCXTWPVSiganlSetup( priceInsideZonesCount = conditions.CountPriceInsideZones(); } + // + // Check Price Inside Consolidation Zone ... + XConsolidationZone cZone; + bool hasConsolidationZone = conditions + .HasConsolidationZone(); + if (!hasConsolidationZone) + { + // + hasConsolidationZone = triggerCycleHelper + .GetLastConsolidationZone(cZone); + // + if (!hasConsolidationZone) + { + // + XConsolidationZone cZones[]; + int count = triggerCycleHelper + .FillConsolidationZones(cZones); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XConsolidationZone iZone = cZones[i]; + + // + XCZone *iCZone; + bool isInited = ToZone(iZone, iCZone); + if (!isInited) + { + continue; + } + + // + bool isValid = IsPriceInsideZone( + cBar, + iCZone // + ); + if (isValid) + { + cZone = iZone; + } + } + } + + // + conditions.consolidationZone = cZone; + hasConsolidationZone = conditions + .HasConsolidationZone(); + } + } + if (hasConsolidationZone) + { + conditions.consolidationZone = cZone; + } + // // PV Conditions ... @@ -1221,18 +1271,6 @@ bool DetectX121SMCXTWPVSiganlSetup( return result; } - // - if (isBullish) - { - Print("Bullish ..."); - } - - // - if (isBearish) - { - Print("Bearish ..."); - } - // conditions.setupTime = cTime; conditions.dir = @@ -1461,16 +1499,6 @@ bool DetectX121SMCXTWPVSiganlTrigger( // // Trigger Conditions ... - // // - // isBullish = - // isBullish && - // false; - - // // - // isBearish = - // isBearish && - // false; - // result = isBullish || isBearish; @@ -1490,34 +1518,34 @@ bool DetectX121SMCXTWPVSiganlTrigger( return result; } - // - // Detect Consolidation ... - bool hasConsolidationZone = conditions.HasConsolidationZone(); - if (hasConsolidationZone) - { - // - hasConsolidationZone = triggerCycleHelper - .GetLastConsolidationZone(conditions.consolidationZone); + // // + // // Detect Consolidation ... + // bool hasConsolidationZone = conditions.HasConsolidationZone(); + // if (hasConsolidationZone) + // { + // // + // hasConsolidationZone = triggerCycleHelper + // .GetLastConsolidationZone(conditions.consolidationZone); - // - if (hasConsolidationZone) - { - // - hasConsolidationZone = - isBullish - ? conditions.consolidationZone.upper <= conditions.point - : conditions.consolidationZone.lower >= conditions.point; + // // + // if (hasConsolidationZone) + // { + // // + // hasConsolidationZone = + // isBullish + // ? conditions.consolidationZone.upper <= conditions.point + // : conditions.consolidationZone.lower >= conditions.point; - // - if (!hasConsolidationZone) - { - // - conditions - .consolidationZone - .Clean(); - } - } - } + // // + // if (!hasConsolidationZone) + // { + // // + // conditions + // .consolidationZone + // .Clean(); + // } + // } + // } // // Detect Nearest Pivot Point ... @@ -1589,7 +1617,13 @@ bool DetectX121SMCXTWPVSiganlTrigger( // // Filling SL Candidates ... + double atr = triggerConditions.x121Conditions.atrBuffer[1]; + + // double sls[]; + + // + bool hasConsolidationZone = conditions.HasConsolidationZone(); if (hasConsolidationZone) { // @@ -1773,30 +1807,28 @@ bool DetectX121SMCXTWPVSiganlTrigger( // double sl = isBullish - ? slsMin - : slsMax; + ? slsMin - atr + : slsMax + atr; double risk = MathAbs(entry - sl); double targetDelta = 2 * (risk / 3); if (target == 0) { + // + int minTargetPint = 50; + double minTargetPointValue = minTargetPint * points; + if (targetDelta < minTargetPointValue) + { + targetDelta = minTargetPointValue; + } + // // Force Target On Half Risk ... target = isBullish ? entry + targetDelta : entry - targetDelta; - } - // - if (isBullish) - { - Print("Bullish ..."); - } - - // - if (isBearish) - { - Print("Bearish ..."); + // } //