2

I have seen other threads but couldnt figure it out based on that.

class 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)

Runtime Error: TypeError : Cannot get managed object at OnData in main.py:line 50 :: if self.closeBar <= self.low and self.Forex["EURUSD"].Price > self.slow.Current.Value: TypeError : Cannot get managed object

orad
  • 15,272
  • 23
  • 77
  • 113
GREGOOR
  • 21
  • 1

1 Answers1

1

I was running into a similar error and solved it by making sure that the types of data I was trying to compare in the if statement with <, >, = etc were of the same type.

Redefine the indicators you want to compare as local indicators in OnData like below and all your indicators will be the same data type:

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(self, data):

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)
tomes
  • 11
  • 2