Backtesting Forex

Introducing Strategy Simulations

Strategies are the core of Backtesting Forex, so knowing how to use them is essential.

How Backtesting Forex works

It's simple. You tell Backtesting Forex how you would have traded in the past, and it tells you how much money you would have made or lost.

The part where you tell Backtesting Forex how you would have traded is called the Strategy Builder. Getting this right is essential to getting accurate results, so this article will explain the basics of how to use it.

How to create a strategy?

First, you need to know how you would trade. Let's take a simple example to illustrate how the Strategy Builder works. This is one of the most basic strategies that are common out there among the traders—the Moving Average Crossover.

Just to clarify, we're not here to recommend using this strategy to trade. It's just an example to illustrate how the Strategy Builder works and it's good as an example because most traders are already familiar with it.

Strategy configuration

Let's set up the Moving Average Crossover strategy using the Strategy Builder.

1. Parameters

Here's what we know about our situation:

  • We know our trading budget, let's say that's $2,500.
  • We have a risk management strategy in place, and we're willing to risk 1% of our budget on each trade. That's $25 per trade.

Now let's look at the strategy itself. The Moving Average Crossover strategy is effective on higher timeframes, so let's use the 4-hour timeframe. At the same time, we don't have any preferred currency pairs, so we'll include all instruments in our strategy.

We'll pick both buy and sell trades as part of our strategy.

Finally, we need to determine how far back our backtesting will go. Since this is a relatively high timeframe strategy, we'll go back at least 1 year. So we'll set the start and end dates to be 1 year apart with the end date being yesterday.

Strategy parameters screenshot

Don't forget to give your strategy a name and, optionally a description (they can be anything as long as they make sense to you). We can then move to the next step.

2. Entry Rules

This is where we define the conditions for entering a trade.

These rules are going to be executed against each candle in the backtesting period (each H4 candle for the past year, as we configured at the previous step), for each instrument (i.e. currency pair) that we configured previously.

When the buy rules are met, a buy trade will be created. When the sell rules are met, a sell trade will be created.

Keep in mind that a new trade will only be created if there isn't one open already for the same instrument. The strategy will not open multiple trades for the same instrument at the same time.

You only need to define the BUY rules, the SELL rules will be generated automatically for you by mirroring the BUY rules.

Our strategy is simple, there is a single rule for entering a BUY trade: when the 20-period Simple Moving Average (SMA) crosses above the 50-period SMA. The "period" here is a 4-hour candle.

So we'll do this:

  1. Create a new rule
  2. Select Instrument
  3. Select SMA in the list of instruments
  4. Set length to 20, leave source as Close
  5. Click Use and then select Cross over... > Cross over
  6. Then again select Instrument
  7. Select SMA in the list of instruments
  8. Set length to 50 this time, leave source as Close
  9. Click Use
  10. Click Done

The SELL rule will be created automatically for you, and it will be the opposite of the BUY rule (Cross under instead of Cross over).

Strategy entry rules screenshot

Screen recording of creating an entry rule (mp4)

So, as part of our strategy, we'll be entering buy or sell trades over the past year on H4, for any of the instruments we selected, whenever the rules we configured are met. If we had more than a single rule, all of them would have to be met at once for a trade to be created.

The trade will continue to be open until either:

  • The Stop Loss rule kicks in,
  • The Take Profit rule kicks in or
  • The Exit rules are met

3. Stop Loss

This is where we define the conditions for closing a trade with a loss. The Stop Loss rule is mandatory in a strategy.

Because our strategy applies to different instruments, it wouldn't make sense to have a fixed value in pips for the Stop Loss. Instead, we'll use the Average True Range (ATR) to determine the Stop Loss value.

In this case, let's settle for a 1.5 x ATR value for the Stop Loss. This will give our trades some room to breathe.

Strategy stop loss screenshot

When/if the current trade would go into a loss by 1.5 x ATR (with length of 14 and SMA smoothing), the trade will be closed with a loss, effectively losing $25 (as per our initial configuration of the strategy for 1% from $2,500).

4. Take Profit

This is where we define the conditions for closing a trade with a profit. The Take Profit rule is mandatory in a strategy.

We can determine the Take Profit based on the Stop Loss we established at the previous step by using Risk to Reward.

Strategy take profit screenshot

Let's go for a 1:2 Risk to Reward ratio. This means that the Take Profit will be twice as large as the Stop Loss. In other words, if the Stop Loss is 1.5 x ATR, the trade will have to go into a profit of 3 x ATR to be closed with a profit.

5. Exit rules

If you need to better control when the trades are closed, you can define Exit rules. Specifying exit rules is optional in a strategy, because closing a trade is already handled by the Stop Loss and Take Profit rules.

Exit rules apply in the same way as Entry rules, but they are executed when the trade is already open. If defined, when all BUY Exit rules are met, the trade will be closed (if it's a BUY trade). The same goes for SELL trades.

For our strategy, we could add an Exit rule that would close the trade if the Moving Average crosses back under the 50-period SMA.

But we'll skip this step for now, because our strategy is too simple for Exit rules.

6. Review and run the strategy

Once you've configured all the steps, you can review the strategy and run it. This means it will be simulated based on how we configured it against the past year of data.

Running a strategy can take a while, depending on its complexity. But once it's done, you can see the results and determine if the strategy was profitable or not.

Strategy results screenshot

Based on the results, you can determine if the strategy is worth pursuing further or if it needs some adjustments. You can duplicate the strategy and make changes to it to see how it would have performed with different settings.

Happy strategising!

Last updated: 28 Dec 2024

See also