From 45e586773639da57f93d5fa3b7767ace37568160 Mon Sep 17 00:00:00 2001 From: hroff-1902 Date: Wed, 8 May 2019 23:41:45 +0300 Subject: [PATCH] heikinashi loop optimized; reset_index moved to tests --- freqtrade/vendor/qtpylib/indicators.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/freqtrade/vendor/qtpylib/indicators.py b/freqtrade/vendor/qtpylib/indicators.py index d62d062d7..6edf626f0 100644 --- a/freqtrade/vendor/qtpylib/indicators.py +++ b/freqtrade/vendor/qtpylib/indicators.py @@ -113,15 +113,9 @@ 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.at[0, 'ha_open'] = (bars.at[0, 'open'] + bars.at[0, 'close']) / 2 + for i in range(1, len(bars)): + bars.at[i, 'ha_open'] = (bars.at[i - 1, 'ha_open'] + bars.at[i - 1, 'ha_close']) / 2 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)