我已经看过其他的帖子了,但是我不能基于此来解决这个问题。
DataConsolidationAlgorithm类(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(2017, 1, 1) #Set Start Date
self.SetEndDate(2020, 1, 1) #Set End Date
self.SetCash(100000) #Set Strategy Cash
self.SetBrokerageModel(BrokerageName.FxcmBrokerage)
symbols = [self.AddForex(ticker, Resolution.Minute).Symbol
for ticker in ["EURUSD"]]
self.SetBenchmark('SPY')
self.slow = self.EMA("EURUSD", 200, Resolution.Daily)
self.SetWarmUp(200)
def OnData(self, data):
# Simple buy and hold template
self.low = self.MIN("EURUSD", 7, Resolution.Daily, Field.Low)
self.high = self.MAX("EURUSD", 7, Resolution.Daily, Field.High)
#fxQuoteBars = data.QuoteBars
#QuoteBar = fxQuoteBars['EURUSD'].Close
#self.QuoteBar = self.History("EURUSD", TimeSpan.FromDays(1), Resolution.Daily)
self.quoteBar = data['EURUSD'] ## EURUSD QuoteBar
#self.Log(f"Mid-point open price: {quoteBar.Open}")
self.closeBar = (self.quoteBar.Close) ## EURUSD Bid Bar
self.history7days = self.History(["EURUSD"], 7, Resolution.Daily)
if self.closeBar <= self.low and self.Forex["EURUSD"].Price > self.slow.Current.Value:
self.SetHoldings("EURUSD", 1.0)
if self.closeBar > self.high:
self.SetHolding("EURUSD", 0.0)运行时错误: TypeError :无法在main.py:line 50中的OnData获取托管对象::if self.closeBar <= self.low和self.Forex"EURUSD".Price > self.slow.Current.Value: TypeError :无法获取托管对象
发布于 2021-06-09 22:30:33
我遇到了一个类似的错误,并通过确保我试图在if语句中与<、>、=等进行比较的数据类型属于同一类型来解决它。
在OnData中将您要比较的指标重新定义为本地指标,如下所示,您的所有指标都将是相同的数据类型:
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(2017, 1, 1) #Set Start Date
self.SetEndDate(2020, 1, 1) #Set End Date
self.SetCash(100000) #Set Strategy Cash
self.SetBrokerageModel(BrokerageName.FxcmBrokerage)
symbols = [self.AddForex(ticker, Resolution.Minute).Symbol
for ticker in ["EURUSD"]]
self.SetBenchmark('SPY')
self.slow = self.EMA("EURUSD", 200, Resolution.Daily)
self.SetWarmUp(200)
# Simple buy and hold template
self.low = self.MIN("EURUSD", 7, Resolution.Daily, Field.Low)
self.high = self.MAX("EURUSD", 7, Resolution.Daily, Field.High)
#fxQuoteBars = data.QuoteBars
#QuoteBar = fxQuoteBars['EURUSD'].Close
#self.QuoteBar = self.History("EURUSD", TimeSpan.FromDays(1), Resolution.Daily)
self.quoteBar = data['EURUSD'] ## EURUSD QuoteBar
#self.Log(f"Mid-point open price: {quoteBar.Open}")
self.closeBar = (self.quoteBar.Close) ## EURUSD Bid Bar
self.history7days = self.History(["EURUSD"], 7, Resolution.Daily)def OnData(自身,数据):
closebar = self.closeBar.Current.Value
low = self.low.Current.Value
price = self.Forex["EURUSD"].Price
slow = self.slow.Current.Value
high = self.high.Current.Value
if closeBar <= low and price > slow :
self.SetHoldings("EURUSD", 1.0)
if closeBar > high:
self.SetHolding("EURUSD", 0.0)https://stackoverflow.com/questions/66187308
复制相似问题