- You are here:
- Home »
- Blog »
- System Development
- » Gap Strategy Tool

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.

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.

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;

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.

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;

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.

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

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.

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.

Jeff is the founder of EasyLanguage Mastery - a website and mission to empowering the EasyLanguage trader with the proper knowledge and tools to become a profitable trader. Join our EasyLanguage FaceBook group to interact with other EasyLanguage traders! Click the FaceBook icon to join.

**Session expired**

Please log in again. The login page will open in a new tab. After logging in you can close it and return to this page.

I may be the only one, but I found the link cited to the Scott Andrews article to be busted.

I think this works. https://investiquant.com/cms/wp-content/uploads/0QXgiSAlUCjoYU6K3pvC/UnderstandingGaps-updated2.18.16.pdf

Thanks for the heads-up. I corrected the link.