Optimising MetaTrader for Algorithmic Trading

If you’ve ever delved into the world of retail foreign exchange trading, you’ll have come across the MetaTrader platform. Let’s be clear. The platform has its drawbacks. If you’ve traded “grown-up” markets, some of the features will leave you scratching your head. But one thing’s for sure – MetaTrader provides fast, convenient access to pretty much every retail forex broker on the planet. That’s no small thing.

If we had the choice, we’d rather trade directly with the broker through a dedicated API rather than through a third-party platform, but often that’s not an option. One thing that my life as a trader has taught me is that it’s better to move fast in order to get trading strategies into the market with a solution that’s “good enough” rather than spending valuable R&D time on developing “optimal” solutions – which usually end up changing anyway. So we suck it up and make the best of the tools at our disposal. It’s all about being smart with priorities.

We do our Spot FX trading through Darwinex. Not only is their business model aligned with their clients’ desire to make money through trading (which is not as common as you might think in FX land), but they were generous enough to provide a fantastic deal on brokerage fees for our members. Darwinex is developing an API to enable fast, direct automated trading and we very much look forward to making use of that in the future. But for now, we’re executing our FX strategies via the MetaTrader platform. Specifically, we’re running our strategies through the Zorro Automated Trading software, which in turn controls MetaTrader.

The main benefit of this stack is convenience – we get all the power and flexibility of Zorro for doing automated trading, without having to build any additional market connectivity infrastructure. This makes the path from idea generation to research to market feedback to live trading about as short as one could hope.

There are a few drawbacks to this approach. One is the additional execution latency that comes with executing through MetaTrader (the Zorro link adds almost nothing however). None of our strategies are latency sensitive, so we’re not worried about this right now.

Another drawback is that MetaTrader is something of a resource hog. And since you’ll generally want to run an automated trading portfolio on a commercial server, resource intensive software leads to bigger servers, which leads to added costs.

Getting Zorro set up and connected to MetaTrader is a bit of a pain the first time around. I’ll give you a walk through of that process in another blog post. But right now, I want to show you some simple tips and tricks for reducing the resource footprint of the MetaTrader platform – and hopefully saving you a few bucks along the way. Here goes.

Reduce the number of bars plotted

MetaTrader is capable of plotting a lot of information about a lot of different markets all at the same time. Which is awesome if you’re this guy:

But we don’t need this for automated trading. And you can save a decent amount of computer resources by getting rid of it. Under the Tools menu, select Options, then click on the Charts tab in the pop-up. Then, enter 1 for Max bars in history and Max bars in chart:

mt4 optimization

Disable auto-scrolling of charts

By default, MetaTrader will automatically scroll its charts as time marches on. Again, we don’t need this feature for our purposes. Disable it like so:

metatrader 4 optimization

Disable news and sounds

More unnecessary (for our purposes) bloat. Turn off MetaTrader’s news feed by selecting Tools –> Options as above, then select the Server tab and uncheck the Enable News box:

metatrader 4 optimization

Disable sounds by selecting the Events tab and unchecking the Enable box:

mt4 optimization

Disable unnecessary tickers

MetaTrader can subscribe to data feeds that you don’t need, hogging valuable resources. Right click in the Market Watch window and select Hide All:

The Market Watch window will then look something like this, showing that you’re only pulling data for one or a few products:

Now that only a few tickers will remain, you may need to add back the ones you wish to trade. Do this by once again right-clicking in the Market Watch window and selecting Symbols, like so:

Another pop-up menu appears listing all the products that you can subscribe to. Anything with a greyed-out box next to it is currently unsubscribed; while anything with a gold box is subscribed. Double click on the boxes to toggle them back and forth:

Close unnecessary charts, minimise the one you need

We don’t need to display charts for all the tickers we intend trading in order to use Zorro to send trades to MetaTrader. Being subscribed via Market Watch (see above) is enough. But you do need one chart.

Because of the way MetaTrader works, Zorro is able to control it by “attaching” some software to a chart. I’ll cover this in another blog post, but the wash up is that this chart needs to remain open in order for Zorro to work properly.

If you close all the charts you don’t need you’ll save some resources, and if you minimise the one chart that you do need, you can save a tiny bit more by reducing the amount of visual rendering.

Your platform should now look like this:

Hide the terminal

The terminal outputs a bunch of information from the platform: useful things like real-time trade profit  and account margin, and less useful things like “signals” that you can subscribe to from within the platform that will trade on your behalf.

Admittedly, turning this off won’t make a huge difference, but it’s easy to do and there’s no downside. Disable the terminal by clicking this button on the toolbar (you can turn it back on anytime by clicking the same button):

metatrader otpimization

Restart

To get the benefit of all those changes, you may need to restart your MetaTrader platform.

Performance

At the time of writing, we were running our Zorro-MetaTrader automated fx portfolio on a virtual machine provided by Google Cloud Platform (here’s an article that will help you get something similar up and running). We’re running an n1 standard instance with 3.5GB of memory, 1 virtual CPU and 50GB of persistent disk (which we wouldn’t need if we weren’t bound to using Windows – I’ve heard that Zorro for Linux is coming, but we make do with what we have). We’re running a MetaTrader platform set up as described in this post. We’ve also got five Zorro instances interacting with it.

How’s the performance? Well, Google’s resource monitor tells us that we’re over-utilising the machine and that we should upgrade, but we haven’t run into any problems yet. Our CPU monitoring looks like this:

Conclusion

Like all trading tools, MetaTrader has its pros and cons. For fast and easy access to retail foreign exchange markets, it’s hard to beat.

By performing some simple optimisations, we can significantly reduce the resource load of the platform, thereby reducing the specs of our trading server, improving its performance and saving some dollars along the way.

1 thought on “Optimising MetaTrader for Algorithmic Trading”

Leave a Comment