New to Algo Trading and got this error when trying to back test...
BacktestingRealTimeHandler.Run(): There was an error in a scheduled event BTCUSD: EveryDay: BTCUSD: 1 min before MarketClose. The error was TypeError : unindexable object
QUANTCONNECT COMMUNITY
New to Algo Trading and got this error when trying to back test...
BacktestingRealTimeHandler.Run(): There was an error in a scheduled event BTCUSD: EveryDay: BTCUSD: 1 min before MarketClose. The error was TypeError : unindexable object
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.
Liam Maurer
from datetime import datetime import decimal import numpy as np from clr import AddReference AddReference("System") AddReference("QuantConnect.Algorithm") AddReference("QuantConnect.Common") from System import * from QuantConnect import * from QuantConnect.Algorithm import * from QuantConnect.Brokerages import * from QuantConnect.Orders import * class DynamicBreakoutAlgorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2019,1,1) self.SetEndDate(2019,5,9) self.SetCash(100000) self.SetCash("EUR", 10000) self.SetCash("BTC", 1) self.SetBrokerageModel(BrokerageName.GDAX, AccountType.Cash) self.AddCrypto("BTCUSD", Resolution.Daily) self.syl = "BTCUSD" self.Securities["BTCUSD"].SetDataNormalizationMode(DataNormalizationMode.Raw); self.Schedule.On(self.DateRules.EveryDay(self.syl), self.TimeRules.BeforeMarketClose(self.syl,1),Action(self.SetSignal)) self.numdays = 20 self.ceiling,self.floor = 60,20 self.buypoint, self.sellpoint= None, None self.longLiqPoint, self.shortLiqPoint, self.yesterdayclose= None, None, None self.SetBenchmark(self.syl) self.Bolband = self.BB(self.syl, self.numdays, 2, MovingAverageType.Simple, Resolution.Daily) def SetSignal(self): close = self.History(self.syl, 31, Resolution.Daily)['close'] todayvol = np.std(close[1:31]) yesterdayvol = np.std(close[0:30]) deltavol = (todayvol - yesterdayvol) / todayvol self.numdays = int(round(self.numdays * (1 + deltavol))) if self.numdays > self.ceiling: self.numdays = self.ceiling elif self.numdays < self.floor: self.numdays = self.floor self.high = self.History(self.syl, self.numdays, Resolution.Daily)['high'] self.low = self.History(self.syl, self.numdays, Resolution.Daily)['low'] self.buypoint = max(self.high) self.sellpoint = min(self.low) historyclose = self.History(self.syl, self.numdays, Resolution.Daily)['close'] self.longLiqPoint = np.mean(historyclose) self.shortLiqPoint = np.mean(historyclose) self.yesterdayclose = historyclose.iloc[-1] # wait for our BollingerBand to fully initialize if not self.Bolband.IsReady: return holdings = self.Portfolio[self.syl].Quantity if self.yesterdayclose > self.Bolband.UpperBand.Current.Value and self.Portfolio[self.syl].Price >= self.buypoint: self.SetHoldings(self.syl, 1) elif self.yesterdayclose < self.Bolband.LowerBand.Current.Value and self.Portfolio[self.syl].Price <= self.sellpoint: self.SetHoldings(self.syl, -1) if holdings > 0 and self.Portfolio[self.syl].Price <= self.shortLiqPoint: self.Liquidate(self.syl) elif holdings < 0 and self.Portfolio[self.syl].Price >= self.shortLiqPoint: self.Liquidate(self.syl) self.Log(str(self.yesterdayclose)+(" # of days ")+(str(self.numdays))) def OnData(self,data): pass
Jack Simonson
Hi Liam,
Historical data requests require that you pass a Symbol object rather than a string to specify the security for which you are requesting data. History calls with work if you add/change these lines of code
## In initialize self.symbolForHistoryCall = self.AddCrypto("BTCUSD", Resolution.Daily).Symbol ## In scheduled event close = self.History(self.symbolForHistoryCall, 31, Resolution.Daily)['close'] self.high = self.History(self.symbolForHistoryCall, self.numdays, Resolution.Daily)['high'] self.low = self.History(self.symbolForHistoryCall, self.numdays, Resolution.Daily)['low']
Right now, our Crypto data has deprecated due to a vendor error, and we are working on getting it back up and running as quickly as possible. I had to modify the End Date of the algorithm to accommodate this, as a history call beyond 5/4/19 returns an empty data frame and will throw an error.
Liam Maurer
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!