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

HADelta code correction?



  • Hi backtrader, for the haDelta indicator,

    should this line

    o, c = d.close, d.open
    

    be written as

    c, o = d.close, d.open
    

    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.
    
        Formula:
          - 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(
            haDelta=dict(color='red'),
            smoothed=dict(color='grey', _fill_gt=(0, 'green'), _fill_lt=(0, 'red'))
        )
    
        def __init__(self):
            d = bt.ind.HeikinAshi(self.data) if self.p.autoheikin else self.data
            o, c = d.close, d.open
    
            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.


 

});