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/

    MACDHisto wrongly calculated, exact same value as MACD

    Indicators/Strategies/Analyzers
    2
    3
    298
    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.
    • D
      dirkie last edited by

      Hello,

      I am new to backtrader. I have experienced with some indicators like RSI, EMA9, MACD and MACDHisto. All indicators produce correct output EXPECT MACDHisto. MACDHisto output has exact same value as MACD. This looks like a bug to me. Strange enough nobody else has yet stumbled upon this.

          def __init__(self):
              # Keep a reference to the "close" line in the data[0] dataseries
              self.dataclose = self.datas[0].close
      
              # To keep track of pending orders and buy price/commission
              self.order = None
              self.buyprice = None
              self.buycomm = None
      
              # Add a MovingAverageSimple indicator
              self.sma = bt.indicators.SimpleMovingAverage(
                  self.datas[0], period=self.params.maperiod)
              self.rsi = bt.indicators.RSI(self.datas[0])
              self.ema9 = bt.indicators.EMA(self.datas[0], period=9)
              self.macdhisto = bt.indicators.MACDHisto(
                  self.datas[0], period_me1=12, period_me2=26, period_signal=9 )
              self.macd = bt.indicators.MACD(
                  self.datas[0], period_me1=12, period_me2=26, period_signal=9 )
      
      <output omitted>
      
          def next(self):
              # Simply log the closing price of the series from the reference
              self.log('Close, %.2f, MACD %2.f, MACDhisto %2.f, RSI %2.f, EMA9 %2.f' %(self.dataclose[0], self.macd[0], self.macdhisto[0],self.rsi[0],self.ema9[0]))
      
      

      This produces the following output, note that MACDHisto has same value as MACD
      2020-05-28, Close, 3030.76, MACD 17, MACDhisto 17, RSI 54, EMA9 3040
      2020-05-28, Close, 3036.62, MACD 16, MACDhisto 16, RSI 56, EMA9 3039
      2020-05-29, Close, 3029.62, MACD 14, MACDhisto 14, RSI 53, EMA9 3037
      2020-05-29, Close, 3035.12, MACD 13, MACDhisto 13, RSI 55, EMA9 3037
      2020-05-29, Close, 3022.24, MACD 11, MACDhisto 11, RSI 50, EMA9 3034
      2020-05-29, Close, 3034.62, MACD 10, MACDhisto 10, RSI 54, EMA9 3034
      2020-05-29, Close, 3022.52, MACD 9, MACDhisto 9, RSI 50, EMA9 3032
      2020-05-29, Close, 3016.95, MACD 7, MACDhisto 7, RSI 48, EMA9 3029
      2020-05-29, Close, 3039.87, MACD 7, MACDhisto 7, RSI 56, EMA9 3031
      2020-05-29, Close, 3061.44, MACD 9, MACDhisto 9, RSI 61, EMA9 3037

      1 Reply Last reply Reply Quote 0
      • vladisld
        vladisld last edited by

        try to print:

        def next(self):
                # Simply log the closing price of the series from the reference
                self.log('Close, %.2f, MACD %2.f, MACDhisto %2.f, RSI %2.f, EMA9 %2.f' %(self.dataclose[0], self.macd[0], self.macdhisto.histo[0],self.rsi[0],self.ema9[0]))
        

        It seems the MACDHisto indicator has 3 lines: macd (default), 'signal` and 'histo'.

        1 Reply Last reply Reply Quote 0
        • D
          dirkie last edited by

          That indeed solved it. Thank you very very much for the quick response!

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