Jump to content

Welcome to the new Traders Laboratory! Please bear with us as we finish the migration over the next few days. If you find any issues, want to leave feedback, get in touch with us, or offer suggestions please post to the Support forum here.

  • Welcome Guests

    Welcome. You are currently viewing the forum as a guest which does not give you access to all the great features at Traders Laboratory such as interacting with members, access to all forums, downloading attachments, and eligibility to win free giveaways. Registration is fast, simple and absolutely free. Create a FREE Traders Laboratory account here.

brownsfan019

Building a GAP Trading Strategy

Recommended Posts

I wrote some code awhile back for TradeStation as a starting point to a gap strategy, I'll post it here. If you run backtesting on it you'll soon realize that it doesn't make sense to risk real money trading it. However -- I haven't given up on it yet. I'm thinking about ways to filter out the entries so that you enter the trade under ideal conditions.

 

Those conditions could include using some type of trend determination filter such as Heikin Ashi, Momentum, Buying/Selling pressure etc.

 

If / when I come up with a decent solution I'll be happy to post the conclusion. In the meantime, feel free to play with the code if it helps.

 

DaveDM

 

----- Place the following in two separate Strategy documents in EasyLanguage, one for Gap Up and one for Gap Down...

 

 

// Gap Up Strategy

 

inputs:

Percent_Fill(.75), // 1 = 100%

Min_Gap_Size_Points(20), // 1 = 1 YM point

Max_Gap_Size_Points(101), // 1 = 1 YM point

Total_Contracts(1),

Take_Position_Start(935),

Exit_Positions_Time(1550),

Risk_Reward_Ratio(1.00);

 

variables:

 

mp(0),

Trade_Count(0),

Min_Gap_Per_Short(0),

Max_Gap_Per_Short(0),

Min_Short_Entry(0),

Max_Short_Entry(0),

Target_Short(0),

P_Close(0),

P_Open(0),

Gap_Size(0),

Stop_Price(0);

 

mp = marketposition;

 

 

// Gap Open, Direction Short

 

If time = Take_Position_Start then begin

if Trade_Count < 1 then begin

P_Close = CloseD(1);

// find bar number to reference for opening price of today

Value1 = FindBar(Date, Take_Position_Start);

P_Open = Open[Value1]; // Open price after Take_Position_Start time

Min_Short_Entry = P_Close + Min_Gap_Size_Points;

Max_Short_Entry = P_Close + Max_Gap_Size_Points;

Target_Short = P_Open - ((P_Open - P_Close) * Percent_Fill);

Stop_Price = P_Open + ((P_Open - P_Close) * Risk_Reward_Ratio);

 

if P_Open > P_Close then begin // Close[2]

if P_Open >= Min_Short_Entry then begin

if P_Open <= Max_Short_Entry then begin

sellshort ("SHORT") Total_Contracts contracts this bar;

Trade_Count = 1;

end;

end;

end;

end;

end;

 

// Short Exit

if mp = -1 then begin

if low <= Target_Short then begin // low

buytocover ("Target_Short_GU") next bar at market; // * or use limit order

// resets

Trade_Count = 0;

P_Open = 0;

P_Close = 0;

Min_Gap_Per_Short = 0;

Min_Short_Entry = 0;

Target_Short = 0;

mp = 0;

Value1 = 0;

Value2 = 0;

Value3 = 0;

Max_Gap_Per_Short = 0;

Max_Short_Entry = 0;

Target_Short = 0;

Stop_Price = 0;

end;

end;

 

// Stop Loss

if mp = -1 then begin

if high >= Stop_Price then begin

buytocover ("Stop_Loss_Ouch!_GU") next bar Stop_Price stop;

// resets

Trade_Count = 0;

P_Open = 0;

P_Close = 0;

Min_Gap_Per_Short = 0;

Min_Short_Entry = 0;

Target_Short = 0;

mp = 0;

Value1 = 0;

Value2 = 0;

Value3 = 0;

Max_Gap_Per_Short = 0;

Max_Short_Entry = 0;

Target_Short = 0;

Stop_Price = 0;

end;

end;

 

// Timed Exit since IntraDay trade only, exit all trades before market close

if mp = -1 and time >= Exit_Positions_Time then begin;

buytocover ("CLOSE_TIME") this bar;

// resets

Trade_Count = 0;

P_Open = 0;

P_Close = 0;

Min_Gap_Per_Short = 0;

Min_Short_Entry = 0;

Target_Short = 0;

mp = 0;

Value1 = 0;

Value2 = 0;

Value3 = 0;

Max_Gap_Per_Short = 0;

Max_Short_Entry = 0;

Target_Short = 0;

Stop_Price = 0;

end;

 

---- ^ that was the end of the gap up strategy. Place the following in a separate EasyLanguage strategy file for Gap Down.

 

 

// Gap Down Strategy

 

inputs:

Percent_Fill(.75), // 1 = 100%

Min_Gap_Size_Points(20), // 1 = 1 YM point

Max_Gap_Size_Points(101), // 1 = 1 YM point

Total_Contracts(1),

Take_Position_Start(935),

Exit_Positions_Time(1550),

Risk_Reward_Ratio(1.00);

 

variables:

 

mp(0),

Trade_Count(0),

Min_Gap_Per_Long(0),

Max_Gap_Per_Long(0),

Min_Long_Entry(0),

Max_Long_Entry(0),

Target_Long(0),

P_Close(0),

P_Open(0),

Gap_Size(0),

Stop_Price(0);

 

mp = marketposition;

 

 

// Gap Down, Direction Long

 

If time = Take_Position_Start then begin

if Trade_Count < 1 then begin

P_Close = CloseD(1);

// find bar number to reference for opening price of today

Value1 = FindBar(Date, Take_Position_Start);

P_Open = Open[Value1]; // Open price after Take_Position_Start time

Min_Long_Entry = P_Close - Min_Gap_Size_Points;

Max_Long_Entry = P_Close - Max_Gap_Size_Points;

Target_Long = P_Open + ((P_Close - P_Open) * Percent_Fill);

Stop_Price = P_Open - ((P_Close - P_Open) * Risk_Reward_Ratio);

 

if P_Open < P_Close then begin

if P_Open <= Min_Long_Entry then begin

if P_Open >= Max_Long_Entry then begin

buy ("LONG_ON_GD") Total_Contracts contracts this bar;

Trade_Count = 1;

end;

end;

end;

end;

end;

 

// Long Exit

if mp = 1 then begin

if high >= Target_Long then begin // high

sell ("Target_Long_GD") next bar at market; // * or use limit order

// resets

Trade_Count = 0;

P_Open = 0;

P_Close = 0;

Min_Gap_Per_Long = 0;

Min_Long_Entry = 0;

Target_Long = 0;

mp = 0;

Value1 = 0;

Value2 = 0;

Value3 = 0;

Max_Gap_Per_Long = 0;

Max_Long_Entry = 0;

Target_Long = 0;

Stop_Price = 0;

end;

end;

 

// Stop Loss

if mp = 1 then begin

if low <= Stop_Price then begin

sell ("Stop_Loss_Ouch!_GD") next bar Stop_Price stop;

// resets

Trade_Count = 0;

P_Open = 0;

P_Close = 0;

Min_Gap_Per_Long = 0;

Min_Long_Entry = 0;

Target_Long = 0;

mp = 0;

Value1 = 0;

Value2 = 0;

Value3 = 0;

Max_Gap_Per_Long = 0;

Max_Long_Entry = 0;

Target_Long = 0;

Stop_Price = 0;

end;

end;

 

// Timed Exit since IntraDay trade only, exit all trades before market close

if mp = 1 and time >= Exit_Positions_Time then begin;

sell ("CLOSE_TIME_GAP_DOWN") this bar;

// resets

Trade_Count = 0;

P_Open = 0;

P_Close = 0;

Min_Gap_Per_Long = 0;

Min_Long_Entry = 0;

Target_Long = 0;

mp = 0;

Value1 = 0;

Value2 = 0;

Value3 = 0;

Max_Gap_Per_Long = 0;

Max_Long_Entry = 0;

Target_Long = 0;

Stop_Price = 0;

end;

Share this post


Link to post
Share on other sites

We have done extensive gap trading testing over the SPI200 index futures. Please feel free to contact me for a copy of the test results.

 

regards

kevin

Edited by Soultrader
email postings not allowed

Share this post


Link to post
Share on other sites
We have done extensive gap trading testing over the SPI200 index futures. Please feel free to contact me for a copy of the test results.

 

regards

kevin

 

Go ahead and post here Kevin - you can upload a wide variety of attachments to the forum. No need for personal emails to be sent.

 

thanks

Share this post


Link to post
Share on other sites
Check out masterthegap.com

 

I subscribed to Scott Andrews' service for a couple of months. He uses statistical data to trade the opening gap everyday in the eminis.....plus pivot points etc. He does a pretty good job of it. I stopped subscribing because I wasn't trading futures at the time....now I am...so I'll probably subscribe again.

He put out a book called "Understanding Gaps" which is useful ;)

 

FWIW, I just got an email advertising a free webinar he is doing tomorrow.

 

Webcasts Details

 

I know nothing about him or his services, just passing on the info.

Share this post


Link to post
Share on other sites

I just started subscribing to the auto-trading program here thegapfill.com. He has back-tested results posted, and daily video of trades for the last month or so. Just started with it, so we will see how it goes.

Share this post


Link to post
Share on other sites
I found this somewhere, and thought it could be useful. It states the half gap fill is 80% winner. Of course you will still need correct money management (i.e. position size, stop loss) to make it profitable.

If anyone's going to take a statistical approach to this, make sure you use ample data. The xls attached on the quoted post uses a fairly small sample size. You may come to incorrect or statistically insignificant conclusions with not enough data. Also, the stats analyzed on the xls deal with specific day biases, which from my testing, are not as reliable or exploitable than biases rooted in market conditions (such as technical analysis, etc). It's a good start, but don't fool yourself with faulty statistics.

Share this post


Link to post
Share on other sites
If anyone's going to take a statistical approach to this, make sure you use ample data. The xls attached on the quoted post uses a fairly small sample size. You may come to incorrect or statistically insignificant conclusions with not enough data. Also, the stats analyzed on the xls deal with specific day biases, which from my testing, are not as reliable or exploitable than biases rooted in market conditions (such as technical analysis, etc). It's a good start, but don't fool yourself with faulty statistics.

 

I totally agree with what you are saying. I didn't put together the data, it could be totally bogus. I'm just wondering how you were able to determine the sample size? I also agree with you that technical analysis should be more valuable than specific day biases, though the fact that Monday has the lowest probability for a gap fill makes logical sense to me, and I think is valuable to know, and should be included in the overall analysis of the trade. The "special days" again should be included as statistically they do appear to have an effect.

Share this post


Link to post
Share on other sites

You want a few hundred gaps to look at, minimally. Basically, you're looking for biases (which should make sense), not find statistical flukes. Example, in the attached spreadsheet, 4pt gaps filled 86% of the time, 6pt gaps filled 77% of the time, but 5pt gaps only filled 60% of the time. That makes no logical sense, so I'd question the sample size just based on that.

Share this post


Link to post
Share on other sites

Mind you going back too far can be a two edged sword as market characteristics change over time. for example a market that trades in a 30 point range with 6 point gaps might be quite different to when it traded in a 12 point range with 4 point gaps. You need to also save enough data for walk forward testing. Oh and you need to ensure you have bull and bear and sideways data.

 

Has anyone considered combining gaps and an opening range break out type setup to determine if it is a gap and go or gap and close?

Share this post


Link to post
Share on other sites

The only gap fill strategy that has worked for me is to trade the ones that occur in the overnight session. Remember, the ES is a 24 hour market. It's not uncommon for gaps to occur between the close of the cash market to the next day's opening, but an examination of the overnight action may show no gap at all.

 

Overnight gaps may be few and far between, but the probability of filling is over 80%.

 

Also, there has to be some air between the gap and current price--I look for at least 5 points.

Share this post


Link to post
Share on other sites

Since I have been watching ES gaps (since I first stumbled on this thread) and I cut out off hours, the only consistent gap trade from my point of view is to trade candlestick patterns. This can still be very risky due to the RTH open madness. However I see no other way to trade this than using candlestick patterns. Just my observation. FWIW

Share this post


Link to post
Share on other sites
Since I have been watching ES gaps (since I first stumbled on this thread) and I cut out off hours, the only consistent gap trade from my point of view is to trade candlestick patterns. This can still be very risky due to the RTH open madness. However I see no other way to trade this than using candlestick patterns. Just my observation. FWIW

 

BR - that's basically what I've seen as well. I'm sure if we spent hours on it, there's so many other options but just glancing it would seem put up a 5 min (or longer chart) and buy the first hammer you see when it gaps down and vice versa. Some days, that's all it takes and 1 easy trade. Other days it's a matter of how many times you want to fire a bullet. My reco is 2-3 shots and then shut 'er down.

Share this post


Link to post
Share on other sites

ZOSO,

 

I don't like at overnight sessions that often, could you post a screenshot of an overnight gap if possible? Also what is the frequency of these gaps?

 

Thanks!

 

The only gap fill strategy that has worked for me is to trade the ones that occur in the overnight session. Remember, the ES is a 24 hour market. It's not uncommon for gaps to occur between the close of the cash market to the next day's opening, but an examination of the overnight action may show no gap at all.

 

Overnight gaps may be few and far between, but the probability of filling is over 80%.

 

Also, there has to be some air between the gap and current price--I look for at least 5 points.

Share this post


Link to post
Share on other sites

Dear Brownsfan,

 

I trade GAPs and found similar conclusions to your post UNTIL I found a website with probabilities for each gap and gap area in relation to the high close open and low of the previous day This gut ONLY trade gaps with an amazing Equity curve. Check it out at masterthegap.com

 

Regards

JM

Share this post


Link to post
Share on other sites
I have a decent amount of experience here, so will share some if anyone wants to look into this. I have an automatic strategy that trades gaps on ES that has a fairly impressive track record. This isn't my primary method of trading, but was one of my first statistical looks at markets, and has helped smooth out the P/L curve. It trades using statistical biases I've found, and only actually attempts roughly 20-25% of the time (but it's actually highly accurate, and has a good r:r). In turn, many of the "gap and go" days are filtered out.

 

For those who are statistically inclined, here are some things to look into regarding statistical biases for gaps. Remember, if the gap filled or not is only one side of the coin. Also look at the bias in context of the gap size and risk.

  • Is the general market trending or congesting?
  • How big is the gap? (I have filters for gaps that are too big, and too small)
  • How does gap size compare to ATR? (same)
  • Have the previous x gaps filled? (look at both the direction of the gap, and against)
  • How does gap direction compare to the trend direction? (look at a few timeframes)
  • Where is the gap positioned compared to the previous day's value area? (ie, is there liquidity close by?)
  • Where is the gap located compared to yesterday's High and Low? (inside/outside)
  • What day of the week is it? (yes, there's a bias)
  • How volatile has the market been?
  • Is the gap near S/R? (this is one of the hardest to automate, so sometimes you end up cutting corners)

 

This list is by no means complete, and I'd encourage someone who wants to delve into this look into these suggestions along with any other ideas they may have. I simply got a decent amount of historical data (think a couple years), and did some testing for each of my potential biases in Mathematica (Excel also works well for this) with a portion of the data. Once I had a good idea of a potential bias, I tested it on out of sample data.

 

When combined, these biases give you a much better idea of the statistical edge you may have by trading any given gap. I programmed the strategy to enter anywhere from 9:00 to 9:45 on a technical trigger (for brownsfan's case, he looked at hammers; you may prefer some type of indicator or other method). Exits are enabled within a certain % of the gap fill, and exit on a similar technical trigger (so they may go past the gap).

 

Hope this gives budding statisticians some ideas. In addition to biases, stop strategy is very important (and could be a bias in itself.. if price goes x% against, what's the chance it'll go back and fill?). Something mine does not do is the "bullets" approach, and there could be some validity in that.

 

Hope I didn't barge in on your candlestick discussion, browns :)

 

Dear Browns

 

You said : "but was one of my first statistical looks at markets"

 

I am very interested in this strategy, but organizing the data and KNOWING where and what to look for is very unclear, Can you point me in the right direction to learn how to get useful data ?

 

I really will appreciated it !

 

Regards

 

Jaime

Share this post


Link to post
Share on other sites

I was reading through this thread. Motivation was this website publishing unique strategy to trade gaps, their strategy is not exactly gap as they call it open out of previous days range. Just bumping an old thread but I think anyone interested in gap trading may find the setups useful

Edited by edakad

Share this post


Link to post
Share on other sites

Firstly we need to know what is a gap trading strategy.Basically gap trading is a simple and disciplined approach to buying and shorting stocks. Essentially one finds stocks that have a price gap from the previous close and watches the first hour of trading to identify the trading range. Rising above that range signals a buy, and falling below it signals a short.

 

A gap is a change in price levels between the close and open of two consecutive days. Although most technical analysis manuals define the four types of gap patterns as Common, Breakaway, Continuation and Exhaustion, those labels are applied after the chart pattern is established. That is, the difference between any one type of gap from another is only distinguishable after the stock continues up or down in some fashion. Although those classifications are useful for a longer-term understanding of how a particular stock or sector reacts, they offer little guidance for trading.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.