Skip to main content

Ghost Trades on MT4 Client Account and How to Deal With Them

Local-Trade-Copier-Tutorials-ghost-trades-1745x1080

In this blog post I will explain how you can deal with the “ghost trades” on a client accounts when using Local Trade Copier. Do not worry, not everyone gets them and there is no bug with this or anything. It’s very simple to fix this and I am sure you’ll agree with that after you finish reading this post.

What is a “Ghost trade”?

A “Ghost trade” is simply a trade from some MT4 master account you’ve been using before and did not closed all open position before you it shutdown. In other words, imagine if you open a BUY position on a MT4 master account #123, then you log off from that account and never use it again. So once that position was opened, the Server EA created a file with the trade information and did not deleted it. This is because Server EA did not get another chance to work on that MT4 master account #123, thus did not see that trade being closed.

Files holding trade information from the master accounts are stored in a special “Working directory“. I will get to that a bit later.

When does the “Ghost trade” appears on client accounts?

Important to mention that not all “ghost trades” can be copied to the client accounts. There’s a certain situation when these can be copied and I am about to explain this right now.

In most cases “ghost trades” only get copied if they are pending orders, but if you were to use ShiftEntryPips on the Client EA, then you might see “ghost trades” even if they are market orders. Now remember, “ghost trades” are simply abandoned files holding trade information from some MT4 master accounts you where using before with the Server EA. It can even be from some other MT4 platform you installed earlier, an older one that you might forgot you even have it on your computer.

As you know, for now, by default Client EA will copy all pending orders from the master account if they are not triggered yet. This means that once Client EA is attached to the chart (fresh start or re-start) it will look at the list of files in the “Working directory” that are holding master trades information. If any of them hold information about the pending orders that are not marked as triggered, the Client EA will place them on the slave account.

So obviously, if you have forgot about some MT4 master account #123 you were using last month, you’ll be surprised to see that “ghost trade” come up each time you start Client EA.

In case a “ghost trade” is a market order, Client EA won’t pick that up and ignore it immediately as this is default behavior of the EA – to ignore any currently open market orders from the master account when Client EA is launched. So even if you have “ghost trades” at the moment and they happen to be market orders, your Client EA should not pick them up.

However, if you are using ShiftEntryPips or set Client EA to copy currently open master trades, you might get those “ghost trades” copied as well. I say “might get”, because it also depends on some other Client EA settings, not mention that you might not have “ghost trades” at all. For example, if you have Client EA configured to copy trades only from specific master accounts or signal provider groups, and “ghost trade” does not match this criteria, then obviously it will not be picked up.

Removing “Ghost Trades”

To remove ghost trades, first you need to locate “Working Directory” that your Server EA and/or Client EA are using. It is quite easy and this information is displayed in two places.

Working Directory” is always visible in the EA blue dashboard.

Working Directory path can be found in the blue dashboard of the Local Trade Copier EA.

Working Directory path can be found in the blue dashboard of the Local Trade Copier EA.

Also, “Working Directory” is logged in the “Experts” tab at the bottom of your MT4 platform and you can also find it in the MT4 Experts log files as well which are stored in the \MQL4\Logs\ folder in your MT4’s “Data Folder“.

Local Trade Copier Working Directory is logged in the Experts tab of the MT4 client terminal.

Local Trade Copier “Working Directory” is logged in the Experts tab of the MT4 client terminal.

As you can see in the picture above, you can also “copy” that text into the clipboard and then paste it elsewhere.

This is quite an easy way to access that folder. I click the right mouse button on the text row showing the “Working Directory” in the “Experts” tab, then I open “Explorer” (or My computer as others call it), usually using Windows Key + E shortcut on my keyboard, and paste that text in the address bar. Obviously, you’ll have to remove the text that goes before the “Working Directory” (date, time, EA name, etc). If you are not familiar with this format you can learn how to read MetaTrader 4 log files here.

So if the text looks like this (see below, the text in red and blue) you’ll need to remove everything that goes before the actual path which starts with C:\…. You need only the blue part of that text.

2015.04.22 10:56:52.225 LTC Server v2.6-dev EURUSDc,Weekly: [19889-1] Work Directory: C:\Users\Rimantas\AppData\Local\ea-coder.com\LTC\ltctrades\

Note that “Working Directory” will be different on each computer because it has username in there. See “Rimantas” is included in the name of a “Working Directory” on my computer. Yours definitely will be different.

A Ghost Trade in the Working Directory of the Local Trade Copier software.

A “Ghost Trade” in the Working Directory of the Local Trade Copier software.

In the picture above you can see I am in the “Working Directory” and there are several files. There are files named “closed-” and they have MT4 account number at the end. These files hold the list of closed trades.

The file names that start with a number and then end with a number are the ones that hold trade information. Obviously, the first number (before the dot) is the number of the master trade (ticket number) and the second number (the one after the dot) is a number of the MT4 master account. In this example, I do not use MT4 master account #123 anymore, so that trade #887766 is a “ghost trade” which could give me trouble. I can simply remove all files that end with .123 and the problem will be over.

Another great way to fix this is to remove all of those files you find in the “Working Directory“, but for this action you need to make sure that all your master and client accounts do not have any trades that the trade copier app should copy/manage. If there are no trades you want to be copied and there are no trades that are copied and needs to be managed, then you can delete all of the files in the “Working Directory“. Best would be if you close MT4 platforms before, and then start them fresh after those files are removed.

Cleaning “Working Directory” when you have currently open trades

There’s also a way to clean the “Working Directory” if you have trades currently running (except for the cases when you have remainders running of “partially closed” or “close by” trades). This is quite simple as well and here are the steps you need to take.

  1. Make sure there are no trades running that are left after “partial close” or “close by” operations. (They usually have “from #” text in the trade comments).
  2. Close all MT4 master and client accounts.
  3. Clean the “Working Directory”.
  4. Start all MT4 master accounts first.
  5. Make sure all MT4 master accounts have their Server EA’s running and “server send” counters growing. Once Server EA’s start, they will create necessary files in the “Working Directory” associated with the currently open trades.
  6. Start all MT4 client accounts.

How to avoid “Ghost Trades”

The most simple way to avoid “ghost trades” is to always close all positions before you log off from the MT4 master account that you won’t be using again. And after you close those trades give the Server EA several seconds to take care of those “trade information files”. They might not be removed immediately, but they will be updated with a special information inside the files that will make all Client EA’s to ignore them completely in any possible case.

Server EA’s will automatically remove trade information files after some time when the associated trade gets closed on the master account (and of course Server EA still running), so do not worry that your “Working Directory” will get fill with many files. However, if you feel that there are lots of “ghost trade” files in there, you can do the “clean” operation anytime as explained above.

Conclusion

When one of my clients emailed me about this problem I was quite surprised how he called those unwanted positions that keeps coming in – The “Ghost Trades”. What a great name. We could also call them “Phantom Trades” 🙂 If you learn why “ghost trades” appear and where do they come from you’ll understand that there is nothing weird about them. It’s like if you leave lights on in your garage and then every time you pass by the building you’ll see the light inside.

Hope this information was helpful and you’ve enjoyed reading this. I certainly did enjoyed the time I spent writing this while eating at a Japanese restaurant 🙂

Rimantas Petrauskas

Rimantas Petrauskas is one of the most well-known programmers among Forex traders. Having more than 20+ years of programming experience, he created two of the most popular trade copiers for the MetaTrader 4 platform—the Signal Magician and Local Trade Copier. Rimantas is also a best-selling author on Amazon after his book "How to Start Your Own Forex Signals Service" hit #4 in the Forex category during the first launch week.

Leave a Reply