heikinashi performance problem resolved

This commit is contained in:
hroff-1902 2019-05-07 23:39:42 +03:00
parent 2200a0223b
commit d642e03cd0

View File

@ -113,12 +113,11 @@ def heikinashi(bars):
bars['low'] + bars['close']) / 4 bars['low'] + bars['close']) / 4
# ha open # ha open
bars.loc[0:1, 'ha_open'] = (bars['open'].values[0] + bars['close'].values[0]) / 2 for i in range(0, len(bars)):
prev_open = bars[:1]['ha_open'].values[0] bars.at[i, 'ha_open'] = (
for idx, _ in bars[1:][['ha_open', 'ha_close']].iterrows(): (bars.at[0, 'open'] if i == 0 else bars.at[i - 1, 'ha_open']) +
loc = bars.index.get_loc(idx) (bars.at[0, 'close'] if i == 0 else bars.at[i - 1, 'ha_close'])
prev_open = (prev_open + bars['ha_close'].values[loc - 1]) / 2 ) / 2
bars.loc[loc:loc + 1, 'ha_open'] = prev_open
bars['ha_high'] = bars.loc[:, ['high', 'ha_open', 'ha_close']].max(axis=1) 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) bars['ha_low'] = bars.loc[:, ['low', 'ha_open', 'ha_close']].min(axis=1)