Hi guys,
I am trying to write an algorithm that buy BTCUSD on a series of offsets every year, using .date_rules.year_start(, but i get following errors:
- Runtime Error: 'NoneType' object is not callable
and
- Backtest Handled Error: BTCUSD: The security does not have an accurate price as it has not yet received a bar of data. Before placing a trade (or using SetHoldings) warm up your algorithm with SetWarmup, or use slice.Contains(symbol) to confirm the Slice object has price before using the data. Data does not necessarily all arrive at the same time so your algorithm should confirm the data is ready before using it. In live trading this can mean you do not have an active subscription to the asset class you're trying to trade. If using custom data make sure you've set the 'Value' property.
Where is the issue?
# region imports
from AlgorithmImports import *
# endregion
class HipsterFluorescentPinkGoshawk(QCAlgorithm):
def initialize(self):
self.set_start_date(2015, 1, 1)
self.set_cash(100000)
self.add_crypto("BTCUSD", Resolution.DAILY,Market.KRAKEN)
self.SetWarmUp(1)
self.long_day=[2,3,46,135,154,210,220]
self.short_day=[170,316]
for day in self.long_day:
self.schedule.on(
self.date_rules.year_start(day-1),
self.time_rules.at(15, 0, 0, TimeZones.UTC),
self._trade('BTCUSD',1)
)
for day in self.short_day:
self.schedule.on(
self.date_rules.year_start(day-1),
self.time_rules.at(15, 0, 0, TimeZones.UTC),
self._trade('BTCUSD',-1)
)
def on_data(self, data: Slice):
self.log(data.time)
#if self.portfolio.cash_book["BTC"].amount > 0:
#self.liquidate("BTCUSD")
#return
def _trade(self,symbol,position):
self.Symbol = symbol
self.Position = position
self.set_holdings(self.Symbol,self.Position)
Mia Alissi
Sources: Momentum Effect In Commodities Futures, Bybit Crypto Futures Regression Algorithm, Momentum Short Term Reversal Strategy, Extended Market Trading Regression Algorithm, Leveraged ETFs With Systematic Risk Management
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.
Julien
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!