Using variable spread

Modified on Mon, 04 Apr 2022 at 01:54 PM

Summary


In order to use variable spread, all you have to do is click the Tick data settings button in the MT4 backtest pane and enable the Use variable spread checkbox.


Configuration


When variable spread is enabled, the Spread tab becomes available in the Tick data settings dialog. This is where you can configure several settings related to the spread and if you hover the mouse cursor over each of them you will get a tooltip with usage information.


By default, the variable spread used is the unaltered spread stored in the tick data.


If you wish to alter the stored spread, each of the available settings has a certain effect on how the processing occurs:

  • As its name implies, the Spread multiplier is a number that will be used as a multiplier for the spread.
    For example, if a particular tick had a spread of 20 points and you were using a spread multiplier of 1.5, that tick would have its spread adjusted to 20 * 1.5 = 30 points. Similarly, if the same tick with a spread of 20 points would occur in conjunction with a multiplier of 0.5, its spread would be adjusted to 20 * 0.5 = 10 points.
  • The Spread addition parameter lets you configure a number of points that gets added to the spread. Note that this can be a negative amount, resulting in a subtraction.
    For example, a tick with a spread of 20 with a spread addition of 2 would become 20 + 2 = 22 points. The same tick (20 point spread) with a spread addition of -5 would become 20 + (-5) = 15 points.
  • The Minimum spread parameter lets you configure a minimum spread threshold. Any spread that is lower than this threshold will be set to the configured value.
    For example, if you configured minimum spread to 5 points and a tick with a spread of 3 points is encountered, its spread will be set to 5 points.
  • The Maximum spread setting enables capping the spread. Any spread that is larger than the configured amount will be set to that value.
    Important: a setting of 0 (the default) does not apply any capping, it is the equivalent of not having a maximum spread configured.
    For example, if maximum spread was configured to 20 points and a tick with a spread of 22 points was encountered, its spread would be configured to 20 points. If the same tick with a spread of 20 points was encountered and the maximum spread was set to 0, the spread would remain 20 points.

Notes:
  • The settings are applied in the following order:
    1. Spread multiplier
    2. Spread addition
    3. Minimum and maximum filtering.
    For example, if you have a spread multiplier of 1.5, a spread addition of 4, a maximum spread of 30 and a tick with a spread of 18 points is encountered, its spread becomes 18 * 1.5 + 4 = 31 points, which is then capped by the 30 maximum and brought down to a final 30 points.
  • The bid price is always used as the baseline. Any of the spread modifications applied will only change the ask price.

Average spread


If you're wondering how to configure the spread to best suit your broker, a solution is available. Some time ago I wrote an EA meant to compute the average spread in a backtest when using variable spread. Long story short, you can compute the average spread of your broker and divide that by the average spread of the tick data for your target period to obtain a spread multiplier that brings the backtest spread to an average that matches your broker's spread.

To begin, download the Average Spread EA attached here. First of all, you need to find out the average spread of your broker for the symbol that you're interested in, so open a chart with that symbol, set its timeframe to M1 and attach the EA to it. Note that the timeframe specifies how often the EA will print the average spread to the log - if you use H1, it will print the average at every hour, if you use M1, every minute. If you only care about a certain time of the day, e.g. the Asian session, make sure you configure the start and end times correctly. After the EA has been running for a few days or weeks, write down the last average that gets printed to your experts log.

From here, it's quite straightforward: make sure that your tick data backtest matches the GMT & DST settings of your broker and backtest the same EA using the same start and end times that you used on your live account. Select the desired backtest range (Use date), make sure you use the default spread settings (if you're not certain, click the Defaults button in the Spread tab of the Tick data settings dialog then select Variable spread once more) and run the backtest. It's a good idea to use H1 or H4 as the backtest timeframe to avoid getting your backtest journal spammed with average spread notifications. Once the backtest is over, write down the last average printed.

At this point, you can divide the live account average by the backtest average to obtain your Spread multiplier setting. Configure it in the Tick data settings dialog and you're ready to backtest with an average spread that matches your broker's average spread.

Please note that no technical support is provided for this EA. If you have any questions about it, you can generally find the answer by inspecting its source code. Feel free to modify it as you see fit, its code is released in the public domain.