How to set conditions on closing trades
-
Hi everyone,
How would someone set up a situation where the EA does the following?
- Count the total dollar value of all profitable trades
- Close all profitable trades
- Start closing losing trades (biggest loss first) until the amount closed in losses equals the profits
- Skip any trades where it would make the total losses closed to be greater than profit closed
To use an example, let's say I have 3 winning trades and 4 losing trades:
Winning trades
Trade 1 buy profit $5
Trade 2 sell profit $8
Trade 3 buy profit $12Losing trades
Trade 4 buy loss $6
Trade 5 sell loss $7
Trade 6 buy loss $8
Trade 7 buy loss $9Desired outcome: close trades 1-3 (total closed profit of $25) and then close trade 7, then trade 6, skipping trade 5 (since this would make the losses go over the profit) but closing trade 4 (total closed losses of $23)?
I tried a proof of concept but it failed to do what I wanted it to (it closed everything):
https://fxdreema.com/shared/XVQAQMwSb
(This is in MT5) -
@breeeeen Are those profit/loss limits supposed to be applied at the same time? I mean, should any trade be closed before those +25 -23 figures are reached?
-
Hi @l-andorrà, sorry the +25 and -23 were just examples, it should be any number as long as profits are equal to or greater than the losses.
-
@breeeeen Then you will definitely need a loop to search for that. Certaily not an easy one. Is that amount of money supposed to be customizable as an input parameter? I mean, would you select for example 15, so that when profit is +1+ be closed if losses now are -15? And then change that value?
-
@l-andorrà no that money doesn't need to be customizable, just as long as profits is greater or equal to losses, whatever their values.
I tried a loop condition, what changes would you make to this example? https://fxdreema.com/shared/XVQAQMwSb (this is in MT5)