Apologies if this is a basic concepts question I am reasonably new to this,, but I am trying to take one the quantapedia base strategy which is buy at close and sell at open and tweak it to only fire if some conditions are made. This is part as it's an easy one to start with to learn how to get data features into OnData to be used as filters.
Where I am struggling, is onData how I can pull in the previous Close, High, Low as the following error message pops up during running the backtest:
Runtime Error: AttributeError : 'NoneType' object has no attribute 'Close'
at OnData
prevcloseprice = data[self.spy].Close
===
at Python.Runtime.PyObject.Invoke(PyTuple args in main.py: line 30
Also I would like to retrieve the price of SPY at last bar (hourly) before the close, and do some comparison logic on it, and say if price < high of previous day for instance, buy at close if not skip this day. So it would be great to understand how to get the data related to the last bar before close data points for a given security, so they can be used in if statements.
Thanks
Mark Hodson
Code with backtest (with commented out lines that cause errors)
Vladimir
Mark Hodson
The “Bar Open-Close strategy” can help solve the problem.
If you are satisfied with my answer, please accept it and don't forget to like it
Mark Hodson
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!