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

HADelta code correction?

  • Hi backtrader, for the haDelta indicator,

    should this line

    o, c = d.close,

    be written as

    c, o = d.close,

    I was noticing that all the signals I was getting were flipped. Thanks!

    class haDelta(bt.Indicator):
        '''Heikin Ashi Delta. Defined by Dan Valcu in his book "Heikin-Ashi: How to
        Trade Without Candlestick Patterns ".
        This indicator measures difference between Heikin Ashi close and open of
        Heikin Ashi candles, the body of the candle.
        To get signals add haDelta smoothed by 3 period moving average.
        For correct use, the data for the indicator must have been previously
        passed by the Heikin Ahsi filter.
          - haDelta = Heikin Ashi close - Heikin Ashi open
          - smoothed = movav(haDelta, period)
        alias = ('haD',)
        lines = ('haDelta', 'smoothed')
        params = (
            ('period', 3),
            ('movav', MovAv.SMA),
            ('autoheikin', True),
        plotinfo = dict(subplot=True)
        plotlines = dict(
            smoothed=dict(color='grey', _fill_gt=(0, 'green'), _fill_lt=(0, 'red'))
        def __init__(self):
            d = bt.ind.HeikinAshi( if self.p.autoheikin else
            o, c = d.close,
            self.lines.haDelta = hd = c - o
            self.lines.smoothed = self.p.movav(hd, period=self.p.period)
            super(haDelta, self).__init__()

  • administrators

    Indeed. Will be soon corrected.

Log in to reply