Hello,
I am a complete noob here. I am trying to teach myself one step a time and a simple code like the one below is throwing errors because the BTCUSD does not exist. What am I doing wrong? Can anyone point me to a good working Crypto trading sample code, please?
I get errors with self.EMA but If I comment out the self.EMA, I get errors with the data.Bars and data.Ticks
It looks like that error message is telling me that the BTCUSD data does not exist but I don't know how to look into an error log, since the toast message is a very inefficient way to debug code.
def Initialize(self):
'''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''
self.SetStartDate(2020,11,15) #Set Start Date
self.SetEndDate(2020,11,28) #Set End Date
self.SetCash(1000) #Set Strategy Cash
self.SetBrokerageModel(BrokerageName.GDAX, AccountType.Cash)
# Find more symbols here: http://quantconnect.com/data
symbol = self.AddCrypto("BTCUSD", Resolution.Minute)
#self.AddCrypto("ETHUSD", Resolution.Minute)
#self.AddCrypto("BTCEUR", Resolution.Minute)
#symbol = self.AddCrypto("LTCUSD", Resolution.Minute).Symbol
# create two moving averages
self.fast = self.EMA(symbol, 30, Resolution.Minute)
self.slow = self.EMA(symbol, 60, Resolution.Minute)
def OnData(self, data):
# via a tradebar dictionary (symbol - bar)
data.Bars["BTCUSD"].Close
# or via a ticks list:
data.Ticks["BTCUSD"][0].Close
Adam W
# I don't think AddCrypto, AddEquity, etc returns Symbols iirc symbol = self.AddCrypto('BTCUSD', *args).Symbol self.fast = self.EMA(symbol, *args) or self.fast = self.EMA('BTCUSD', *args) def OnData(self, data): # Check if there is data if data.ContainsKey('BTCUSD'): self.Debug(data['BTCUSD'].Close)
Derek Melchin
Hi Gil,
See the attached backtest for a full example of Adam's solution above.
To access tick data in OnData, we need to request it when calling AddCrypto. For example,
self.AddCrypto("BTCUSD", Resolution.Tick)
Best,
Derek Melchin
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.
Gil Motta
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!