fixed: heikinashi worked in backtesting, but failed in tests with testing arrays

This commit is contained in:
hroff-1902 2019-05-08 00:00:44 +03:00
parent d642e03cd0
commit 2554ebf273

View File

@ -113,11 +113,15 @@ def heikinashi(bars):
bars['low'] + bars['close']) / 4
# ha open
idx = bars.index.name
bars.reset_index(inplace=True)
for i in range(0, len(bars)):
bars.at[i, 'ha_open'] = (
(bars.at[0, 'open'] if i == 0 else bars.at[i - 1, 'ha_open']) +
(bars.at[0, 'close'] if i == 0 else bars.at[i - 1, 'ha_close'])
) / 2
if idx:
bars.set_index(idx, inplace=True)
bars['ha_high'] = bars.loc[:, ['high', 'ha_open', 'ha_close']].max(axis=1)
bars['ha_low'] = bars.loc[:, ['low', 'ha_open', 'ha_close']].min(axis=1)