Advertisements
$ £ ¥
¥ £ $

Forex Quotes with 5 vs. 4 Decimal Places in MetaTrader Expert Advisors

Many Forex brokers now offer quotes with 5 digits after the dot (5 decimal places) instead of the traditional 4 digits after the dot (4 decimal places). This also translates into XXX/JPY currency pairs having 3 digits after the dot (3 decimal places) instead of 2.

This has a lot of benefits for scalping traders and opens up many new trading possibilities for others via the MetaTrader platform. However, there is a problem with almost all expert advisors that are applied in MetaTrader with brokers using such extended Forex quotes instead of the more conventional 4- and 2-decimal places format. As the majority of expert advisors use the Point variable for pips to set stop-loss and take-profit levels, there are two major problems with 5-decimal quotes:

5 Decimal Places vs. 4 Decimal Places and 3 Decimal Places vs. 2 Decimal Places in Forex Quotes

First, both stop-loss and take-profit values have very strong chances to come too close to the pair's current Bid or Ask value, and MetaTrader will generate an OrderSend Error 130, if they are too close. Second, the entire strategy embedded into the given EA will stop working properly because all the profit and loss will probably get divided by 10.

Let's look at the following example. With a 4-decimal quote, EUR/USD rate is 1.2703, and one Point in MetaTrader 4 is 0.0001 — a conventional pip for the EUR/USD pair. Your expert advisor buys EUR/USD, setting stop-loss at 20 pips — 1.2683, and take-profit at 40 pips — 1.2743. Everything goes fine and you win 40 pips when the exchange rate reaches 1.2743. But for a 5-decimal quote, things are completely different. E.g., the rate above could have been 1.27032, and one Point in your MT4 would have been 0.00001 — one-tenth of the conventional pip for EUR/USD. The same expert advisor would have set the stop-loss at 1.27012 and take-profit at 1.27072. Not only 99% of brokers wouldn't allow such a close stop-loss and take-profit setting, but if allowed, this position wouldn't be very rational and, of course, it wouldn't be according to the initial strategy's rules.

So, how to correct this problem without completely rewriting the expert advisor and, of course, without changing your broker (to one with the 4-decimal quotes)?

First, all MetaTrader expert advisors that are featured on our website have been already modified to work with both 4- and 5-decimal quotes.

Second, there is a way to make a MetaTrader EA work properly with 5-decimal quotes.

Fixing MT4 EA to work with 5 decimal places

  1. Open the .mq4 file of the expert advisor that you would like to modify in MetaEditor.
  2. Add a new global variable declaration (it should be in the beginning of the code, along with other variable declarations):
    double Poin;
  3. Add the following code to the OnInit() (or init()) function of the EA. This function is usually present in all EAs (it contains various initialization routines), but if it isn't there, you can create it and include this code:
    int OnInit()
    {
            // Checking for unconventional Point digits number.
            if (Point == 0.00001) Poin = 0.0001; // 5 decimal places.
            else if (Point == 0.001) Poin = 0.01; // 3 decimal places (for yen-based pairs).
            else Poin = Point; // Normal.
            return(INIT_SUCCEEDED);
    }
  4. Replace all further occurrences of Point in the code with Poin. This will change the EA to use your declared variable Poin, which now contains the standard 4-decimal pip value, instead of the system MT4 variable Point.
  5. That is all. Compile the EA and you are ready to run it on 5-decimal quotes in MetaTrader 4. Of course, it will still work with standard 4-decimal quotes too.

Fixing MT5 EA to work with 5 decimal places

  1. Open the .mq5 file of the expert advisor that you would like to modify in MetaEditor.
  2. Add a new global variable declaration (it should be in the beginning of the code, along with other variable declarations):
    double Poin;
  3. Add the following code to the OnInit() function of the EA. If there is no such function, you can create it and include the following code:
    int OnInit()
    {
            // Checking for unconventional Point digits number.
            if (Point() == 0.00001) Poin = 0.0001; // 5 decimal places.
            else if (Point() == 0.001) Poin = 0.01; // 3 decimal places (for yen-based pairs).
            else Poin = Point(); // Normal.
            return(INIT_SUCCEEDED);
    }
  4. Replace all further occurrences of Point() (and _Point) in the code with Poin. This will change the EA to use your declared variable Poin, which now contains the standard 4-decimal pip value, instead of the system MT5 variable _Point or function Point().
  5. That is all. You can now compile the EA and you are ready to run it on 5-decimal quotes in MetaTrader 5. Of course, it will still work with standard 4-decimal quotes too.

If you want to ask a question about dealing with the varying number of digits in Forex quotes or if you want to share your own way of dealing with the issue, please feel free to do so on our Forum.