Search in uioop.blogspot.com

Thursday, January 14, 2016

Improve MT4 Trade Copier speed on multi-core CPU machines

Article from: https://www.mt4copier.com/improve-mt4-trade-copier-speed/

In this blog post I’ll show how to improve MT4 performance and how to make sure your Expert Advisors and indicators are not suffering from unnecessary delays. This literally allows you to speed up MT4 software when it is used on multi-core processor VPS servers. In this example I will use one of my MT4 apps to demonstrate how to identify this problem and how to fix this, but you might experience the same problem with any other MT4 app in general.
Recently I have been receiving quite a lot of emails where people complaint that my Local Trade Copier software is working very slowly. Results have been quite different for most of those trade copier users, but on average they have experienced somewhere between 10 to 60 second delay when copying trades. That is huge and not tolerable and should be fixed. However, what I found out is that everything is okay with my software and the problem comes from the MT4 platform when it runs on a multi-core CPU machine (in most cases VPS servers). Normally the trade copier software should synchronize trades every 400 milliseconds, which is basically 2 times every second, and you can even adjust the sync rate to make it work even faster. I had this “slow copier” problem as well in the past so I want to share with you how to solve this problem.
This “slow MT4” problem is quite well known to programmers and there are lots ofdiscussions about MT4 and multi-core processors. However, I do not want to throw technical terms and explanation at you. I just want to show you how to solve the problem when your MT4 is running slowly. And even if your MT4 does not seem to run slowly, by applying this trick you might even be able to run more MT4 client terminals on the same VPS server.
Technically, the problem is that MT4 is a 32-bit application and this gives trouble to work efficiently on multi-core processor machines (like Dual-core, Quad-core, etc). However, in most cases this seems to be the problem only when you are running multiple MT4 client terminals on the same VPS server and this server has multi-core CPU. Usually, the multi-core CPU on a VPS server is a “virtual CPU”, which means those CPU cores are not real physical CPU’s. They are simulated virtual CPU cores.
If you are running a single MT4 instance you should not face problems like this. This should not be a problem as well if you are running multiple MT4 instances on the VPS server that has only single CPU core. If you are running some simple MT4 app like thisPartial Close EA then you might not face these problems as well.

How many CPU cores your VPS server has?

Here’s how to know how many CPU cores your VPS server has.
Click the right-mouse button somewhere on the task-bar at the bottom of your Windows screen and in the pop-up menu choose “Start Task Manager“.
You can start Task Manager in Windows VPS server from this pop-up menu.
You can start Task Manager in Windows VPS server from this pop-up menu.
When the “Task Manager” window loads up you need to switch to the “Performance” tab where you’ll see if you have multiple CPU cores or not.
Performance tab with 4x CPU cores in the Windows Task Manager.
Performance tab with 4x CPU cores in the Windows Task Manager.
In the picture above you can see this VPS server has 4x CPU cores.
The specifications of this VPS server are as follows:
  • AMD Opteron(tm) Processor 6136 (4 CPUs) ~2.4Ghz.
  • 8GB RAM Memory.
  • VPS system runs on a VMWare Virtual Platform.
If you switch to the “Processes” tab, you’ll find terminal.exe’s in the process list. This is your MT4 processes and what you need to do is to set each of them to use the same CPU core. By default each process use all CPU cores and in our case this creates a problem for MT4.
MT4 terminal.exe process list in the Windows Task Manager.
MT4 terminal.exe process list in the Windows Task Manager.
To make the process more simple I suggest to sort that process list by name by clicking on the column that says “Image Name“.
In this Task Manager process list we see that there are 4x MT4 instances running. Each of those MT4 platforms run several MT4 Copier EA instances which makes a total of 9x EA’s running on this VPS. CPU Usage in the picture is shown as 19% but it is actually jumping between 19% and 36% all the time. At a first glance anyone might say that CPU load of 36% or even 60% is not a big deal and VPS should work fine, however this “CPU Usage” number seems to be incorrect in such case.
The whole VPS system is working very slowly and it is even difficult to switch to another window. If I try to switch to another MT4 platform window I have to wait about 20-60 seconds. Obviously trade copying on such server would take ages and you would experience huge delays and price differences. I even had the same problem with only 2x MT4 instances and only two copier EA’s (Server EA and Client EA).

Simple trick to make MT4 run faster on multi-core CPU servers

Now here’s a simple trick you need to apply to make MT4 client terminals (and of course all apps running inside these terminals) work faster. There are two options. For some, option #1 helps speed up MT4, while others find only option #2 is actually helping.

Option #1: Set all terminal.exe processes to use the same CPU core.

To apply option #1 you need to set all terminal.exe processes to use the same CPU core. It does not really matter which CPU core you’ll choose to use, what’s important is that all MT4 processes should use the same. To make it simple I always set all terminal.exe’s to use CPU0. Do not worry that this will put all load on one CPU core and Windows Task Manager will show 100% load on CPU0. Remember, those are virtual cores that are actually running on the same physical processor at your hosting provider’s server. So actually all work will still get done by that physical CPU, but because MT4 will not need to jump and split operations between multiple CPU cores it will work faster.

Option #2: Set each terminal.exe process to use different CPU core.

If option #1 does not help you should also try option #2. To apply option #2 you need to set each terminal.exe process to use different CPU core. Say your VPS has 4x CPU cores and you run 4x MT4 instances. Then all 4x MT4 instances should be set as follows:
  • MT4 instance #1 should use CPU0
  • MT4 instance #2 should use CPU1
  • MT4 instance #3 should use CPU2
  • MT4 instance #4 should use CPU3
If you have more MT4 platforms than CPU cores you should close the rest of MT4 instances (at least for testing purposes) to see if this option #2 solution helps you at all.

How to set MT4 to use certain CPU core

Configuring MT4, or any other process from the list, to use only certain CPU cores is quite easy. You need to switch to the “Processes” tab, choose the terminal.exe process from the list, click the right-mouse button on that item and choose “Set Affinity” from the pop-up menu. In the “Processor Affinity” window you need to deselect all CPU cores and select only CPU0 like in the picture below.
Setting CPU affinity on MT4 terminal process in the Windows Task Manager.
Setting CPU affinity on MT4 terminal process in the Windows Task Manager. This makes the MT4 platform to work only using single CPU core for faster performance.
When I did this for all 4x MT4 instances I am running on my VPS all of them started to work efficiently. I can now switch between windows easily and CPU Usage dropped as well to 16% – 29% (even though I still think this number does not show correct values on VPS servers).
Obviously I can copy trades at the fastest speed possible. Trades are transferred between MT4 platform in under 1 second now.

MT4 Trade Copier speed is just one piece of the puzzle

I would mention that Local Trade Copier speed has little to do with how fast your trades are copied between MT4 platforms. In most cases delays come from the problems like slow MT4 (like in this example), poor internet connection or even execution delays from your broker. There were even cases when brokers delay trade execution on purpose for some economic news scalpers/traders.
To list all potential problems that affect trade copying speed I would list them in the following order (where 1st item is the most common problem and the last item is the least common problem):
  1. Slow MT4 performance because of the multi-core CPU server.
  2. Slow MT4 performance because of too many 3rd party indicators or Expert Advisors running on the MT4 terminal.
  3. Too many MT4 client terminals running on the same VPS server.
  4. Slow VPS performance because of 3rd party software (anti-virus, firewall, Internet browsers and other apps).
  5. Poor internet connection. I know all VPS providers will say that their connection is high quality, but even world class services have issues from time to time. Keep this in mind. On the other hand, it’s not necessary your server provider is the one to blame for bad Internet connection. There can be several or even dozen of servers/gateways in between your VPS and your broker’s server.
  6. Your MT4 app problem (in this example that would be the Local Trade Copier).
I won’t deny that my MT4 apps or MT4 copier might have problems running on your MT4 or your VPS. This have happened in the past and I did a lot of work to fix this. However, based on the last several months and tens of solved “slow trade copying” cases I’ve noticed that it’s always MT4, VPS or Internet connection problem. When you finally fix the problem with the trade copying speed you can even try to copy your Forex trades at a better price.

How to know if your LTC copier is slow

So how to know if it’s the Local Trade Copier working slow and does not copy trades fast enough or is it that the problem lies in the slow execution from your broker?
That’s quite simple. Both, Server EA and Client EA has special counters in the blue dashboard that are growing on each synchronization cycle. Server EA has “Server send” counter and Client EA has “Server read” counter.
Server send counter in the blue dashboard of the LTC Server EA.
“Server send” counter in the blue dashboard of the LTC Server EA.
If counters on all LTC EA instances are growing steadily, consistently and rapidly (according to your SyncRate setting in the EA Inputs), then it looks like your copier is working fine. If you see one of those counters growing slow and randomly, you should apply option #1 and/or option #2 solutions explained earlier in this article.
If counters on all LTC EA’s are growing steadily and consistently then you should also check the execution time. After each copied trade Client EA will print information in the “Experts” tab at the bottom of MT4 client terminal about the trade execution speed, price deviation and slippage.
Local Trade Copier reports broker execution speed on copied trades.
Local Trade Copier reports broker execution speed on copied trades.
In the picture above you can see Client EA reported that it took 203ms to execute the trade. This obviously does not include the synchronization time (the time required for the copier to actually send the signal from master to the client account). These 203ms is the time spent to deliver the “open trade” request to the broker’s server, actually get the trade executed and receive a confirmation answer from the broker’s server. In other words, this is out of control for the trade copier software or any other MT4 app. This depends on how fast your Internet connection is and how fast your broker’s execution speed is.
Under normal conditions you should get execution delay somewhere between 50-300 ms. If you want to get this close to 1ms, or something like that, you should rent a VPS server which is on the same network as your broker’s server. You can contact your broker to find out such information.
Local Trade Copier reports price deviation and slippage on copied trades.
Local Trade Copier reports price deviation and slippage on copied trades.
In the picture above we also see that the copier reported actual price deviation on the copied trade comparing it to the original trade’s open price. In this case there was a price difference of 0.6 pips which is considered very low under such circumstances. This report also included slippage which was zero in this case. Slippage is something you cannot avoid, but first thing what you need to find out is whether the slippage you get is the result of a bad Internet connection or it’s your VPS server running slowly.

Trade copier speed troubleshooting checklist

  1. After each trade is copied there will be a message logged in the “Experts” tab which gives the exact slippage and delay in ms. This way you can know if delay is coming from the broker/internet connection. If you get execution delay between 50ms and 300ms then your Internet connection and broker is working fine.
  2. Check if “Server read” and “Server send” counters are growing steadily or randomly. If one of these counters grow randomly, with delays, then it means your computer is slowing down the trade copier software.
  3. Check if your computer/VPS server has multiple CPU cores or just a single CPU core. If you have a single CPU then try closing 3rd party applications and remove other EAs and indicators from your MT4 to make it work faster. If this does not help then maybe you are running too many MT4 instances and/or simply need to get a better and more powerful computer.
  4. If your computer/VPS server has multiple CPU cores then you might suffer from the well known MT4 issue that it cannot work efficiently on multiple CPU core machines. In that case you would have to set all terminal.exe’s to use the same CPU. This can be done from the “Processes” tab in the “Task Manager” window. You need to select each terminal.exe and choose “Set Affinity“. Then in the CPU list window you need to select which CPU’s each process should use. Idea here is to try two operational modes: 1) Set all terminal.exe’s to use the same CPU0; 2) Set each terminal.exe to use different CPU.
If you have tried all that above and still have slow trade copying speed you should contact me.

Conclusion

If your MT4 is running slowly and your VPS server provider tells you that everything is okay on their side, you should check if your VPS is a multi-core CPU machine. MT4 in some cases cannot work efficiently on multi-core CPU machines and requires some additional configuration. I hope that this article will help you find out the cause of your slow MT4 problem and possibly fix it.
So, have you suffered from this problem before? Or maybe you are still struggling to find a solution to this? If you tried all that, did it helped? Please post your comments below.

No comments:

AVG Internet Security 2013

Total Pageviews

Contributors