How to close a part of trade if n % of TP in profit?
-
Hi,
I'm currently struggling with an issue I have no idea yet, how to solve.
Let's assume I calculate the ATR value and use a multiplier of it either for SL and TP. As an example let's assume ATR is 10 and TP multilpier is 4, which means TP is 40 pips away from open price.
After a while my trade goes in profit and I want to partly close a defined number of pips (eg. 25% of my TP or in that example 1 initial ATR distance from opening).Possible solution 1:
Get to know how many candles trade is open and recalclate ATR from opening candle, store it in a variable and check if openingPrice + initialATR > than current bit/ask price depending on trade direction.Possible solution 2:
Get the distance between openingPrice and currentTP and divide it by the number (here 4) and check if current ask/bitPrice +/- tpDistance divided by tpMultiplier is > 0There may be other solutions, such as storing the TP per trade (ordernumber) as a global variable, which may survive a terminal restart. But I have no idea how to do so with fxdreema.
I could also open 2 trades and give them a splited lot size with 2 different TPs, but I don't like that approach so much.
Any ideas or tips I'd really appreciate!
-
Not sure I understood you. What do you want to close? The whole trade or just some lots?
-
Just a portion of the trade. Is there a function that I can get the number of bars the trade is open already? I'm currently prefering to calculate ATR from trade open again.
-
https://www.mql5.com/en/forum/114217
This custom code should do the trick. You can put the code in a "Custom mql code" block in the builder (I don't know how advanced a developer you are, pretty sophisticated strategy for a dude joined 5 days ago lol)
-
@roar thanks a lot. Never used the custom mql block so far. Didn't expect it to be so easy.

Thanks a lot.
-
@trader-philipps said in How to close a part of trade if n % of TP in profit?:
@roar thanks a lot. Never used the custom mql block so far. Didn't expect it to be so easy.

Thanks a lot.
The ea i created was place both buy and sell order at same time how can i correct this i want to add close on reversed signal and trailing loss breakeven how do i solve this problem thanj
-
I think you should start a new thread as this seems to be a new topic.
However, you can limit the in the close block that it should apply only to buy, sell or both (default). May that help you?
