Trying to do a rolling window to make an SMA of BTCUSD. I've already reviewed the Documentation and this specific line of code thats throwing the error is pulled right out of the documentation for how to add the quotebar in a rolling window in on Data.
I think I need to make the SMA of BTCUSD be on the close bar of the quote data? maybe thats the issue? However I keep getting the following error:
Runtime Error: Trying to dynamically access a method that does not exist throws a TypeError exception. To prevent the exception, ensure each parameter type matches those required by the 'QuantConnect.Data.Market.TradeBar'>) method. Please checkout the API documentation.
at OnData
self.window.Add(data["BTCUSD"])
===
at Python.Runtime.PyObject.Invoke (Python.Runtime.PyTuple args in main.py:line 58
TypeError : No method matches given arguments for Add: (<class 'QuantConnect.Data.Market.TradeBar'>) (Open Stacktrace)
This is my code:
class RollingWindowAlgorithm(QCAlgorithm):
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(2021,2,1) #Set Start Date
self.SetEndDate(2021,4,21) #Set End Date
self.SetCash(25000) #Set Strategy Cash
self.SetBrokerageModel(BrokerageName.GDAX, AccountType.Cash)
self.AddCrypto("BTCUSD", Resolution.Minute) # Subscribe to minutely QuoteBars in Initialize(self)
# Creates a Rolling Window indicator to keep the 2 QuoteBar
self.window = RollingWindow[QuoteBar](2) # For other security types, use QuoteBar
# Creates an indicator and adds to a rolling window when it is updated
self.SMA("BTCUSD", 50).Updated += self.SmaUpdated
self.smaWin = RollingWindow[IndicatorDataPoint](50)
self.SetBenchmark("BTCUSD")
self.SetWarmUp(50)
def SmaUpdated(self, sender, updated):
'''Adds updated values to rolling window'''
self.smaWin.Add(updated)
def OnData(self, data):
'''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.'''
# Add Quotebar in rollling window
if data.ContainsKey("BTCUSD"):
# Add EURUSD QuoteBar in rolling window
self.window.Add(data["BTCUSD"])
# Wait for windows to be ready.
if not (self.window.IsReady and self.smaWin.IsReady): return
Derek Melchin
Hi David,
To resolve the issue, we should replace `data` with `data.QuoteBars`.
See the attached backtest for reference.
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.
David Eldringhoff
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!