gap fade – Helping you Master EasyLanguage https://easylanguagemastery.com Helping you Master EasyLanguage Sun, 22 Jan 2023 00:28:09 +0000 en-US hourly 1 https://wordpress.org/?v=7.1.5 https://easylanguagemastery.com/wp-content/uploads/2019/02/cropped-logo_size_icon_invert.jpg gap fade – Helping you Master EasyLanguage https://easylanguagemastery.com 32 32 Gap Strategy Tool https://easylanguagemastery.com/building-strategies/gap-strategy-tool/?utm_source=rss&utm_medium=rss&utm_campaign=gap-strategy-tool https://easylanguagemastery.com/building-strategies/gap-strategy-tool/#comments Mon, 22 Apr 2019 10:00:19 +0000 http://systemtradersuccess.com/?p=9420

Years ago I attempted to create a gap fading strategy. None ever worked enough for me to trade consistently. Years later I ran into Scott Andrews and his PDF called, “Understanding Gaps”.  This looked interesting but I never really did much with it. Well maybe it’s time to revisit gap fading strategies. If you know what a gap trade is. If not, please take a look at this article before going any further.

After reviewing the eBook I thought it would be a good idea to begin building a strategy tool to help analyze gaps. The tool will be written in EasyLanguage and I envision it being loaded into a chart where it will provide various statistical based results on gaps. Information such as…

  • Probability of a gap closing based upon gap size, day of the month, and day of the week
  • Probability of a gap closing based yesterday’s price action.
  • Probability of a gap closing based upon recent market conditions such as price above below an SMA
  • The impact of stops on trading gaps
  • The impact of profit targets on gaps

These are just a few ideas off the top of my head. It’s a tall order to build such a testing tool so, we’ll start out very simple for this first article. In future articles we’ll build upon the original concept. Hopefully, the final strategy tool will be helpful to many readers. Let’s get started.

The first metric analyzed in Scott’s eBook is the probability of a successful gap trade taking place based upon the size of a gap. Since Scott picked this as the first metric I’m going to start with gap size as well.

In the end we want to know how often a gap closes based upon its size. Do larger gaps fill less often than smaller gaps? To figure this out we’ll need the following information:

  • The total number of gaps
  • The number of gaps for each gap-size category
  • The number of successful gap closes for each category

Before we can do anything, we first need to correctly compute the gap size.

Computing Gap Size

The most obvious way to measure the size of a gap is to use the number of points or ticks from today’s open from yesterday’s close. That is:

Gap Size = Today’s Opening Price – Yesterday’s Closing Price

This will give us what we want but gap sizes will likely change based upon the instrument you’re trading. For example, let’s say we determine that a 10-point gap in the S&P eMini futures closes most of the time. Then we must ask, what happens when we move to a stock or other future contract? A 10-point gap in one instrument may mean something completely different in another instrument. This would not be a big deal if I was simply creating a testing tool for the eMini. However, I want this tool to work on a variety of instruments.

Furthermore, consider how gap sizes may change when you take into account changing market volatility. Over the years volatility in any given market will change. A 25-point gap today on the eMini may not be the same as a 25-point gap in five years. Put another way, gap sizes will likely expand during a more volatile periods and shrink during more quiet times. Using static values to categorize gap size may not be the best idea.

Scott proposed a way to normalize gap sizes based upon the average true range of the market. He does this by using the average true range over the past five days. Scott simply measures the gap size in points (or ticks) and divides this value by the 5-day average true range. Below is the formula.

Gap Size = ( Today’s Opening Price – Yesterday’s Closing Price ) / 5-Day Average True Range

Now we know how to compute a meaningful gap size let’s move on.

Gap Group

On the first bar of a new day the gap size will be computed and categorized into one of six different groups. It will also be important for us to track the total number of all gaps. This is done by simply incrementing a counter each time we have a valid gap. What is valid gap? Well, at this time that would be a gap size that is at least 4 ticks (a minimum price move is one tick). If a gap is smaller than this size, it will be ignored.

Following Scott’s lead, I’m also going to create six buckets or groups to describe the size of gaps. Each group represents a percentage of their 5-day ATR.

  • Group1 – Gap Size < 20%
  • Group2 – 20% > = Gap Size < 40%
  • Group3 – 40% >= Gap Size < 60%
  • Group4 – 60% >= Gap Size < 80%
  • Group5 – 80% >= Gap Size < 100%
  • Group6 – 100% >= Gap Size

Once we know which group a particular gap belongs to I also increase a counter for that group. This way, we’ll have a tally for each of the different types of gaps. Here is the code for determining the gap size, categorizing the different gap groups and increasing the appropriate group counter.

GapSize = absvalue( PrevClosed - TodaysOpen );
Percent = GapSize / FiveDayATR;

if ( GapSize > minGapSize ) Then
Begin

GapCount = GapCount + 1;

If ( Percent < .20 ) then
Begin
CurrentGapType = 1;
Group1 = Group1 + 1;
End

Else if ( Percent < .40 ) Then
Begin
CurrentGapType = 2;
Group2 = Group2 + 1;
End

Else If ( Percent < .60 ) Then
Begin
CurrentGapType = 3;
Group3 = Group3 + 1;
End

Else If ( Percent < .80 ) Then
Begin
CurrentGapType = 4;
Group4 = Group4 + 1;
End

Else If ( Percent < 1.0 ) Then
Begin
CurrentGapType = 5;
Group5 = Group5 + 1;
End

Else Begin
CurrentGapType = 6;
Group6 = Group6 + 1;
End;

Counting Gap Closes

What is success? When a gap is closed. I’m going to look for this by using the MP function. The code below detects when a trade was closed on the previous bar. If this happens we increment a “success” counter for the particular gap size we were trading.

If ( MP = 0 ) and ( MP[1] <> 0 ) Then
Begin

If ( CurrentGapType = 1 ) then Group1Closed = Group1Closed + 1
Else if ( CurrentGapType = 2 ) Then Group2Closed = Group2Closed + 1
Else if ( CurrentGapType = 3 ) Then Group3Closed = Group3Closed + 1
Else If ( CurrentGapType = 4 ) Then Group4Closed = Group4Closed + 1
Else If ( CurrentGapType = 5 ) Then Group5Closed = Group5Closed + 1
Else If ( CurrentGapType = 6 ) Then Group6Closed = Group6Closed + 1;
End;

Now we’ll have everything we need to compute the percentage of gap fills that occur based upon the size of the gap.

Printing The Results

When we have run through the entire price history we’ll want to print our results. The most direct way to do this in TradeStation is to use the “Print” command to send text to the Print Log window. Since we know the number of total successful gap fills that took place and the total number of gaps that occurred based upon the gap group, it’s a simple step to compute the percentage of gaps which filled by dividing the group total by the total gaps counted. Below is the code which handles this.

If ( LastBarOnChart ) Then
Begin
Print( "Number of Gaps...: ", round(GapCount,0) );
Print( "Group 1..........: ", round(Group1,0), " (", Group1Closed / GapCount, ")" );
Print( "Group 2..........: ", round(Group2,0), " (", Group2Closed / GapCount, ")" );
Print( "Group 3..........: ", round(Group3,0), " (", Group3Closed / GapCount, ")" );
Print( "Group 4..........: ", round(Group4,0), " (", Group4Closed / GapCount, ")" );
Print( "Group 5..........: ", round(Group5,0), " (", Group5Closed / GapCount, ")" );
Print( "Group 6..........: ", round(Group6,0), " (", Group6Closed / GapCount, ")" );
End;

Results

I’m now going to execute this over the eMini (ES) from 2006-2015. To do this, all I need to do is load the strategy tool into the chart. Below is an image of the strategy tool running on a 5-minute chart.

Gap Size Strategy Tool running on 5-minute bar of Emini

The results are then printed within the Print Log window once the analysis is complete.

Gap Size Strategy Tool grouping by gap size. Number of gaps (percentage close)

What we see in the Print Log is 2381 gaps were counted. Each Gap Group lists the number of gaps along with the percentage of gap fills in parenthesis. Thus, Group 1 sees 35% of the gaps completely fill within some time during the day while Group 6 only sees 2% of the gaps fill.

When you first compare these results to what Scott has in his eBook you’ll likely see a big difference. This confused me at first until I realized that Scott defined a “successful trade” as one that made money. In the strategy code I built, I defined a “successful trade” as closing the gap. I did this because it was the most straightforward event to code at this time.

Which method is better? I’m leaning towards a more nuanced definition. I do like the idea of a successful trade not necessarily meaning a gap close but instead, just being profitable. I can imagine one could build systems that don’t rely on a gap closing every time. Many points could be harvested from a market without the need for a gap to close. So, I think my first step in modifying this code will be to incorporate some other methods of measuring success.

Conclusion

This is the first step in building our gap analyzer and it’s very basic. However, we must start somewhere. As pointed out in the above paragraph, the definition of success will likely be modified in the next article. Scott also recorded profit factor for each of the different gap groups. Thinking about it at this very minute I kind of like the idea of recording potential profit vs drawdown. That is each trade will have a theoretical maximum profit (a gap close) and a theoretical maximum drawdown (how much heat you must take before reaching a gap close).

Future articles will expand upon this idea adding more analysis and in the end, we’ll hopefully have something useful when exploring possible gap trading opportunities.

]]>
https://easylanguagemastery.com/building-strategies/gap-strategy-tool/feed/ 2
Improving The Simple Gap Strategy, Part 1 https://easylanguagemastery.com/strategies/improve-simple-gap-strategy/?utm_source=rss&utm_medium=rss&utm_campaign=improve-simple-gap-strategy https://easylanguagemastery.com/strategies/improve-simple-gap-strategy/#comments Mon, 17 Nov 2014 11:00:21 +0000 http://systemtradersuccess.com/?p=6762

Let’s try to improve upon the gap strategy that was provided by Ben Little’s article entitled, “Testing A Simple Gap Strategy.” In this article Ben demonstrated a simple trading model called, Gap Fade 31, based on the opening gap in the S&P futures market. This was the first gap based article on System Trader Success and it drew a fair amount of attention. Personally, I’ve not looked at gap strategies since 2008. I never did find a gap strategy that I liked. However, I thought this would be a good time to review some concepts I’ve not reviewed in many years.

Gap Fade #1 Trading Model

This trading model opened positions in the opposite direction of a gap. Thus, up-gaps were faded by going short and down-gaps were opportunities to go long. A hard stop value and profit target were placed after a new position was opened. For a more complete description please see the original article.

The trading model utilized two important filters.

  1. A market regime filter which divided the market into Bull or Bear. This was accomplished with a 100-period moving average applied to the daily data.
  2. Range filter which limited to taking trades only if today’s opening price was contained within the previous day’s range. That is, if today’s opening price was above yesterday’s intraday high or low, the trade was not taken.

Ben tested the validity of the regime filter in the original article. By the term “validity” I’m referring to the regime filter to provide value. Clearly the regime filter provided value by reducing unproductive trades and dramatically improved results as seen in the original article. The regime filter forces the trading model to take long trades only taken during a bull regime and short trades only taken during bear regimes. This makes logical sense and helps give credence to the model. Ben also tested the robustness of the regime filter which held up well.

Testing Environment

Because I plan on running some tests I’m going to break my historical data into two portions. An in-sample portion and out-of-sample portion. Thus, when I’m finished with my back-testing I’ll have a portion of the data to test the modified trading model on.

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

Baseline Results

Based upon our assumptions above, here is the baseline performance of the trading model. I’ve also attached the TradeStation performance report: Gap_Strategy_Baselin.xls.

Gap Fade #1

Baseline

Net Profit

$24,118

Profit Factor

1.2

Total Trades

1,118

% Winners

72%

Avg.Trade Net Profit

$20.42

Annual Rate of Return

1.44%

Max Drawdown (intraday)

5.2%

Testing the Importance of the Range Filter

I would like to test the validity of the range filter. So, in the test below I simply removed the range filter allowing the trading model to take trades that were outside of the previous day’s range.

Gap Fade #1 No Range Check

Baseline

No Range Check

Net Profit

$24,118

$4,220

Profit Factor

1.2

1.02

Total Trades

1,118

1,674

% Winners

72%

70%

Avg.Trade Net Profit

$20.42

$2.52

Annual Rate of Return

1.44%

0.28%

Max Drawdown (intraday)

5.2%

9.82%

Here we clearly see that avoiding trades that fall outside of the previous day range improves the results. The range check is valid.

Testing Day-of-the-Week Filter

Back in 2008 when I was looking at gap-based trading models, testing day-of-the-week filters was common practice. I remember it was often demonstrated that particular days of the week should be avoided as they continually produced negative results. Let’s see how that looks today with this model.

In this bar graph the x-axis represents the day of the week and the y-axis is the net profit accumulated for taking all trades during that particular day of the week. The first bar is Monday (1), and the last bar (5) is Friday. We can see that Monday and Friday have not produced very good results overall. Not taking gap trade on these days may be a good idea.

The code for this strategy is at the bottom of this article.

Testing Gap Size vs. Profitability

I distinctly remember that the size of a gap also played a roll in determining if a particular trade would be ignored or not. I don’t recall completely, but I think too large of gaps or too small of gaps were avoided. Let’s see what we have going for us today.

I’ve modified the code to take two inputs:

  1. Gap Increments
  2. Gap Iterations

Gap Increments tells the software the size range of gaps that we will be trading. For example, a gap increment of 5 states we are testing gaps that fall within a 5-point range.

Iterations tell the software how many different scenarios we are testing. It is this input value where we use TradeStation’s optimization feature to perform iterations over the trading model while testing different gaps sizes. Based on how the software works, it’s important to start this input value from zero. For example, if we want to perform 6 iterations we would enter zero here and then use the optimizer to test from 0-5. That means we will be performing 6 tests with a gap increment of five. This would generate the following tests:

Iteration

Gap Tested

0

0-5 pts

1

5-10 pts

2

10-15 pts

3

15-20 pts

4

20-25 pts

5

25-30 pts

So in the above example we would have 6 different tests. The first test would only trade gaps greater than 0 and less than or equal to 5 points. The second test would only trade gaps greater than 5 and less than or equal to 10 points. And so on…

Here are the results when I tested the trading model with a gap increment of 1 with 25 iterations.

Looking at this bar graph we can see gaps sizes, at bar #8 is the last bar to produce profits. Bars to the right of #8 produce no profits. Bar #8 represents gaps less than or equal to 9 points and greater than 8 points. In the end it looks like we can improve the system by only taking gaps that are equal to or less than 9 points.

The code for this strategy is at the bottom of this article.

Gap Fade #1 Model With Day-of-Week Filter

Let’s now take what we learned and apply it to our baseline system. First, we apply the day-of-the-week filter (DOW) to our baseline system.

Gap Fade #1 Day-of-Week Filter

Baseline

DOW Filter

Net Profit

$24,118

$27,103

Profit Factor

1.2

1.39

Total Trades

1,118

743

% Winners

72%

75%

Avg.Trade Net Profit

$20.42

$36.48

Annual Rate of Return

1.44%

1.60%

Max Drawdown (intraday)

5.2%

2.87%

Gap Fade #1 Model With Gap Size Filter

Here we apply the gap size filter to our baseline system.

Gap Fade #1 Gap Size Filter

Baseline

Size Filter

Net Profit

$24,118

$28,863

Profit Factor

1.2

1.27

Total Trades

1,118

1,095

% Winners

72%

73%

Avg.Trade Net Profit

$20.42

$26.36

Annual Rate of Return

1.44%

1.69%

Max Drawdown (intraday)

5.2%

4.34%

Gap Fade #1 Model Combining Both Filters

In this test I combined the day-of-week filter with the gap size filter.

Gap Fade #1 Combined Filters

Baseline

Combined

Net Profit

$24,118

$27,138

Profit Factor

1.2

1.43

Total Trades

1,118

690

% Winners

72%

75%

Avg.Trade Net Profit

$20.42

$39.33

Annual Rate of Return

1.44%

1.60%

Max Drawdown (intraday)

5.2%

2.52%

Conclusion

At this point I like the day-of-week filter better than the gap size filter. I like the fact that the net profit per trade and profit factor is larger than the gap size filter. Furthermore, we already have a gap size filter in place with our range check. Thus, I really don’t feel too comfortable adding an additional check on the gap size.

After coming up with these two filters and testing them on our in-sample data, we can now apply them to our out-of-sample data. For now however, I'll be doing this next time as this article is getting a bit long. Once we test our idea on the out-of-sample data we’ll see if our efforts paid off or if it’s back to the baseline system to try new ideas.

Other Article In This Series

]]>
https://easylanguagemastery.com/strategies/improve-simple-gap-strategy/feed/ 38