Hi QuantConnect Community,
I am designing an intraday algorithm to trade the E-mini S&P 500 futures contract based on signals derived from the VIX index and a simple moving average (SMA) of the E-mini S&P 500's price. Here's a brief overview of my strategy:
- Calculation of Expected Move:
- I use the prior day's close of the VIX index to calculate the daily expected move of the E-mini S&P 500 futures contract.
- Creation of Bands:
- I create upper and lower bands for the current trading day using the prior day's closing price of the VIX and the prior day's close of the E-mini S&P 500 futures.
- Trade Signals:
- A trade signal is generated when the current price on the 5-minute time frame closes above the 20-period SMA within the lower band.
However, I am encountering a runtime error: 'NoneType' object has no attribute 'Close'.
Could anyone help me identify and fix the issue causing this runtime error? I'm new to QuantConnect and any guidance would be greatly appreciated!
Thank you in advance!
Mia Alissi
Hi Elliot,
The error message
'NoneType' object has no attribute 'Close'typically occurs when you're trying to access theCloseattribute of aNoneobject. This can happen if the data for a particular symbol at a specific time slice is not available, and you're trying to access theCloseattribute of this non-existent data.In your case, it's likely that you're trying to access the
Closeprice of the E-mini S&P 500 futures contract or the VIX index at a time when the data isn't available.To fix this issue, you should check if the data for the symbol exists in the current time slice before trying to access its
Closeattribute. You can do this by using theContainsKeymethod of theSliceobject. Here's an example:In this code,
symbolis the symbol of the asset you're interested in (in your case, the E-mini S&P 500 futures contract or the VIX index). TheContainsKeymethod checks if the data for this symbol exists in the current time slice. If it does, the code then checks if theCloseattribute of this data is notNonebefore trying to access it.If you're dealing with TradeBars (which is likely the case if you're working with futures), you might need to use
self.CurrentSlice.Bars.ContainsKey(symbol)instead ofself.CurrentSlice.ContainsKey(symbol).Please refer to the QuantConnect forum discussion for more details on this issue.
I hope this helps! Let me know if you have any other questions.
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.
Elliot Marshall
Elliot Marshall
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!