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?
-
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',), )
-
@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
-
@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?