For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

How to get data stream notifier from inside indicator



  • Hi there,
    Thanks for the great platform!
    A fairly straightforward question:

    How do I get the data status (CONNECTED,DELAYED,LIVE etc.) inside my Indicator?

    Inside a strategy I can use

    def notify_data(self, data, status, *args, **kwargs):
            logger.info(self.asset_name+" DATA STREAM NOTIFIER = {}".format(data._getstatusname(status)))
            if status == data.LIVE:
                self.counttostop = self.p.stopafter
                self.datastatus = 1
    

    But I'm not sure how I can translate this to inside the indicator.

    Thanks!
    Josh


  • administrators

    Indicators do not receive notifications. They are meant to be calculators.

    But nothing prevents you from passing any information to an indicator, via a member attribute or invoking a user defined method.



  • Thanks for the response, and good to know.

    I managed to solve my issue by doing

            try:
                status = (self.datas[0]._getstatusname(self.datas[0]._laststatus))
            except AttributeError:
                # Means we backtesting
                status = None
    

    within the next of my indicator.

    Cheers,
    Josh


  • administrators

    Although that code seems sane, it doesn't make any sense when the data feed for the indicator is not a data feed which provides notifications.

    A classical example is an SMA of another SMA. It would therefore seems more logical and reasonable to pass the information using a method.

    But each master ... has his own way



  • Aha, yes I see your point. Well, for now this will work :)
    Thanks for pointing it out!
    Josh