Back

Runtime Error accessing SMA

I am a bit puzzled and I don't know what I am doing wrong. This code:

class QuantumDynamicProcessor(QCAlgorithm):

def Initialize(self):

self.SetStartDate(2019, 1, 1) # Set Start Date
self.SetCash(200) # Set Strategy Cash
self.AddForex("EURUSD", Resolution.Daily, Market.Oanda)
self.SetBrokerageModel(BrokerageName.OandaBrokerage)

self.heikinAshi = self.HeikinAshi("EURUSD", Resolution.Daily)
self.momentum = self.MOM("EURUSD", 10, Resolution.Daily)
self.movingAverage = self.SMA("EURUSD", 50, Resolution.Daily)
self.RegisterIndicator("EURUSD", self.movingAverage, Resolution.Daily)

self.SetWarmUp(50)

def OnData(self, data):
if not self.Portfolio.Invested:
if self.heikinAshi.Close.Value > self.movingAverage.Current.Value:
self.MarketOrder("EURUSD", 1000)
if self.Portfolio.Invested:
if self.heikinAshi.Close.Value < self.heikinAshi.Open.Value:
self.MarketOrder("EURUSD", -1000)

Results in a Runtime Error.

Runtime Error: AttributeError : 'Identity' object has no attribute 'Value'
at OnData in main.py:line 19
:: if self.heikinAshi.Close.Value > self.movingAverage.Current.Value:
AttributeError : 'Identity' object has no attribute 'Value' (Open Stacktrace)

Isn't this the right way to access the current value of a moving average?

Update Backtest







0

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.


Hi Chantal Coolsma 

Please add .Current before .Value:

def OnData(self, data):
if not self.Portfolio.Invested:
if self.heikinAshi.Close.Current.Value > self.movingAverage.Current.Value:
self.MarketOrder("EURUSD", 1000)
if self.Portfolio.Invested:
if self.heikinAshi.Close.Current.Value < self.heikinAshi.Open.Current.Value:
self.MarketOrder("EURUSD", -1000)

In all Indicators, the numerical value can be found in the Current.Value attribute. 

1

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.


Update Backtest





0

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.


Loading...

This discussion is closed