Back

Playing The Gap

Hi guys,

I am trying to code an algo that would simply buy at open if a gap occurs and sell at the end of the day or if the gap has been filled.

My problem is to define the gap, how can I code this:
Gap_Down = Close[1] > Open[0] // The close of yesterday is greater that the open today.
Gap_Change = (Open[0]/Close[1] -1) // The difference in percentage.

Thank you in advance.
Chris
Update Backtest








Hey Chris!

I'v coded up a quick sample. What I've done is saved off the opening and closing prices and then performed the required equations. Something similar could be done for gap up as well. I think this is the simplest way to do this.

Let me know what you think!
1

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Hi Michael,

Thank you very much for your help.
I will try to add more options to it.

Chris
0

Hi All,
I am new to Quantconnect. How can I implement below strategy? I tried to modify the code here but failed.

1. If gap down 0.2%+ at open then short "SPY" at 9:40am and close any position at 15:45pm
2. If gap up 0.2%+ at open then buy"SPY" at 9:40am and close any position at 15:45pm

Thanks.

Ming
0

Hey there,

I don't now if this ist still relevant for you, but I think you could use the calculation methon of ChrisD to get the direction an size of the gap and then use scheduled events as described here (

https://www.quantconnect.com/docs#Scheduled-Events

) to trade at the specified times.

@ MichaelH Do you think the perfomance could be better if the difference of the high of the day befor to the low of the first bar of the current day (Gap Up) or vice versa would be included?

0

Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed