From 901b4e7848c76c93f435a0374c9b363e055fbbb3 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Sun, 28 Jul 2024 18:59:05 +0330 Subject: [PATCH] complete recovery senario a ... --- Classes/x-saherelm.xtrade.class.mq5 | 63 ++++++++++++++++++++--------- Experts/x-test-strategies.ea.mq5 | 12 +++--- 2 files changed, 52 insertions(+), 23 deletions(-) diff --git a/Classes/x-saherelm.xtrade.class.mq5 b/Classes/x-saherelm.xtrade.class.mq5 index 5331f5c4..c859f3a5 100644 --- a/Classes/x-saherelm.xtrade.class.mq5 +++ b/Classes/x-saherelm.xtrade.class.mq5 @@ -4742,7 +4742,7 @@ public: if (mData[i].recoveryLevel <= 0) { // - if (profit > 0) + if (profit > 0 && iPosition.tp == 0) { // double proftiInPoints = profit / volume; @@ -5104,29 +5104,17 @@ public: if ( recoveryTPPoint > 0 && recoverySLPoint > 0 && - mData[i].recoveryLevel < maxAllowedRecover) + (maxAllowedRecover <= 0 + ? true + : mData[i].recoveryLevel < maxAllowedRecover)) { // // Current Profit ... double distanceInPoints = (MathAbs(profit) / volume); - double _volumeMultiplier = ((mData[i].recoveryLevel) * recoveryVolumeMultiplier); + double _volumeMultiplier = ((mData[i].recoveryLevel + 1) * recoveryVolumeMultiplier); double _volume = volume * (_volumeMultiplier <= 0 ? 1 : _volumeMultiplier); string _comment = GenerateRecoveryTag(ticket); - // - // Try to Remove SL of Recovery Signals ... - if (iPosition.sl > 0 || iPosition.tp > 0) - { - // - string comment = "EQM Recover Remove TP/SL"; - bool isSLRemoved = mTrader.Modify( - ticket, - 0, - 0, - comment // - ); - } - // if (profit < 0) { @@ -5180,6 +5168,9 @@ public: // if (isPrepared) { + // + RemovePositionTPSL(iPosition); + // rSignal.comment = _comment; @@ -5202,6 +5193,9 @@ public: mData[i].recoveryLevel / 2 == 0)); if (canRecover) { + // + RemovePositionTPSL(iPosition); + // ENUM_POSITION_TYPE _type = isLong @@ -5237,7 +5231,10 @@ public: } } } - else if (profit >= 0 && mData[i].recoveryLevel > 0) + else if (profit >= 0 && + (mData[i].recoveryLevel == 1 || + (mData[i].recoveryLevel >= 2 && + mData[i].recoveryLevel / 2 == 1))) { // if (mRecoverBasedOnPressures) @@ -5285,6 +5282,9 @@ public: // if (isPrepared) { + // + RemovePositionTPSL(iPosition); + // rSignal.comment = _comment; @@ -5298,6 +5298,9 @@ public: } else { + // + RemovePositionTPSL(iPosition); + // ENUM_POSITION_TYPE _type = isLong @@ -5658,6 +5661,30 @@ private: requiredProfitsForHedge -= commissions; } + // + bool RemovePositionTPSL(XPosition &osition) + { + // + bool result = false; + + // + // Try to Remove SL of Recovery Signals ... + if (osition.sl > 0 || osition.tp > 0) + { + // + string comment = "EQM Recover Remove TP/SL"; + result = mTrader.Modify( + osition.ticket, + 0, + 0, + comment // + ); + } + + // + return result; + } + // bool ExecuteRecoverySignal(XSignal &signal) { diff --git a/Experts/x-test-strategies.ea.mq5 b/Experts/x-test-strategies.ea.mq5 index aa97aec9..c20418cd 100644 --- a/Experts/x-test-strategies.ea.mq5 +++ b/Experts/x-test-strategies.ea.mq5 @@ -114,7 +114,7 @@ int OnInit() // // EventSetTimer(1); - EventSetMillisecondTimer(100); + // EventSetMillisecondTimer(100); // // Init Succeed ... @@ -152,7 +152,7 @@ void OnDeinit(const int reason) delete eaTradeHandler; // - EventKillTimer(); + // EventKillTimer(); // Clean(strategies); @@ -162,6 +162,8 @@ void OnDeinit(const int reason) // On Tick Handler ... void OnTick() { + // + HandleTradeState(); HandleStrategiesOnTick(); } @@ -177,7 +179,7 @@ void OnTrade() void OnTimer() { // - HandleTradeState(); + // HandleTradeState(); // // // if (eaTimeTracker.IsNewDay()) @@ -280,8 +282,8 @@ bool InitialEA() // // Configure Recovery ... eaTradeHandler.AllowRecover(true); - eaTradeHandler.MaxAllowedRecover(2); - eaTradeHandler.RecoveryTPPoint(eaTPPoint); + eaTradeHandler.MaxAllowedRecover(0); + eaTradeHandler.RecoveryTPPoint(50); eaTradeHandler.RecoverySLPoint(eaSLPoint); eaTradeHandler.RecoveryVolumeMultiplier(2); eaTradeHandler.RecoverBasedOnPressures(false);