Back

Custom indicator. Error - object has no attribute 'Updated'

Hello,

I have developed cutom indicator using python and I need to store data in rolling window.

I can't find any examples of the Updated function.

Please help.

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 Konstantin,

Please check out “Combining with Indicators” and “Custom Period Indicators” page for illustrations of using the Update function. In addition, there is a great example in python here for your reference too. Hope this helps! If you have further questions, please let us know!

Thanks for your support!

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 Alethea Lin,

I ask not about Update function, I ask about Updated. Updated is requred by rolling windows. There is no examples of Updated implementation for custom indicators.

# In Initialize, create the rolling windows
def Initialize(self):
# Creates an indicator and adds to a rolling window when it is updated
self.SMA("SPY", 5).Updated += self.SmaUpdated
self.smaWindow = RollingWindow[IndicatorDataPoint](5)

# Adds updated values to rolling window
def SmaUpdated(self, sender, updated):
self.smaWindow.Add(updated)

 

 

0

Hi Konstantin,

Sorry that I misunderstood your question. Based on the error, it is likely that there is something wrong with creating the custom indicator. All indicators should extend the IndicatorBase class, hence have the Updated event handler. I tried to find two more examples here and here that might be helpful for you to check out.

In the meantime, could you please share your code so we can replicate the issue in order to assist you better?

Thanks for supporting QC, and we look forward to your response.

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.


class AwesomeOscillator():
def __init__(self, name, fast=5, slow=34):
self.Name = name
self.Time = datetime.min
self.Value = 0
self.IsReady = False
self.p = {}
self.p['fast'] = fast
self.p['slow'] = slow
self.queue_fast = deque(maxlen=fast)
self.queue_slow = deque(maxlen=slow)

def __repr__(self):
return "{0} -> IsReady: {1}. Time: {2}. Value: {3}".format(self.Name, self.IsReady, self.Time, self.Value)

def Update(self, input):
median = (input.High + input.Low) / 2.0
self.queue_fast.appendleft(median)
self.queue_slow.appendleft(median)
self.Time = input.EndTime

count = max([len(self.queue_fast), len(self.queue_slow)])
maxlen = max([self.queue_fast.maxlen, self.queue_slow.maxlen])
sma_fast = sum(self.queue_fast) / self.p['fast']
sma_slow = sum(self.queue_slow) / self.p['slow']

self.Value = sma_fast - sma_slow
self.IsReady = count == maxlen

Using IndicatorBase leads to error,

TypeError : cannot instantiate an open generic type

My indicator is based on url

0

Hi Konstantin,

Thank you for providing the code. I was able to reproduce the same error. Actually, adding customer indicators to RollingWindow is not supported yet. However, I have created an issue for the engineering team to add this feature to LEAN. You can follow this GitHub issue for updates.

Thanks for bringing up the issue so we can make LEAN better!

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.


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