Close each trade if certain conditions?
-
On every tick, I want to check every open trade and close it if it has Loss of 100 pips or if it has profit of 50 pips.
What is the best/quickest way to do this?
Thanks in advance.
-
I also would like to open a new trade in this loop when it closes due to Loss with twice the lot of the closed trade (opposite trade, if closed trade was Buy then open Sell, if closed trade was Sell then open Buy trade)
-
Hi @yalgaar
I think that the easiest way is to set for each position a TP = 50 and SL = 100. Like this

Or by using a constant to allow those values can be modified.
Regards
-
Thanks for your reply but I really do not want to set this. I want the EA to do this when the TP or SL is reached.
The SL and TP should be hidden from the broker.
-
So for that case you could use the "Condition Block". Like this

Regards
-
Thanks. That's what I was looking for. I was not aware you had "Trade/Order Loop" options in Condition block!
This is sweet! -
Is your "Close Position" block same as "Close Trades" block?
I that case, how should I set it? I want it to close only the trades that meet the condition.
-
The blue "Close Trades" block has no idea about the loop of trades...so this will not work. It will close all open Trades with its own filter conditions. Unfortunately it does not have the conditions I need.
I am thinking the Pink "Close" block might help. I am not sure I will have to test this. Let me know your thoughts?
-
"Close Position" block is MQL5 and it is equal to "Close Trades" MQL4 block.
I am pretty sure that a better way exists to do it but this is how it might be work.
- Set a Group# for each position to be opened

- Each position should have 2 condition blocks in order to close the position if one of them is met.

You can copy those blocks for each position.
The goal can be achieved with different ways in fxDreema.
Hope this helps you.
Regards
-
I appreciate all your help but this is still not helping me.
I do not have control over how and when the trades are taken. So I am unable to set the Group numbers.
I just want a loop that will go over every single open trade ( these trades may or may not be opened by me or my EA) and check its current profit/loss. If loss is over 100pips then close it and open another position with 2 times the lots in opposite direction......if profit is over 50pip, then just close that trade.
-
Maybe something like this works... Try measuring the profit and loss with the Check distance block. So you will need two blocks of those, both in a loop that goes through all trades.

-
@josecortesllobat @l-andorrà Hi Jose, thank you, but I was wondering if this was good by itself,... or does this (the Condition for TP or Condition for SL) go under a purple For each position or For each Trade Block? Please advise