diff --git a/Experts/x-saherelm.xcaea.ea.mq5 b/Experts/x-saherelm.xcaea.ea.mq5 index 01ecbe09..d6ff5003 100644 --- a/Experts/x-saherelm.xcaea.ea.mq5 +++ b/Experts/x-saherelm.xcaea.ea.mq5 @@ -394,14 +394,13 @@ void OnTick() eaSignal.time = eaConditions.time; eaSignal.symbol = eaConditions.symbol; eaSignal.period = eaConditions.period; - // eaSignal.partialCloseOnTPLevel = eaConditions.partialCloseOnTPLevel; - // eaSignal.partialCloseMultiplier = eaConditions.partialCloseMultiplier; // - // Copy( - // eaConditions.targets, - // eaSignal.targets // - // ); + // Handling Targets ... + Copy( + eaConditions.targets, + eaSignal.targets // + ); // // Validate Signal ... diff --git a/Libraries/x-saherelm.x-trade.lib.mq5 b/Libraries/x-saherelm.x-trade.lib.mq5 index 10df371b..baced782 100644 --- a/Libraries/x-saherelm.x-trade.lib.mq5 +++ b/Libraries/x-saherelm.x-trade.lib.mq5 @@ -492,8 +492,9 @@ struct XTarget { // // Props ... - double target; - double volumeMultiplier; + bool doRF; // Do RF on Target + double target; // Target Price for Actions + double volumeMultiplier; // Volume Multiplier for Partial Close // // Constructor ... @@ -511,6 +512,7 @@ struct XTarget { // target = 0; + doRF = false; volumeMultiplier = 0; } diff --git a/XCAEA/Classes/xcaea.x-trade.manager.class.mq5 b/XCAEA/Classes/xcaea.x-trade.manager.class.mq5 index 53be7142..da22c8a2 100644 --- a/XCAEA/Classes/xcaea.x-trade.manager.class.mq5 +++ b/XCAEA/Classes/xcaea.x-trade.manager.class.mq5 @@ -1067,26 +1067,69 @@ class XCXCAEATradeManager : public XCBaseAlert // // Can Risk Free ... - bool canRF = jTarget.target > 0 && - (isLong - ? jTarget.target > iPosition.entry - : jTarget.target < iPosition.entry) && - (isLong - ? iPosition.price > targetDelta - : iPosition.price < targetDelta); - if (canRF) + bool canRF = + jTarget.doRF && + jTarget.target > 0 && + (isLong + ? jTarget.target > iPosition.entry + : jTarget.target < iPosition.entry) && + (isLong + ? iPosition.price > targetDelta + : iPosition.price < targetDelta); + + // + // Can Partial Close ... + bool canPC = + jTarget.volumeMultiplier > 0 && + jTarget.target > 0 && + (isLong + ? jTarget.target > iPosition.entry + : jTarget.target < iPosition.entry) && + (isLong + ? iPosition.price > targetDelta + : iPosition.price < targetDelta); + bool canRFPC = canRF || + canPC; + if (canRFPC) { // - double tp = iPosition.tp; - double sl = jTarget.target; - string comment = "RF On Target ..."; - bool isModified = trader.Modify( - iPosition.ticket, - sl, - tp, - comment // - ); - if (isModified) + // Handle Risk Free ... + bool isRFDone = false; + if (canRF) + { + // + double tp = iPosition.tp; + double sl = jTarget.target; + string comment = "RF On Target ..."; + isRFDone = trader.Modify( + iPosition.ticket, + sl, + tp, + comment // + ); + } + + // + // Handle Partail Close ... + bool isPCDone = false; + if (canPC) + { + // + double volume = jTarget.volumeMultiplier * iPosition.volume; + volume = NormalizeVolume(volume, iPosition.symbol); + string comment = "RF On Target ..."; + isPCDone = trader.ClosePartial( + iPosition.ticket, + volume, + comment // + ); + } + + // + // Handle Report Action ... + bool isRFPCDone = isRFDone || + isPCDone; + if (isRFPCDone) { // trades[idx].signal.appliedTargetIDX = j; @@ -1097,7 +1140,9 @@ class XCXCAEATradeManager : public XCBaseAlert ToString(iPosition.type) + " Position: " + ToString(iPosition.ticket) + - " RF On Traget: " + ToString(jTarget.target) + + (isRFDone ? "RF" : "") + + (isPCDone ? "PC" : "") + + " On Traget: " + ToString(jTarget.target) + " Successfully ..."; HandleReportProtector(message); } diff --git a/XCAEA/Signals/xcaea.signaller.class.mq5 b/XCAEA/Signals/xcaea.signaller.class.mq5 index 9bf29bf3..915a15e6 100644 --- a/XCAEA/Signals/xcaea.signaller.class.mq5 +++ b/XCAEA/Signals/xcaea.signaller.class.mq5 @@ -559,34 +559,6 @@ class XCXCAEASignaller : XCBase ? entry + reward : entry - reward; - // // - // // Handling RF ... - // double rfReward = risk * 1.95; - // double rfPrice = - // isBullish - // ? entry + rfReward - // : entry - rfReward; - // Add( - // rfPrice, - // conditions.targets // - // ); - - // // - // rfReward = risk * 2.95; - // rfPrice = - // isBullish - // ? entry + rfReward - // : entry - rfReward; - // Add( - // rfPrice, - // conditions.targets // - // ); - - // - // Handling Partial Close ... - // conditions.partialCloseOnTPLevel = 1; - // conditions.partialCloseMultiplier = 0.5; - // conditions.sl = sl; conditions.tp = tp; @@ -596,6 +568,58 @@ class XCXCAEASignaller : XCBase ? X_POSITION_TYPE_LONG : X_POSITION_TYPE_SHORT; + // + // Preparing Targets ... + XTarget iTarget; + double iPrice = 0; + double iReward = 0; + + // + // Partial Close 25% of Volume in R2R 1 ... + iReward = risk * 1; + iPrice = + isBullish + ? entry + iReward + : entry - iReward; + iPrice = NormalizePrice(iPrice, conditions.symbol); + iTarget.target = iPrice; + iTarget.volumeMultiplier = 0.25; + AddRef( + iTarget, + targets // + ); + + // + // Partial Close 25% of Volume in R2R 2 ... + iReward = risk * 1.90; + iPrice = + isBullish + ? entry + iReward + : entry - iReward; + iPrice = NormalizePrice(iPrice, conditions.symbol); + iTarget.target = iPrice; + iTarget.volumeMultiplier = 0.25; + AddRef( + iTarget, + targets // + ); + + // + // Risk Free in R2R 3 ... + iReward = risk * 2.90; + iPrice = + isBullish + ? entry + iReward + : entry - iReward; + iPrice = NormalizePrice(iPrice, conditions.symbol); + // iTarget.doRF = true; + iTarget.volumeMultiplier = 0.25; + iTarget.target = iPrice; + AddRef( + iTarget, + targets // + ); + // // Handling Targets ... bool hasTargets = HasChild(targets);