mirror of
https://github.com/wassname/pandas-ta.git
synced 2026-09-09 11:28:26 +08:00
ENH PR #153 atr tv mamode alignment
This commit is contained in:
@@ -626,6 +626,7 @@ indicator consisting of two different simple moving averages. See: ```help(ta.tt
|
||||
* _Elder's Thermometer_ (**thermo**) Elder's Thermometer measures price volatility. See: ```help(ta.thermo)```
|
||||
|
||||
## **Updated**
|
||||
* _Average True Range_ (**atr**): The default ```mamode``` is now "**RMA**" and with the same ```mamode``` options as TradingView. See ```help(ta.atr)```.
|
||||
* _Trend Return_ (**trend_return**): Returns a DataFrame now instead of Series with pertinenet trade info for a _trend_. An example can be found in the [AI Example Notebook](https://github.com/twopirllc/pandas-ta/tree/master/examples/AIExample.ipynb). The notebook is still a work in progress and open to colloboration.
|
||||
|
||||
|
||||
|
||||
+10
-13
@@ -1,34 +1,30 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from pandas_ta.overlap import ema, rma, sma
|
||||
from pandas_ta.overlap.wma import wma
|
||||
from pandas_ta.overlap import ema, rma, sma, wma
|
||||
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='rma', drift=None, offset=None, **kwargs):
|
||||
def atr(high, low, close, length=None, mamode=None, 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 = str(mamode).lower()
|
||||
|
||||
mamode = mamode = mamode.lower() if mamode else "rma"
|
||||
drift = get_drift(drift)
|
||||
offset = get_offset(offset)
|
||||
|
||||
# Calculate Result
|
||||
_mode = ""
|
||||
tr = true_range(high=high, low=low, close=close, drift=drift)
|
||||
if mamode == "ema":
|
||||
# alpha = (1.0 / length) if length > 0 else 0.5
|
||||
# atr = tr.ewm(alpha=alpha).mean()
|
||||
atr = ema(tr, length=length)
|
||||
atr, _mode = ema(tr, length=length), "ema"
|
||||
elif mamode == "sma":
|
||||
# atr = tr.rolling(length).mean()
|
||||
atr = sma(tr, length=length)
|
||||
atr, _mode = sma(tr, length=length), "sma"
|
||||
elif mamode == "wma":
|
||||
atr = wma(tr, length=length)
|
||||
else:
|
||||
atr, _mode = wma(tr, length=length), "wma"
|
||||
else: # "rma"
|
||||
atr = rma(tr, length=length)
|
||||
|
||||
percentage = kwargs.pop("percent", False)
|
||||
@@ -46,7 +42,8 @@ def atr(high, low, close, length=None, mamode='rma', drift=None, offset=None, **
|
||||
atr.fillna(method=kwargs["fill_method"], inplace=True)
|
||||
|
||||
# Name and Categorize it
|
||||
atr.name = f"ATR{'p' if percentage else ''}_{length}"
|
||||
# mamode_ =
|
||||
atr.name = f"ATR{_mode}_{length}{'p' if percentage else ''}"
|
||||
atr.category = "volatility"
|
||||
|
||||
return atr
|
||||
|
||||
Reference in New Issue
Block a user