July 13

14 comments

Improving The Simple Gap Strategy Part 3

By Jeff Swanson

July 13, 2015

automated trading, Automated Trading Development, EasyLanguage, ES, gap, S&P Emini, stock index futures, strategies

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.

Baseline

Up Day

Down Day

Net Profit

$2,4865

$880

$23,985

Profit Factor

1.2

1.01

1.46

Total Trades

1,183

621

562

%  Winners

72%

68%

77%

Avg.Trade Net Profit

$21.02

$1.42

$42.68

Annual Rate of Return

1.48%

0.06%

1.43%

Max Drawdown (Intraday)

5.2%

6.5%

3.84%

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.

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

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

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?

Jeff Swanson

About the author

Jeff has built and traded automated trading systems for the futures markets since 2008. He is the creator of the online courses System Development Master Class and Alpha Compass. Jeff is also the founder of EasyLanguage Mastery - a website and mission to empower the EasyLanguage trader with the proper knowledge and tools to become a profitable trader.

  • 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.

  • 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?

      • 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?

  • 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.

  • 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.

  • {"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

    Learn To Code & Build Strategies
    Using EasyLanguage. 

    >