KeyNotFoundException : 'GBPUSD' wasn't found in the Slice object, likely because there was no-data at this moment in time and it wasn't possible to fillforward historical data. Please check the data exists before accessing it with data.ContainsKey("GBPUSD"). I tried putting the containskey function in and adding data reference to the def Trade(self, data): but i get "requires 1 additional positional arguement data" error. Can someone please help? FOr some reason i can't add any of my run time error backtests from the last couple days so i attached this old backtest. A more recent Code snippet is below.
def Trade(self):
'''
Enter or exit positions based on relationship of the open price of the current bar and the prices defined by the machine learning model.
Liquidate if the open price is below the sell price and buy if the open price is above the buy price
'''
#for symbol in self.symbols:
#if self.CurrentSlice[symbol] is None: return
#if self.Securities.IsReady: return
for holding in self.Portfolio.Values:
if self.CurrentSlice is None: return
if self.CurrentSlice[holding.Symbol].Open < self.sell_prices[holding.Symbol] and not holding.Invested:
self.SetHoldings(holding.Symbol, 5 / len(self.symbols))
elif self.CurrentSlice[holding.Symbol].Open > self.buy_prices[holding.Symbol] and not holding.Invested:
self.SetHoldings(holding.Symbol, -5 / len(self.symbols))
elif holding.Invested:
if self.CurrentSlice[holding.Symbol].Open < self.sell_prices[holding.Symbol] and holding.IsShort:
self.Liquidate(holding.Symbol)
if self.CurrentSlice[holding.Symbol].Open > self.buy_prices[holding.Symbol] and holding.IsLong:
self.Liquidate(holding.Symbol)
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!