Skip to content

Commit

Permalink
include preferred notation with .loc[]
Browse files Browse the repository at this point in the history
  • Loading branch information
boschje authored Feb 19, 2021
1 parent 0690605 commit 417ebfd
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions technical/candles.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


def heikinashi(bars):
"""
"""
Heikin Ashi calculation: https://school.stockcharts.com/doku.php?id=chart_analysis:heikin_ashi
ha_open calculation based on: https://stackoverflow.com/a/55110393
Expand All @@ -20,14 +20,14 @@ def heikinashi(bars):

bars = bars.copy()

bars['ha_close'] = bars[['open', 'high', 'low', 'close']].mean(axis=1)
bars.loc[:, 'ha_close'] = bars.loc[:, ['open', 'high', 'low', 'close']].mean(axis=1)

ha_open = [ (bars.open[0] + bars.close[0]) / 2 ]
[ ha_open.append((ha_open[x] + bars.ha_close[x]) / 2) for x in range(0, len(bars)-1) ]
bars['ha_open'] = ha_open

bars['ha_high'] = bars[['ha_open', 'ha_close', 'high']].max(axis=1)
bars['ha_low'] = bars[['ha_open', 'ha_close', 'low']].min(axis=1)
bars.loc[:, 'ha_high'] = bars.loc[:, ['ha_open', 'ha_close', 'high']].max(axis=1)
bars.loc[:, 'ha_low'] = bars.loc[:, ['ha_open', 'ha_close', 'low']].min(axis=1)

result = pd.DataFrame(
index=bars.index,
Expand Down

0 comments on commit 417ebfd

Please sign in to comment.