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

update MADR #473

Merged
merged 3 commits into from
Aug 17, 2024
Merged
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
29 changes: 21 additions & 8 deletions technical/indicators/indicators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ def VIDYA(dataframe, length=9, select=True):
return df["VIDYA"]


def MADR(dataframe, length=21, stds=2):
def MADR(dataframe, length=21, stds_dist=2, matype="sma"):
"""
Moving Averae Deviation RAte just like bollinger bands ...
Source: https://tradingview.com/script/25KCgL9H/
Expand Down Expand Up @@ -1054,13 +1054,26 @@ def MADR(dataframe, length=21, stds=2):
_plusDev = _stdCenter + _std * 2
_minusDev = _stdCenter - _std * 2
"""
df["sma"] = ta.SMA(df, timeperiod=length)
df["rate"] = (df["close"] / df["sma"]) * 100 - 100
df["stdcenter"] = ta.SMA(df.rate, timeperiod=length * stds)
df["std"] = ta.STDDEV(df.rate, timeperiod=length * stds)
df["plusdev"] = df["stdcenter"] + df["std"] * stds
df["minusdev"] = df["stdcenter"] - df["std"] * stds
df = df.drop(columns=["sma", "std"])

if matype.lower() == "sma":
ma_close = ta.SMA(df, timeperiod=length)
elif matype.lower() == "ema":
ma_close = ta.EMA(df, timeperiod=length)
else:
ma_close = ta.SMA(df, timeperiod=length)

df["rate"] = ((df["close"] / ma_close) * 100) - 100

if matype.lower() == "sma":
df["stdcenter"] = ta.SMA(df.rate, timeperiod=(length * stds_dist))
elif matype.lower() == "ema":
df["stdcenter"] = ta.EMA(df.rate, timeperiod=(length * stds_dist))
else:
df["stdcenter"] = ta.SMA(df.rate, timeperiod=(length * stds_dist))

std = ta.STDDEV(df.rate, timeperiod=(length * stds_dist))
df["plusdev"] = df["stdcenter"] + (std * stds_dist)
df["minusdev"] = df["stdcenter"] - (std * stds_dist)
# return stdcenter , plusdev , minusdev, rate
return df

Expand Down
Loading