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
-
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__()
-
still not solved