How to Avoid EA Blowing Up Your Account

Recently I woke up to a call from my client, claiming he had been losing $2,000 (out of $10k account) in a day and he had no idea what to do. In fact, he wanted to know if this was due to the strategy itself that the Expert Advisor (EA) had been opening and closing positions continuously, like broken toy robots.

Certainly not the best way to start a day.

We immediately started the investigation and this turned out to be because of a misconfiguation, by which he was accidentally running one EA on multiple charts.

Its logic included something like this:

  • BUY 0.1 lot if there is no open positions
  • CLOSE 0.1 lot if there is more than 0.1 lot

What happened was, when the conditions to open positions were met, each of the same EA running on two different chart attempted to buy 0.1 lot, resulting in 0.2 lot total held in the account. Since there is more than 0.1 lot in the account, the EA instances now closes both of the open positions, bringing back the original state in the beginning. This process went on and on until the conditions for opening positions were no longer satisfied.

It’s not rocket science if explained. However the infinite loop was not cheap. Earning 20% of accounts requires hard work, patience, or both.

I would like to share what we discussed in our team after this incident.

Avoiding Misconfiguations

Never run the same EA in multiple charts. If you have VPS or multiple computers with active MetaTrader 4 clients, make sure there is only one single chart running the EA.

Also do note that the expensive loop can be resulted from different EA running in the same account with the same Magic Number.

Emergency Exit in the Expert Advisor Itself

It is a good idea to have an “Emergency Exit” coded in your EA, if you are making one. Emergency Exit can be in a form of minimum account equity threshold – that is where the EA stops functioning at all when the equity of your account runs too low. For example, there must be something wrong if your account had $10,000 yesterday and now $6,000. This can be coded very easily by any experienced MQL4/5 programmers.

Other triggers may include the balance of your account. However, keep in mind that it could drop suddenly with legit reasons, such as when your EA closes positions with large floating losses.

Monitoring with Fx24x7

If you want more control over your threshold, or you do not have an access to MQL4 code, you can still monitor your EA with Fx24x7. The alarms you may want to use are:

  • AccountEquity
  • AccountBalance