Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    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

    Indicators/Strategies/Analyzers
    2
    5
    527
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      jwsmith last edited by

      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

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • J
          jwsmith last edited by

          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

          1 Reply Last reply Reply Quote 1
          • B
            backtrader administrators last edited by

            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

            1 Reply Last reply Reply Quote 0
            • J
              jwsmith last edited by

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

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors