I am trying to code an intraday strategy that buys on a gap from open to close. The strategy would, after the market opens, compare that day's opening price with yesterday's low. If today opens sufficiently below yesterday's low, then the strategy will buy the stock and then sell at the end of the day, on close. My question is, how do i identify yesterdays low and today's open (easy to do with Daily Bars, after each bar is complete) while using minute or tick data for the back test, since all holding periods are intraday? Is there a way to add a symbol with two different time resolutions so you can get high/low/close/open data for different time windows?
Jared Broad
private DateTime _date = new DateTime(); private decimal _low = Decimal.MaxValue; public void OnData(TradeBars data) { var barOpen = data["SPY"].Open; var barLow = data["SPY"].Low; if (Time.Date != _date.Date) { //Date changed, check for gap down from yesterday's *low*: if (barOpen < _low * 0.99m) { //Buy on gaps down. } //Reset variables to detect next morning. _low = barLow; _date = Time.Date; } if (barLow < _low) { //Build our lowest point. _low = data["SPY"].Low; } }
OR: You could create a custom consolidator which builds daily bars and use your existing daily bar logic. Check out the "How do I use Consolidators?" QC University algorithm.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.
Reuben
Jared Broad
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.
Reuben
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!