ENH PR #153 atr tv mamode alignment

This commit is contained in:
Kevin Johnson
2020-10-30 09:32:24 -07:00
parent ac39583a2f
commit 00906b86f3
3 changed files with 12 additions and 14 deletions
+1
View File
@@ -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
View File
@@ -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
+1 -1
View File
@@ -17,7 +17,7 @@ setup(
"pandas_ta.volatility",
"pandas_ta.volume"
],
version=".".join(("0", "2", "23b")),
version=".".join(("0", "2", "24b")),
description=long_description,
long_description=long_description,
author="Kevin Johnson",