Heiken Ashi bars not calculated correctly with compression
-
Hi,
I want to use both 1h and 4h Heiken Ashi bars.
First, I tried to read the 1-minute data in with resample and compression=60 and compression=240, but the Heiken Ashi bars are not calculated correctly (my guess is that as Heiken Ashi uses the previous bar open and close values that [-1] is not refereeing correctly to previous hour and previous 4-hour bar).
Next, I decided to try reading 1-hour bar data:
data = bt.feeds.GenericCSVData(
....
timeframe=bt.TimeFrame.Minutes,
compression=60,
...)dataHK = bt.feeds.GenericCSVData(
....
timeframe=bt.TimeFrame.Minutes,
compression=60,
...)#Add the filter
dataHK.addfilter(bt.filters.HeikinAshi(dataHK))#Add the data to Cerebro
cerebro.adddata(data, name="Real")
cerebro.adddata(dataHK, name="Heikin")and Heiken Ashi bars are calculated correctly.
Now I have problems (or don't understand how to configure), to add 4h-data. I can't use the same data of 1-hour bars with resample and different compression (because Heiken Ashi is not calculated correctly), so I tried to read both 1h- and 4h-data. In addition to the data definitions above, I added:
data4HK = bt.feeds.GenericCSVData(
...
timeframe=bt.TimeFrame.Minutes,
compression=240,
... )#Add the filter
dataHK.addfilter(bt.filters.HeikinAshi(dataHK))
data4HK.addfilter(bt.filters.HeikinAshi(data4HK))#Add the data to Cerebro
cerebro.adddata(data, name="Real")
cerebro.adddata(dataHK, name="Heikin")
cerebro.adddata(data4HK, name="Heikin4")BUT it doesn't work either.... because def(next) can't process 1h and 4h-data correctly.
Any help, how to go on? The easiest solution would be to somehow define Heiken Ashi to calculate bars correctly with compression=60 and compression =240.... but any solution is appreciated.