Improving The Simple Gap Strategy Part 3

In the last article in this series, Improving The Simple Gap Strategy Part 2, I tested two filters on the OOS sample data. The first filter was a day-of-week (DOW) filter which did not produce decent results.  The second filter, Gap Size, did show promising results. Reviewing my notes from years ago, I also discovered that the size of the gap will play an important factor in the success of many gap strategies. So, this was not a surprise. It was something I should have recalled, but it was worth testing again. In this article I’m going to test a another idea. At the conclusion of this article you will find the free EasyLanguage code for this strategy.

Testing Environment

Because I’m currently testing and developing this trading model I’m going to be using my in-sample portion only. Before getting into the details of the results, let me say this: all the tests within this article are going to use the following assumptions:

  • Starting account size of $100,000
  • In-sample dates are from 1998 through December 31, 2012
  • One contract was traded per signal
  • The P&L is not accumulated
  • $20 was deducted per round-trip for slippage and commissions

Previous Day’s Price Action

The idea is to determine if the previous day’s direction has any impact on the baseline system. That is, does the performance of the Simple Gap Strategy depend upon if yesterday was a down day or an up day? This will be simple to test to perform. I will create a flag indicating if yesterday was an up day (Close <= Open) or a down day (Close > Open). From there we can test each of the two conditions by only taking trades when the previous day was a up-day. Then I’ll run the test again only taking trades when the previous day was a down-day.

Below is a table of the results. The “Up Day” column displays the results if trades are only taken if yesterday’s close was higher than its open. The “Down Day” displays the results if trades are only taken if yesterday’s close was lower than its open.

Simple Gap Previous Day Filter Results

Notice the number of trades in the “Up Day” column (621) added to the number of trades in the “Down Day” column (562) add up to the baseline total of 1,183. So, we have a nice clean divide with all trades accounted for.

The “Up Day” column shows a severe decrease in performance. If yesterday’s price action produces an up-day, it sure looks like that this gap fading strategy will probably not work out very well. On the other hand, if yesterday was a down-day, this gap fading strategy does rather well. We produce about the same amount of profit with about half the trades. As you can see, by looking at the “Up Day” column, we eliminated some very unproductive trades as we are taking only 562 trades. This produces a significantly better profit factor and average profit per trade.

The next question you might be asking yourself is this, is there a significant difference between long and shorts? That’s a good question. The results in the table above combine both long and shorts. Recall, we are taking both long and short trades during each of the two tests. Thus, it’s possible that shorting during the “Up Day” filter is doing really well, but the overall results are being destroyed by poor performance on the long side. Looking at long trades and short trades individually should be done. Looking at the TradeStation performance report I can see both long and short trades during the “Up Day” filter are horrible.

As for the “Down Day” filter both long and short trades produce decent results. I’ve separated the long from short trades and generated two equity graphs to demonstrate the difference. First equity graph, below, is the short trades only during “Down Day” filter.

Gap_Short_Only_DownDays

Next is long trades only during the “Down Day” filter.

Gap_Long_Only_UpDays

 

If you combine the long and shorts you get the following equity graph.

Gap_EQ_Curve_DownDay_Filter

Overall, there is a lot of choppiness in the early few years, but this is nothing different from the original strategy.

Conclusion

In summary the filter based upon the previous day’s price action does appear to help improve the overall performance so, I think we can keep this filter to test on the OOS. This means we now have two filters, the Gap Size and the Previous Day. I won’t combine these filters and test them on the OOS yet. There are still other ideas to test which will appear in another article. Some of the ideas include:

  • What about dynamic exit as a percentage of the gap size?
  • What about a dynamic stop as a percentage of the gap size?
  • What about holding a trade through the end of the day?
  • What about exiting a trade after so many consecutive winning bars?

Downloads

The free EasyLanguage code for this strategy is below. There is also a text version of the code which can be used to help convert this strategy to another platform. For the TradeStation WorkSpace please download the file from one of the previous articles. You’ll find links to the previous articles below.

Gap Strategy With Previous Day Filter (TradeStation ELD)
Gap Strategy With Previous Day Filter (Text file)

Other Article In This Series

About the Author Jeff Swanson

Jeff is the founder of System Trader Success - a website and mission to empowering the retail trader with the proper knowledge and tools to become a profitable trader the world of quantitative/automated trading.

follow me on:
  • Maverick says:

    Dear Jeff,
    Do you think the reason why the result is as it is is because the market inherently has upside bias?

    • Maverick, that could be the reason. It’s hard to say for sure, but there is no doubt there is a longer term bias to the upside. For shorter time frames, like what the gap strategy uses, I’m not so sure this bias comes into play.

  • Paul Mayer says:

    Jeff, I am using Multicharts (compatible with Tradestation Easylanguage), and when I copied and pasted the text version of the code into the “Powerlanguage editor” and attempted to save the code, it generated an error, saying that _C_E Expectancy was an unknown function. The error it generated was this:
    —— Compiled with error(s): ——
    Unknown Function
    line 47, column 9

    And line 47 was this:

    Value1 = _CE_Expectancy( “Gap Fade #1”, value2, value3, true );

    I have been really interested in gap fading for years and would love to have this code working to experiment with it. Can you by chance send me or post the CE Expectancy Function? Or build it into the Strategy code?

    • Paul, you can simply delete that line and it should compile fine.

      • Paul Mayer says:

        It did compile, but won’t run — I turn it on, and then Multicharts automatically turns it off. That will normally happen if the Max Bars Back is insufficient, but that’s not the case here, as it should only need 101 bars for the trendfilter and I set the MaxBarsBack to 501 just to be safe. I am assuming the ES futures should be set to US stock regular trading session. Anything else you can think of that would prevent Multicharts from running this strategy?

        • Paul, sorry I won’t be of much help as I don’t use Multicharts. The workspace I use does use a custom session which is 830 – 1515 central time. The compatibility of some of the functions may be an issue. I would see if you could get any of the older versions of the gap strategy to run from other articles in this series. This might help isolate the problem. Maybe someone else reading this who is familiar with Multicharts can help?

  • Marco says:

    Great article Jeff, I think the main problem in adding more filters is that we cut the trade frequency. I think also the gaps following up days can be considered adding other filters. Collecting everything together would result in a strongly reliable fading strategy.
    https://nightlypatterns.wordpress.com

  • Scott says:

    You should really look over at MasterTheGap.com and how they trade gaps. I used to follow their site a few years ago so they may have changed things now, but here are some of the things I liked when trading gaps

    – stop = 30% of 5-day ATR
    – you have to look at which “zone” the market opens in relative to yesterday’s close and whether or not it was an up or down day – http://www.masterthegap.com/public/Gap_Zone_Map.cfm
    – market conditions are considered, like position of moving averages relative to each other
    – seasonality also matters, day of week, month of year, day of month, others
    – price patterns, like 3 down days, or price is down after just making a 10-day high, things like that

    • Thanks Scott for the link and for the ideas! I did look at that site many years ago and remember vividly the gap zones. It’s something I’ve not looked at in a long time. This makes me a think an entire series of gap articles, which go beyond the current gap strategy, may be a great addition. I’ve really not looked at gap trading in many years.

  • Ryan says:

    Jeff, take a look at my (free) site under the special reports section for more gap testing ideas.

    https://daxgaptrading.wordpress.com/special-reports/

    Ryan

  • Rich S. says:

    Jeff, Extended the Data to 6/30/2015 so as to get a look at OOS data. Not encouraging, appears to be rolling over. Typical of most algo systems, unfortunately, frustrating.

  • >