Tâche terminée
Spécifications
I need an Expert Advisor for MetaTrader 4 (not MT5).
This EA will continuously monitor two values in MT4: Account "Balance" and account "Equity" (Equity changes as floating drawdown or gain of all open trades changes, while Balance only changes after a trade is closed).
When Equity falls below a given percentage of Balance (this percentage is provided as a parameter to the EA), then the EA will immediately close only those open trades which are currently negative (trades which at that time produce a floating negative drawdown, not in floating positive gain). Open trades which are in floating positive gain or pending orders will never be touched.
A status e-mail will be sent when trades are closed by the EA. This e-mail will list the trades closed as well as Balance and Equity before and after the close.
The EA needs to be programmed extremely careful and with reliability in mind. Closing of positions must be repeated until successful. After 5 minutes of trying, an error message on screen and via e-mail must be generated while the EA will continue trying to close the trades indefinitely (except when the condition for closing the trades is not present any more because the floating drawdown has reduced).
In essence, this EA will provide an automatic "emergency bailout" if one or more trades threaten to blow up the account, while leaving positive trades untouched. After closing all of the negative trades, the EA will continue to run and will be ready to close other trades if the condition to do so is met again.
Regards,
D.
Edit: To clarify the action of the EA, here is an example, step by step over time:
1. There are EUR 10,000 in the account, no trades. I have set the percentage parameter for your EA to 50 %.
2. Some other EA (not your EA) opens 3 trades. After one day, 2 of these trades are negative (floating DD) and one trade is positive (floating gain). All 3 trades are still open. This is how the account now looks - note Balance and Equity:
Trade 1: - 2,000 EUR
Trade 2: - 3,000 EUR
Trade 3: + 2,000 EUR
Balance: 10,000 EUR, Equity: 7,000 EUR
Balance is unchanged because no trade had been closed. Equity however is only 7,000 now because of the combination of floating DD and floating gain from the open trades. What your EA now needs to do is continuously calculate how many percent the current Equity is from the current Balance. In this case, this is currently 70 %. Action will only be taken by your EA when this percentage falls below the percentage given in the parameter.
Let's see how that happens:
3. A day later, the DD of Trade 2 gets worse, now it looks like this:
Trade 1: - 2,000 EUR
Trade 2: - 5,001 EUR
Trade 3: + 2,000 EUR
Balance: 10,000 EUR, Equity: 4,999 EUR
Now your EA calculates that Equity is only 49 % of Balance. That's less than the given parameter of 50 %. Now the EA will take action: It will immediately close ALL trades in the account which are in floating DD. So it will close Trade 1 und Trade 2, while it leaves Trade 3 untouched. After this action, this is how the account will look like (of cause I am ignoring slippage etc.):
Trade 3: + 2,000 EUR
Balance: 2,999 EUR, Equity: 4,999 EUR
The percentage calculated by the EA is now at 166.69 % and far away from the given 50 %. The EA will continue to run and will take action any time again when Equity drops below 50 % of Balance.
Edit: The EA must not close only one negative trade and then reevaluate. When the condition to close is met, ALL negative trades must be closed. Only after all these trades have been closed, the EA will start to evaluate again. That's necessary because else the floating DD would be reduced after closing the first negative trade and the remaining negative trades may not be closed.
Edit: The EA must check for the condition on every tick (not only once a day).