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/

    Problem feeding indicators through each other

    Indicators/Strategies/Analyzers
    1
    2
    179
    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.
    • C
      CooleRnax last edited by

      When I setup init this way I get nan in bears_change (direction change) indicator.

      bears = BearsPower(self.data, period=15)
      bears_change = Change(bears)
      

      But when I do it ugly way everything works, where is the problem?

      bears = BearsPower(self.data, period=15)
      bears_change = Change(bears.power)
      

      Indicators code:

      class Move(Indicator):
          lines = ('move',)
      
          def __init__(self):
              self.lines.move = self.data - self.data(-1)
              super(Move, self).__init__()
      
      
      class Change(Indicator):
          lines = ('change',)
      
          def __init__(self):
              self.move = Move(self.data)
              super(Change, self).__init__()
      
          def next(self):
              change = 0
              if self.move[-1] < 0 and self.move[0] > 0:
                  change += 1
              elif self.move[-1] > 0 and self.move[0] < 0:
                  change -= 1
              self.lines.change[0] = change
      
      class BearsPower(Indicator):
          lines = ('power',)
          params = dict(
              period=13,
              mode='close',
          )
      
          def __init__(self):
              if self.p.mode == 'close':
                  source = self.data.close
              elif self.p.mode == 'high':
                  source = self.data.high
              elif self.p.mode == 'low':
                  source = self.data.low
      
              self.ema = EMA(source, period=self.p.period)
              self.lines.power = self.data.low - self.ema
              super(BearsPower, self).__init__()
      
      1 Reply Last reply Reply Quote 0
      • C
        CooleRnax last edited by

        still not solved

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