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.


  • Topics

  • Posts

    • Date: 31st March 2025.   Trump Confirms Tariffs on All Countries, Sending Stocks Lower.   The NASDAQ continues to trade lower due to the US confirming the latest tariffs will be on all countries. In addition to this, bearish volatility also is largely due to the higher inflation data from Friday. The NASDAQ declines to its lowest price since September 11th 2024. Core PCE Price Index - Inflation Increases Again! The PCE Price Index read 2.5% aligning with expert forecasts not triggering any alarm bells. However, the Core PCE Price Index rose from 0.3% to 0.4% MoM and from 2.7% to 2.8% YoY, signalling growing inflationary pressure. This increases the likelihood that the Federal Reserve will maintain elevated interest rates for an extended period. The NASDAQ fell 2.60% due to the higher inflation reading which is known to pressure the stock market due to pressure on consumer demand and a more hawkish Federal Reserve. Boston Fed President Susan Collins recently commented that tariffs could drive up inflation, though the long-term impact remains uncertain. She told journalists that a short-term spike is the most probable outcome but believes the current pause in monetary policy adjustments is appropriate given the prevailing uncertainties. Although, certain investment banks such as JP Morgan actually believe the Federal Reserve will be forced into cutting rates. This is due to expectations that the economy will struggle under the new trade policy. For example, JP Morgan expects the Federal Reserve to delay rate cuts but will quickly cut towards the end of 2025. Market Risk Appetite Takes a Hit! A big factor for the day is the drop in the risk appetite of investors. This can be seen from the VIX which is up almost 6%, Gold which is trading 1.30% higher and the Japanese Yen which is the day’s best performing currency. Most safe haven assets, bar the US Dollar, increase in value. It is also worth noting that all indices are decreasing in value during this morning's Asian session with the Nikkei225 and NASDAQ witnessing the strongest decline. Previously the stock market rose in value as investors heard rumours that tariffs would only be on certain countries. This bullish swing occurred between March 14th and 25th. Over the weekend, President Donald Trump indicated that the upcoming tariffs would apply to all countries, not just those with the largest trade imbalances with the US. NASDAQ - Technical Analysis In terms of technical analysis, the NASDAQ continues to obtain indications that sellers control the price action. The price opens on a bearish price gap measuring 0.30% and trades below all Moving Averages on all timeframes. The NASDAQ also trades below the VWAP and almost 100% of the most influential components (stocks) are declining in value.     The next significant support level is at $18,313, and the resistance level stands at $20,367.95. Key Takeaway Points: NASDAQ falls to its lowest since September 2024 as the US confirms tariffs on all countries, adding to inflation concerns. Core PCE inflation rises to 0.4% MoM and 2.8% YoY, increasing the likelihood of prolonged high interest rates. Investor risk appetite drops as VIX jumps 6%, gold gains 1.3%, and safe-haven assets outperform. NASDAQ shows strong bearish momentum, trading below key technical levels with support at $18,313 and resistance at $20,367.95. Always trade with strict risk management. Your capital is the single most important aspect of your trading business.   Please note that times displayed based on local time zone and are from time of writing this report.   Click HERE to access the full HFM Economic calendar.   Want to learn to trade and analyse the markets? Join our webinars and get analysis and trading ideas combined with better understanding of how markets work. Click HERE to register for FREE!   Click HERE to READ more Market news.   Michalis Efthymiou HFMarkets   Disclaimer: This material is provided as a general marketing communication for information purposes only and does not constitute an independent investment research. Nothing in this communication contains, or should be considered as containing, an investment advice or an investment recommendation or a solicitation for the purpose of buying or selling of any financial instrument. All information provided is gathered from reputable sources and any information containing an indication of past performance is not a guarantee or reliable indicator of future performance. Users acknowledge that any investment in Leveraged Products is characterized by a certain degree of uncertainty and that any investment of this nature involves a high level of risk for which the users are solely responsible and liable. We assume no liability for any loss arising from any investment made based on the information provided in this communication. This communication must not be reproduced or further distributed without our prior written permission.
    • PM Philip Morris stock, top of range breakout at https://stockconsultant.com/?PM
    • EXC Exelon stock, nice range breakout at https://stockconsultant.com/?EXC
    • UTZ Utz Brands stock, watch for a bottom breakout at https://stockconsultant.com/?UTZ
    • FL Foot Locker stock, nice breakdown follow through at https://stockconsultant.com/?FL
×
×
  • Create New...

Important Information

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