Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Balance of Power Indicator #294

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions ta/trend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1857,3 +1857,22 @@ def psar_down_indicator(high, low, close, step=0.02, max_step=0.20, fillna=False
high=high, low=low, close=close, step=step, max_step=max_step, fillna=fillna
)
return indicator.psar_down_indicator()

class BOPIndicator(IndicatorMixin):

def __init__(self, close: pd.Series, open: pd.Series, high: pd.Series, low: pd.Series, fillna: bool = False):
self._close = close
self._open = open
self._high = high
self._low = low
self._fillna = fillna
self._run()

def _run(self):
top = self._close - self._open
bottom = self._high - self._low
self._bop = sma_indicator(top/bottom)

def bop(self) -> pd.Series:
bop = self._check_fillna(self._bop, value=0)
return pd.Series(bop, name='BOPIndicator')
7 changes: 7 additions & 0 deletions ta/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
STCIndicator,
TRIXIndicator,
VortexIndicator,
BOPIndicator,
)
from ta.volatility import (
AverageTrueRange,
Expand Down Expand Up @@ -276,6 +277,12 @@ def add_trend_ta(
df[f"{colprefix}trend_vortex_ind_neg"] = indicator_vortex.vortex_indicator_neg()
df[f"{colprefix}trend_vortex_ind_diff"] = indicator_vortex.vortex_indicator_diff()

# BOP Indicator
indicator_bop = BOPIndicator(
close = df[close], open = df[open], high = df[high], low = df[low], fillna = fillna
)
df[f"{colprefix}trend_bop_ind"] = indicator_bop.bop()

# TRIX Indicator
df[f"{colprefix}trend_trix"] = TRIXIndicator(
close=df[close], window=15, fillna=fillna
Expand Down