Hello everyone,
I am currently setting up my first algorithm on this platform and tried to backtest it. It looks good in the beginning. I can see the values changing, but then after a while I get this 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 Add method. Please checkout the API documentation.
"
at OnData in main.py:line 50
TypeError : No method matches given arguments for Add (Open Stacktrace)
The mentioned line 50, which is actually line 45 in my algo, looks like this:
self.tradeBarWindow.Add(data["BTCUSD"])
I honestly, do not see my mistake, could someone help me out?
Error Log: https://www.quantconnect.com/backtest/60871/2815074/4ead5896542dd044dd5fb4f783eda1bf-log.txt
Douglas Stridsberg
Hi, please could you attach the backtest or otherwise paste the code (using the Insert Code Snippet button on the same row as the bold and italics buttons)?
Your error could be caused by any number of things and it's impossible to tell without seeing the full code.
Pascal S
I deleted a few lines and added some new, but basically, the mistake is the same
class Trendchange(QCAlgorithm):
def Initialize(self):
self.length = 50
self.SetStartDate(2013, 12, 26) # Set Start Date
self.SetEndDate(2020, 12, 26) # Set Start Date
self.SetCash(10000) # Set Strategy Cash
self.SetWarmUp(self.length)
self.symbol = "EURUSD"
self.AddForex(self.symbol, Resolution.Hour)
#self.AddCrypto("BTCUSD", Resolution.Hour)
self.SetBrokerageModel(BrokerageName.Bitfinex, AccountType.Cash)
self.SetBenchmark(self.symbol)
self.longOnly = True
self.tradeBarWindow = RollingWindow[TradeBar](self.length) # Store the last 100 values
self.support = 0.0
self.resistance = 0.0
self.high = 0.0
self.low = 9999999999.9
self.newLL = False
self.newHH = False
def OnData(self, data):
'''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
Arguments:
data: Slice object keyed by symbol containing the stock data
'''
def findMax(self):
high = 0.0
i = self.length-1
while i > 0:
if self.tradeBarWindow[i].High > high:
high = self.tradeBarWindow[i].High
i -= 1
return high
def findMin(self):
low = 999999999.9
i = self.length-1
while i > 0:
if self.tradeBarWindow[i].Low < low:
low = self.tradeBarWindow[i].Low
i -= 1
return low
# Update our rolling windows
self.tradeBarWindow.Add(data[self.symbol])
if data[self.symbol].Close > data[self.symbol].Open:
self.high = data[self.symbol].High
elif data[self.symbol].Close < data[self.symbol].Open:
self.low = data[self.symbol].Low
# Wait for windows to be ready.
if not self.tradeBarWindow.IsReady: return
if self.IsWarmingUp: return
holdings = self.Portfolio[self.symbol].Quantity
currOpen = self.tradeBarWindow[0].Open
currHigh = self.tradeBarWindow[0].High
currLow = self.tradeBarWindow[0].Low
currClose = self.tradeBarWindow[0].Close
tp = 6
sl = 3
##### RUN SOME LOGIC HERE...
longCondition = False
shortCondition = False
if currLow < findMin(self):
self.resistance = self.high
self.newLL = True
if self.newLL:
if currClose > self.resistance:
longCondition = True
self.newLL = False
if currHigh > findMax(self):
self.support = self.low
self.newHH = True
if self.newHH:
if currClose < self.support:
shortCondition = True
self.newHH = False
##### END OF LOGIC
#### TRADE EXECUTION
if (holdings <= 0.0) and longCondition:
self.LimitOrder(self.symbol, 1.0, currClose)
self.LimitOrder(self.symbol, -1.0, currClose*(1+(tp/100)))
elif (holdings >= 0.0) and shortCondition:
self.LimitOrder(self.symbol, -1.0, currClose)
self.LimitOrder(self.symbol, 1.0, currClose*(1-(tp/100)))
Â
Â
Douglas Stridsberg
Thank you for attaching that. I don't immediately see what's wrong but I have two thoughts:
Pascal S
Thank you Douglas, I will do what you suggest.
Pascal S
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!