Hi all,
I'm attempting to compare a donchian channel breakout to the 100 day EMA. When adding this indicator in, my code breaks and I get Error: Cannot Get Managed Object. Does anyone know how to fix this issue? Blow is the changed code, with a previous backtest.
class Donchian6(AlphaModel):
def __init__(self, lowerBand = 55, upperBand = 55, emaPeriod = 100, resolution = Resolution.Daily):
self.lowerBand = lowerBand
self.upperBand = upperBand
self.resolution = resolution
self.emaPeriod = emaPeriod
self.insightPeriod = Time.Multiply(Extensions.ToTimeSpan(resolution), upperBand)
self.symbolData = {}
resolutionString = Extensions.GetEnumString(resolution, Resolution)
self.Name = '{}({},{},{})'.format(self.__class__.__name__, lowerBand, upperBand, resolutionString)
def Update(self, algorithm, data):
insights = []
for key, sd in self.symbolData.items():
if sd.donchian.IsReady and sd.donchianWindow.IsReady and sd._donchian["UpperBand"].IsReady and sd._donchian["LowerBand"].IsReady:
if sd._donchian["UpperBand"][1] < sd.Security.Close and sd.Security.Close > sd.ema:
insights.append(Insight.Price(sd.Security.Symbol, self.insightPeriod, InsightDirection.Up))
if sd._donchian["LowerBand"][1] > sd.Security.Close and sd.Security.Close < sd.ema:
insights.append(Insight.Price(sd.Security.Symbol, self.insightPeriod, InsightDirection.Down))
return insights
def OnSecuritiesChanged(self, algorithm, changes):
for added in changes.AddedSecurities:
self.symbolData[added.Symbol] = SymbolData(algorithm, added, self.upperBand, self.lowerBand, self.emaPeriod, self.resolution)
for removed in changes.RemovedSecurities:
data = self.symbolData.pop(removed.Symbol, None)
if data is not None:
algorithm.SubscriptionManager.RemoveConsolidator(removed.Symbol, data.Consolidator)
class SymbolData:
def __init__(self, algorithm, security, lowerBand, upperBand, emaPeriod, resolution):
self.Security = security
self.donchian = DonchianChannel(upperBand, lowerBand)
self._donchian = {}
self.Consolidator = algorithm.ResolveConsolidator(security.Symbol, resolution)
algorithm.RegisterIndicator(security.Symbol, self.donchian, self.Consolidator)
self.donchian.Updated += self.DonchianUpdated
self.donchianWindow = RollingWindow[IndicatorDataPoint](2)
self._donchian["UpperBand"] = RollingWindow[float](2)
self._donchian["LowerBand"] = RollingWindow[float](2)
self.ema = ExponentialMovingAverage(emaPeriod)
self.ConsolidatorEMA = algorithm.ResolveConsolidator(security.Symbol, resolution)
algorithm.RegisterIndicator(security.Symbol, self.ema, self.ConsolidatorEMA)
def DonchianUpdated(self, sender, updated):
self.donchianWindow.Add(updated)
self._donchian["UpperBand"].Add(self.donchian.UpperBand.Current.Value)
self._donchian["LowerBand"].Add(self.donchian.LowerBand.Current.Value)
Nicholas Fitzgerald
Found the solution, needed to use sd.ema.Current.Value
Nicholas Fitzgerald
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!