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/

    Can somebody explain me how to use the heikin ashi indicator into a strategy

    General Code/Help
    4
    6
    1380
    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.
    • S
      Simone last edited by Simone

      Hi at all as you can see from the short description field can somebody explain me how to use heikin ashi indicator into a strategy. I was reading the documentation about the heikin ashi but i didn't understand how implement the indicator inside my strategy. Can somebody please help me?

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        The indicator version has with 4 output lines

        • ha_open
        • ha_high
        • ha_low
        • ha_close

        It works exactly as any other indicator. What is the problem?

        1 Reply Last reply Reply Quote 0
        • S
          Simone last edited by

          I want to use the heikin ashi data into the indicators, for example, i want to use the weighted moving avarage and the RSI also based to the Hekin Ashi data.
          I've tried to wrote this:

          self.sma=bt.indicators.SimpleMovingAverage(self.hk.close[0], period=self.params.speriod)
          

          but is not working. Is giving me:

          AttributeError: 'Lines_LineSeries_LineIterator_DataAccessor_Strateg' object has no attribute 'ha_close'
          

          I've tried also in that way:

          def __init__(self):
                  self.ha_close=bt.indicators.HeikinAshi()
                  self.startcash=self.broker.getvalue()
          	self.ema=bt.indicators.WeightedMovingAverage(
          		self.ha_close[0],period=self.params.period)
          
          IndexError: array index out of range
          

          And another question because on internet (https://backtest-rookies.com/2018/01/26/backtrader-working-heikin-ashi/) i found a tutorial that explain one strategy code but is using hk.close instead of ha_close that you told me.

          P.S. I'm sorry if my question are so obviously for a lot of people. I'm pretty new and here is look like one of the only place that somebody can help me

          1 Reply Last reply Reply Quote 0
          • M
            momentum last edited by

            You don't pass to the SimpleMovingAverage the ha_close line (self.hk.close) but rather a specific value of it (self.hk.close[0]).

            If you look at the implementation of class HeikinAshi, it has line alias

                lines = ('ha_open', 'ha_high', 'ha_low', 'ha_close',)
            
                linealias = (
                    ('ha_open', 'open',),
                    ('ha_high', 'high',),
                    ('ha_low', 'low',),
                    ('ha_close', 'close',),
                )
            
            1 Reply Last reply Reply Quote 0
            • B
              backtrader administrators last edited by

              @Simone said in Can somebody explain me how to use the heikin ashi indicator into a strategy:

              You say you want to work with the INDICATOR.

              @backtrader said in Can somebody explain me how to use the heikin ashi indicator into a strategy:

              The indicator version has with 4 output lines

              ha_open

              You get information for the INDICATOR

              @Simone said in Can somebody explain me how to use the heikin ashi indicator into a strategy:

              but is using hk.close instead of ha_close that you told me.

              Apparently you DON'T want the INDICATOR. You want a standard data stream transformed into a Heikin Ashi data stream.

              But first, if you have the indicator ... with a line named ha_close, you don't do this

              @Simone said in Can somebody explain me how to use the heikin ashi indicator into a strategy:

              self.sma=bt.indicators.SimpleMovingAverage(self.hk.ha_close[0], period=self.params.speriod)
              

              Because as pointed out by @momentum, you are passing the CURRENT value (which at the moment you actually create it ... it doesn't exist) to the SimpleMovingAverage

              You pass the ENTIRE line

              self.sma=bt.indicators.SimpleMovingAverage(self.hk.ha_close, period=self.params.speriod)
              

              If you want the transformed data you add a filter

              data.addfilter(bt.filters.HeikinAshi)
              

              Please read this post

              • Blog - Release 1.9.51.121
              1 Reply Last reply Reply Quote 0
              • J
                jennywestwong last edited by

                @backtrader, @momentum @Simone with addfilter, the whole data source changes to heikin ashi values and the backtest produces fake results with non existing value. But what if I only want to use specific heiken ashi o/h/l/c and normal o/h/l/c values in my strategy to compute something?

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