Skip to content

Commit

Permalink
rename ma to ma_close, stds to stds_dist
Browse files Browse the repository at this point in the history
  • Loading branch information
stash86 committed Aug 17, 2024
1 parent 39972b7 commit 0f0318b
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 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, matype="sma"):
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 @@ -1056,24 +1056,24 @@ def MADR(dataframe, length=21, stds=2, matype="sma"):
"""

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

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

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

std = ta.STDDEV(df.rate, timeperiod=(length * stds))
df["plusdev"] = df["stdcenter"] + (std * stds)
df["minusdev"] = df["stdcenter"] - (std * stds)
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

0 comments on commit 0f0318b

Please sign in to comment.