Apr
01

Thoughts on Backtesting and Its Effectiveness

Backtesting is a convenient way for showing what could have happened had your trading system traded through the past. Backtesting in Metatrader 4 leaves some things left desired.

Caveats With Backtesting in Metatrader 4

For starters, Metatrader 4′s backtesting engine can only backtest to 1 minute accuracy. In a given minute, there could be as many as 110 ticks (as per my measuring). Those fluctuations in price are not always captured accurately in Metatrader 4′s backtester. If your trading system has trades that are open maybe 30 minutes or less on average, there is a good chance that they are not accurately represented.

Calculation of the spread is also not particularly accurate. Metatrader 4 as of build 416 seems to use the most recent spread for a given currency pair. That means during the week–when the spreads tend to be smaller–most backtests will show a better result than backtests performed during the weekends–when spreads are at their widest.

The biggest problem is backtesting multiple currency pairs. There are a growing number of trading systems which take advantage of high positive or negative correlation between currency pairs in an effort to achieve higher returns. Metatrader 5 attempted to compensate for this, but that step forward was significantly hindered by numerous other limitations that I’d rather not go into.

How to Setup the Best Backtest Within Metatrader 4

Above all else, there is one thing that you need to make sure you have if you expect to have an accurate backtest. The finer the data, the more accurate your results. The absolute best source of data is recorded price data. The problem with this datasource is it’s often incredibly expensive, and time consuming. The most accurate free and reliable source of data available can be found here: (http://www.forextester.com/data/datasources.html)

I generally keep a dedicated metatrader terminal strictly for backtesting. It’s a lot easier to manage the data.

Clear Out Old Data

The first thing you should do is remove any old and potentially gapped data. To do this, you need to:

  1. Exit Metatrader Terminal if you haven’t done so already.
  2. Navigate to the [MetatrderFolder]\History folder.
  3. Select the folder with the same name of the server you are using.
  4. Delete all .hst files associated with the currency pair that you intend to test.

Acquire and Add New Data

Once you’ve cleared out the old data, you need to acquire and import the new data.

  1. Download the most continuous data possible. This is the best place to get free minute-level data (http://www.forextester.com/data/datasources.html)
  2. Unzip the file.
  3. Start Metatrader Terminal
  4. Press F2 or go to Tools -> History Center
  5. Navigate to the currency pair and the 1M (one minute) timeframe.
  6. Click Import
  7. Load the file you unzipped in step 2.
  8. Look for the input relating to GMT shift. You need to make sure the data you receive is shifted accordingly to match with your broker.
  9. Click OK to import the data. Note: It may appear that Metatrader 4 isn’t working properly, or has frozen. To check, open up Task Manager (Ctrl+Alt+Del), go to the process tab, and look for ‘Terminal.exe’. If that process is using up CPU and RAM, then Metatrader 4 is still working. To import 10 years of data takes somewhere in the neighborhood of 5-10 minutes if you have a fast computer.
  10. Once you’ve imported the data you need to convert it. Exit out of the history center, and open up a chart on the 1 minute timeframe for the currency pair you just imported.
  11. Look for the script ‘Period_converter’ and attach it to the chart.
  12. The script will ask you for a multiplier input. Make sure to set up the proper multiplier for the timeframe you intend to backtest in. What this script will do is it will take the 1 minute data, find the open, high, low, and close of the data in a specific time range, and use that data to create the open, high, low, and close of the higher timeframe.

Once you’ve completed the data import and conversion, you have given yourself the cleanest data possible to perform the backtest of your EA(s).

 

Mar
25

What I Think is the Holy Grail

When you go to a trading forum of any kind, there will inevitably be talk about the ideal trading system. It’s from these interactions with people that you can readily guess their level of experience.

The absolute best trading system should:

  • Always win 100% of trades
  • Never have a floating loss

The reality is far from this utopia.

Components of an Ideal Trading Algorithm

My ideal trading algorithm is made up of three components:

  1. Large positive edge
  2. Self adapting
  3. Hands free

Large Positive Edge

Trading systems are generally a tradeoff between two characteristics:

  1. Win Rate
  2. Risk / Reward

Assuming a completely random game of chance, the Win Rate multiplied by the Reward divided by the Losing Rate multiplied by the Risk should always be greater than or equal to 1 in order to not lose money. Let’s take a standard coin toss. If I were to offer you a coin toss game where you pay me $1.00 and if the coin lands heads up, I’ll give you your $1.00 back. If the coin lands tails up, I keep the $1.00 you gave me. Using the formula I mentioned above:

  • Win Rate: 50%
  • Risk: $1.00
  • Reward: $1.00

[(0.50) * 1.00] / [(1.00 - 0.50) * 1.00] = 1.00

In the long run, you expect to break even. When applying this to trading–and the transaction costs involved–breaking even isn’t enough.

Here’s a revised example, it costs $0.01 for every coin toss. If heads, I keep your dollar, if tails, you get your dollar back. Considering the transactions now:

[(0.50) * 1.00] / ([(1.00 - 0.50) * 1.00] + 0.01) = 0.98

In the long run, you expect to lose 2% of your capital. Not ideal. This is the same as applying the spread.

Self Adapting

It’s common knowledge that markets are based on human decisions. The political atmosphere of the day coupled with public opinion on various topics shapes the characteristics of the markets. There are certain trading systems in existence that are suited for particular market characteristics. In order for this trading system to be fully robust, it needs to be capable of anticipating, and reacting to future events, particularly ‘Black Swans’.

Adapting doesn’t necessarily mean changing itself completely. It could be as simple as changing expectations, or reallocating capital accordingly.

Hands Free

After being programmed once, the ideal trading algorithm should not require any additional input or help. It should be programmed to follow or take advantage of a universal market trait–the kind that will not change forever.

 

Mar
18

My Thoughts on Trading

Characteristics of Traders

In my eye, trading isn’t so much about gaining as much capital as possible as it is about preserving existing capital first. In a way, it’s the opposite of a traditional business–profit first, liability second. When trading, you should always consider you liability prospects before considering your profit. It’s almost akin to playing the devil’s advocate against yourself, or more specifically, your prospective trades.

That said, a trader requires three things: Bucks, Brains, and Balls:

Bucks

Without money to trade, you aren’t much of a trader.

Brains

Without the proper knowledge and a trading system to manage your bucks, you will soon lose those bucks and not be much of a trader.

Balls

Without the courage to trust your Brains and your trading system to continue to follow their expected performance, you’ll make mistakes, soon lose those bucks and not be much of a trader.

Characteristics of Trading Systems

A trading system needs to account for every possible outcome. It should be rule-based and as rigid as possible. Any thinking required of the trader means the trading system has failed. It’s similar to a checklist. Checklists help the individual following a set of instructions keep track of their progress. There is relatively little thinking going on, and there are predictable outcomes.

The best trading system accounts for all possibilities for each condition. There should be no presumption as to what is ‘supposed’ to happen. If it’s supposed to happen and doesn’t, the error is with the system, and not the trader.

There should be defined entries, defined exits, and defined trade management. There should be no ambiguity at all. If I need to ask a question about a trading decision, there is a problem with the trading system.