Skip to content

Commit

Permalink
chaikin_oscillator fix
Browse files Browse the repository at this point in the history
Fix for Chaikin Oscillator as suggested by @renubar
  • Loading branch information
voice32 committed May 7, 2018
1 parent a7cde03 commit 7c60ae3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions indicators.py
Expand Up @@ -224,13 +224,15 @@ def bollinger_bands(data, trend_periods=20, close_col='<CLOSE>'):
def chaikin_oscillator(data, periods_short=3, periods_long=10, high_col='<HIGH>',
low_col='<LOW>', close_col='<CLOSE>', vol_col='<VOL>'):
ac = pd.Series([])

val_last = 0

for index, row in data.iterrows():
if row[high_col] != row[low_col]:
val = ((row[close_col] - row[low_col]) - (row[high_col] - row[close_col])) / (row[high_col] - row[low_col]) * row[vol_col]
val = val_last + ((row[close_col] - row[low_col]) - (row[high_col] - row[close_col])) / (row[high_col] - row[low_col]) * row[vol_col]
else:
val = 0
val = val_last
ac.set_value(index, val)
val_last = val

ema_long = ac.ewm(ignore_na=False, min_periods=0, com=periods_long, adjust=True).mean()
ema_short = ac.ewm(ignore_na=False, min_periods=0, com=periods_short, adjust=True).mean()
Expand Down

0 comments on commit 7c60ae3

Please sign in to comment.