How to optimize Metatrader4 for low memory usage, suitable for VPS?

If you are like me, you are running bunch of expert advisors for MT4, and your MT4 is not on your personal computer (desktop or laptop), but on dedicated 24/7 server, likely on VPS. But the problem with VPSs is that they offer various plans, and more memory you need, more expensive they are… MetaTrader 4 is not really renowned to be cpu and memory optimized to start with, but once you open 5, 6, or even 10 currency windows, attach one EA to each one (if you run EAs like MegaDroid, you probably know that you can make it trade more frequently, and then number of EAs escalates – but be selective and dont use bad apples like problematic IvyBot EA), things become nasty, and fast. So in order to save some money on VPS (or memory on your server), I did a sweep of forex related forums, and found some advices and hints on how to optimize metatrader for low memory usage.

Difference that makes the difference

mt4 memusage after optimization

But before I tell you how to do it, let me show you my results. I am lucky so I have my own linux server at home, and on it I run Sun’s excellent and free virtualization software VirtualBox. In it, i have Windows xp virtual machine, and this one is dedicated to run my forex applications. I currently use two forex brokers but run three instances of MT4 (real Alpari UK, real FXDD and demo FXDD; i started with InvesttechFX as foreign exchange broker but in spite of lucky first days this account is now wiped). And you can imagine that in every MT4 i have multiple currency windows with expert advisors attached to them.

After few days of use, I brought up Windows Task Manager on this virtual machine, and it showed that three terminal.exe processes were using: 152.772 KB, 112.972 KB and 81.836 KB of memory, which totals to around 346 megabytes of RAM. Auch! But as you know the memory usage is not static, but fluctuates with various activities of metatrader, activity of expert advisors, logging, network transfers -  so to play it safe i would say I need at least 400 megabytes for all the peaks OF metatrader forex applications… If I want my metatrader applications to run stable and reliable, I need to have additional buffer zone, so that they do not swap to hdd and become slow (actually a lot of EAs need fast responses to be successful and profitable)… And of course Windows by itself also uses some RAM, so to be on the safe side I concluded that my virtual machine needs to have 1024 megabytes of ram – 1 GB… I could go with the 768 megabytes if i really wanted to optimize…

Since I run Linux server, I don’t really care about whether I give my forex trading virtual machine 768 or 1024 megabytes of ram… But if I had to pay for VPS hosting like many of you (and like I did in the past), then you know that VPS plans differ in price based on bandwidth (not a crucial thing for MT4), hard disk space (5 GB is enough for Win XP + several instances of MT4 + dozens of EAs) and especially RAM (yup, you guessed, this is critical for us!). One of more frequent forex VPS providers (forexvps.com) charges you $30 more per month if you need VPS with 1024 MB or RAM (instead of 512MB), so see the difference!  Anyhow, if you’ll dig, you will find cheaper but excellent forex windows VPS providers like swvps.com (visit them thru my affiliate link, or go there directly), which I used in past (and would continue to do so if I had not decided to get my own dedicated server, plus they also have UK and US servers! You know that I use Alpari UK as one of brokers and having VPS server close to broker’s server really counts!) which offer way affordable plans, even ones offering up to 4 GB of ram… But anyhow…

After I optimized my MT4 applications, I gave system on my virtualbox a few days of running (applications grow in memory usage with time) and when I finally inspected the memory, I was amazed! My memory usage came down to around 170 MB as you can see from picture above! I checked memory footprint a few more times and the peak I saw was 225 MB. Which is still almost 50% lower than my average memory usage before (not to mention the peaks)… Anyhow as a result I reconfigured my virtualbox to only use 512 MB of RAM which saves more resources for other processes on server (and which in case of VPS would save you considerable money every month).

So what to do?

Step 1

Step 1

Before you begin: It might be smart to log your current memory usage. That way you will know how much memory you have saved!  Step 1: Go to MetaTrader 4 – Tools – Options – Charts. In the lower two fields enter number 516. This way MT4 will not hold more than last 516 bars (of every currency/time chart) in memory – and overall memory footprint will be way lower. For additional memory savings also feel free to tick off all checkbox on same options screen. As far as EAs are concerned MT4 works completely the same. The only problem with using this configuration is if you are doing backtests (which you shouldn’t anyhow, as ea backtesting is irrelevant). But if you still want to backtest, you can change “max bars in history” and “max bars in chart” back to maximum value of 2147483647.

Step 2

Step 2

Step 2: On every pair/time chart do a couple of zoom-ins (there is a magnifying glass icon in middle of toolbar). This will make bars as big as possible, but more important - each chart will have less charts - thus saving memory.  Step 3: That's it, restart MT4 and see the difference. Good luck, and I hope this can halve your VPS fees and fx online trading!

Permalink Print Comment

Comments on How to optimize Metatrader4 for low memory usage, suitable for VPS? »

September 26, 2009

Lee @ 1:36 am

Hi

"Step 1: Go to MetaTrader 4 – Tools – Options – Charts. In the lower two fields enter number 516." why 516 but not more or less ?

Thank you.

October 2, 2009

editor @ 5:01 pm

Because this still allows all EAs to work perfectly (with room to spare), but prevents memory hogging.

November 15, 2009

Lee @ 12:53 am

Hi editor again,

Thanks for your reply. Is there any ways to make VPS runs faster?

Thanks in advance.

Lee

Leave a Comment