Saturday, May 18, 2013

Meta-Trader - Fading the Gap

Welcome back traders.

In this post, let's delve into John Carter's excellent book Mastering the Trade.  It was interesting to find out that this book contains many ideas which can be tested programmatically.  And I find that to be more than a bit ironic since John Carter himself doesn't do any automated trading.  But he does follow defined setups, and this was the first one in the book and it goes like this:

- Use this system on the broad market indices, either the stock index futures or the broad market ETFs such as SPY or DIA.  I tested it against DIA which is the ETF for the Dow Jones Industrial Average.

- When the market opens with a gap greater than 10 Dow points and less than 70 Dow points,  fade the gap.  In other words, if the market gaps up, sell short and if the market gaps down, go long.

- Close the trade when the gap is closed (as in the example on the left) otherwise close at the end of the current day at the market price.

- Stop loss is 50 Dow points, however John Carter recommends a stop at 1.0 to 1.5 times the gap size.  I didn't find the results to be much different when using Carter's formula versus a fixed stop.

Coding this system took some trial and error but I have to say its a complete pleasure to work in this environment versus Meta-Trader. TradeStation by default will evaluate systems once per bar.  When I tested it against the hourly bars, it would not enter a position until 10:30 AM.  So I ran it against the 5-minute bars and TradeStation had no problem pulling up and executing the system against 5-minute bars for the past several years.  This was a major relief vs Meta-Trader where you could not trust the results of 5-minute bars due to the bar interpolation issue.  Also, getting reliable data inside MT4 is a challenge to say the least. What an amazing tool TradeStation is and I am so glad to be done with MT4!

Code for the system is pretty simple and looks like this:

{* Index Gap Fade down *)

var: bool GapDn(false);
var: double DistanceInPoints(0.0);

{* Did we gap down?*}
GapDn = Open < CloseD(1);

{* How big was the gap, will always be positive *}
DistanceInPoints = closeD(1) - Open;

{* Greater than 10 and less than 70 Dow Points and 9:35 AM *}
if GapDn and DistanceInPoints > 0.1 and DistanceInPoints < 0.7 and time = 0935 then Buy ( "FadeGapDn" ) at next bar at market;

{* Stop a stop of 50 dollars, we are trading 100 shares *}
SetStopLoss(50.0);

Results for the system are shown in the table in percentage return of invested capital. 

- For the past 8 years, returns ranged between -0.55 and +1.16% per year. 

- Against the entire 7+ year test period, the system returned 2.56% with about -0.38% drawdown.

- Percentage profitable was just over 63% showing the system definitely does have a positive statistical bias

JC references an analysis where he shows that gaps are less likely to fill on Mondays than other days of the week and some other conditions (last day of the month etc) which I did not include in my analysis.

One weakness of this system that it loses money on days where the market gaps up and does not look back.  Since the stock market has a positive bias over time and certainly over the test period, the system fights the trend in that respect.  We can see that in the results where buying the gap down makes twice as much overall as shorting the gap up.

Overall results from this system are not stellar.  To make a living in active trading, we want to make about 1% per day on our assets at risk. But this system is just one of many tools in our arsenal of money making techniques.

I will upload the TradeStation code to my Yahoo Group and notify the list.

Have a great weekend and week ahead.

1 comment:

  1. 당신의 블로그의 다음 업데이트를 계속 체크 아웃하기를 기대합니다.
    외환거래

    ReplyDelete