Sunday, January 27, 2013

Meta-Trader - Range Bands - Part 2

Welcome back, Meta-Traders.

As promised, here is part 2 in my series on the Range Bands indicator.  If you missed part #1, check it out here.

In this post, we create a Meta-Trader Expert System to trade the range bands indicator and test it out on our favorite Forex pair EUR/USD.  We also make some interesting observations about seasonality, so read on for that.

The trading logic is extremely simple as follows:
  • If bar closes above the upper range band, buy.  If already in a short position, close the short position before going long.
  • If bar closes below the lower range band, sell.  If already in a long position, close the long position before going short.
  • Risk 0.05 of the account per position using our standard lot sizing algorithm discussed early in the history of this blog
  • Run tests against the hourly charts although the expert is also coded to run at any other time frame
  • Calculate the range bands against a 14-bar look back of whatever time frame Meta-Trader is using at the time.
  • Also, I ran the back tests using the "Open Prices Only" option, so tests were lightning fast and the took only a matter of minutes rather than the hours it takes for the "Each Tick" method.
The first round of back-tests were pretty terrible as expected. In a 12-year back test, the results were negative in 10 out of 12 years.  Even worse, the draw down nearly always exceeded the profits, most of the time by a factor of 2x1.  2006 is a good example, where the system lost -24% for the year, but suffered -44% in draw down.  The only good year was 2010 where results were clearly spectacular returning 134% for the year with only -32% draw down.

These results were consistent with just about every other trend-following EA that I have coded.  Whether its a Moving Average Crossover or a Donchian breakout (breakout of X-bar high) the results were the same.  Bottom line is that Forex is just to whippy a market with too many false breakouts to work well with a trend-following system most of the time.   That's most of the time, what about part of the time?

We know from my prior post Fun with Forex Historical that the second week of January has the largest amount of movement of any other week of the year based on a 20-year study.  And we also know that January has a strong seasonal effect in the stock market.  So what if we limited our trading to just January? Would that change the results?

I went back and ran the expert for each of the 12 years, but used the date range feature of MT4 back-tester to start trading on 1/1 of the year and end of 1/30 of the year.  Lo and behold, the system turned a profit for 7 out of 12 years!  Overall, the system turned a small average yearly profit, but average draw down was still many times larger than average profit.

Not willing to leave it at that, I coded the EA to check for the month and only trade in the month of January by adding this code:

if (Month()!=TradeOneMonth)
{
   CloseOpenTrades();
   return(1);
}

Print("Proceeding with month: ", Month());

I made the variable TradeOneMonth to be an external parameter passed into MetaTrader.  This would allow   the following improvements:
  • Allow for a single 12-year back test where only the month of January was traded
  • Allow for optimization across the 11-year period to see if any other month of the year was more profitable than January.
  • I also adjusted the EA to close any open positions as of February 1st to prevent any side-affects from positions open in January staying open all year until the next January.
This time the results were even better with an average annual profit of 3.87% but with Drawdown still pretty high at -14.28%.   But when you consider the fact that this capital is only deployed one month a year and can be deployed elsewhere the other 11 months of the year, the results started to get interesting.

Next, I ran an optimization over the entire 12-year period to see what would happen if I only traded February, or only traded March etc.  This would add some scientific rigor and show that the January effect was indeed real, or not as the case may be.

The results are shown below.

The bottom line is January was the most profitable month to trade by a factor of 3!  Drawdown was also highest in January, but only about 30% above other months which shows only about 30% as much profit.

Bottom line is this.  Trend trading in Forex is not profitable most of the time, but shows a strong seasonal tendency to be profitable in the month of January.

The next step is to code the Range Bands system in TradeStation and run some back tests with Forex to compare the MT4 results with those of TradeStation.  That should be interesting it itself, and get me started coding trading systems in EasyLanguage, the language of TradeStation.

I uploaded the expert system to my Yahoo group at FX-Mon group. Use in good health and have a great week.

No comments:

Post a Comment