For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
2019-10-02: The community is currently in read-only mode

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



  • 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?


  • administrators

    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?



  • 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



  • 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',),
        )
    

  • administrators

    @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


Log in to reply
 

});