The function always calculated ATR in EMA mode.
This commit is contained in:
YuvalWein
2020-10-20 23:25:45 +03:00
committed by GitHub
parent 286aea7e63
commit 388e24bc56
+4 -11
View File
@@ -3,15 +3,15 @@ from pandas_ta.overlap import ema, rma
from .true_range import true_range
from pandas_ta.utils import get_drift, get_offset, verify_series
def atr(high, low, close, length=None, mamode=None, drift=None, offset=None, **kwargs):
def atr(high, low, close, length=None, mamode='sma', drift=None, offset=None, **kwargs):
"""Indicator: Average True Range (ATR)"""
# Validate arguments
high = verify_series(high)
low = verify_series(low)
close = verify_series(close)
length = int(length) if length and length > 0 else 14
mamode = mamode.lower() if mamode else "ema"
mamode = str(mamode).lower()
drift = get_drift(drift)
offset = get_offset(offset)
@@ -48,13 +48,10 @@ def atr(high, low, close, length=None, mamode=None, drift=None, offset=None, **k
atr.__doc__ = \
"""Average True Range (ATR)
Averge True Range is used to measure volatility, especially
volatility caused by gaps or limit moves.
Sources:
https://www.tradingview.com/wiki/Average_True_Range_(ATR)
Calculation:
Default Inputs:
length=14, drift=1, percent=False
@@ -66,24 +63,20 @@ Calculation:
ATR = EMA(tr, length)
else:
ATR = SMA(tr, length)
if percent:
ATR *= 100 / close
Args:
high (pd.Series): Series of 'high's
low (pd.Series): Series of 'low's
close (pd.Series): Series of 'close's
length (int): It's period. Default: 14
mamode (str): Two options: None or 'ema'. Default: 'ema'
mamode (str): Two options: 'sma' or 'ema'. Default: 'sma'
drift (int): The difference period. Default: 1
offset (int): How many periods to offset the result. Default: 0
Kwargs:
percent (bool, optional): Return as percentage. Default: False
fillna (value, optional): pd.DataFrame.fillna(value)
fill_method (value, optional): Type of fill method
Returns:
pd.Series: New feature generated.
"""