I simply cloned any strategy you have: “Clone of Moving Average”
# region imports
from AlgorithmImports import *
# endregion
class QuantLeague(QCAlgorithm):
def initialize(self):
self.set_start_date(2020, 1, 1)
self.set_cash(1000000)
self.symbol = self.add_equity("SPY", Resolution.Daily).Symbol
self.fast_moving_average = self.sma(self.symbol, 50, Resolution.Daily)
self.last_action = None
def on_data(self, data):
# Ensure we have enough data to calculate the moving average
if not self.fast_moving_average.is_ready:
return
price = data[self.symbol].Close
# Buy if the price is above the moving average
if price > self.fast_moving_average.current.value:
if not self.portfolio.invested or self.last_action == "Sell":
self.set_holdings(self.symbol, 1)
self.last_action = "Buy"
# Sell if the price is below the moving average
elif price < self.fast_moving_average.current.value:
if self.portfolio.invested and self.last_action == "Buy":
self.liquidate(self.symbol)
self.last_action = "Sell"
On cloud, when I run backtest, I get Always this error:
Runtime Error: 'NoneType' object has no attribute 'Close'
at on_data
price = data[self.symbol].Close
^^^^^^^^^^^^^^^^^^^^^^^
in main.py: line 17 (Open Stack Trace)
(Seems to be a data issue, but this is cloud, the data should be loaded without issue)
Whats heppening here ? This is critical issue
Can you resolve ?
Mia Alissi
Sources: Handling Data - QuantConnect.com, Debugging - QuantConnect.com, Gaussian Naive Bayes Model, Handling Data - QuantConnect.com, Brain ML Stock Ranking - QuantConnect.com
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.
Perfxtra
No, issue perisists !
Error Message:
Runtime Error: cannot access local variable 'price' where it is not associated with a value
at on_data
if price > self.fast_moving_average.current.value:
^^^^^
in main.py: line 23
Perfxtra
The graphs and blocked (Loading..)
Perfxtra
2) Now the graphs are bloked (see capture). Any help ?
Alexandre Catarino
Hi
The Eng Team has solved the “retrieving backtest chart”, and I can no longer reproduce it.
Please let us know if it persists on your end.
As for the NoneType question, please use
`slice[self.symbol]` is `None` (thus `NoneType`) because there is no market data (TradeBar or QuoteBar) in the Slice object.
Best regards,
Alex
Perfxtra
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!