本文整理汇总了Python中talib.TRANGE属性的典型用法代码示例。如果您正苦于以下问题:Python talib.TRANGE属性的具体用法?Python talib.TRANGE怎么用?Python talib.TRANGE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类talib
的用法示例。
在下文中一共展示了talib.TRANGE属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: trange
# 需要导入模块: import talib [as 别名]
# 或者: from talib import TRANGE [as 别名]
def trange(candles: np.ndarray, sequential=False) -> Union[float, np.ndarray]:
"""
TRANGE - True Range
:param candles: np.ndarray
:param sequential: bool - default=False
:return: float | np.ndarray
"""
if not sequential and len(candles) > 240:
candles = candles[-240:]
res = talib.TRANGE(candles[:, 3], candles[:, 4], candles[:, 2])
if sequential:
return res
else:
return None if np.isnan(res[-1]) else res[-1]
示例2: test_tr
# 需要导入模块: import talib [as 别名]
# 或者: from talib import TRANGE [as 别名]
def test_tr():
'''test TA.TR'''
tr = TA.TR(ohlc)
talib_tr = talib.TRANGE(ohlc['high'], ohlc['low'], ohlc['close'])
assert round(talib_tr[-1], 5) == round(tr.values[-1], 5)
示例3: TRANGE
# 需要导入模块: import talib [as 别名]
# 或者: from talib import TRANGE [as 别名]
def TRANGE(frame, high_col='high', low_col='low', close_col='close'):
return _frame_to_series(frame, [high_col, low_col, close_col], talib.TRANGE)
示例4: test_true_range
# 需要导入模块: import talib [as 别名]
# 或者: from talib import TRANGE [as 别名]
def test_true_range(self):
result = pandas_ta.true_range(self.high, self.low, self.close)
self.assertIsInstance(result, Series)
self.assertEqual(result.name, 'TRUERANGE_1')
try:
expected = tal.TRANGE(self.high, self.low, self.close)
pdt.assert_series_equal(result, expected, check_names=False)
except AssertionError as ae:
try:
corr = pandas_ta.utils.df_error_analysis(result, expected, col=CORRELATION)
self.assertGreater(corr, CORRELATION_THRESHOLD)
except Exception as ex:
error_analysis(result, CORRELATION, ex)
示例5: TRANGE
# 需要导入模块: import talib [as 别名]
# 或者: from talib import TRANGE [as 别名]
def TRANGE(data, **kwargs):
_check_talib_presence()
_, phigh, plow, pclose, _ = _extract_ohlc(data)
return talib.TRANGE(phigh, plow, pclose, **kwargs)
# ---------------------------------------------
# Parrern Recognition
# ---------------------------------------------
示例6: ADX_MA
# 需要导入模块: import talib [as 别名]
# 或者: from talib import TRANGE [as 别名]
def ADX_MA(data, period=14, smooth=14, limit=18):
"""
Moving Average ADX
ADX Smoothing Trend Color Change on Moving Average and ADX Cross. Use on Hourly Charts - Green UpTrend - Red DownTrend - Black Choppy No Trend
Source: https://www.tradingview.com/script/owwws7dM-Moving-Average-ADX/
Translator: 阿财(Rgveda@github)(4910163#qq.com)
Parameters
----------
data : (N,) array_like
传入 OHLC Kline 序列。
The OHLC Kline.
period : int or None, optional
DI 统计周期 默认值为 14
DI Length period. Default value is 10.
smooth : int or None, optional
ADX 平滑周期 默认值为 14
ADX smoothing length period. Default value is 10.
limit : int or None, optional
ADX 限制阈值 默认值为 18
ADX MA Active limit threshold. Default value is 18.
Returns
-------
adx, ADXm : ndarray
ADXm 指标和趋势指示方向 (-1, 0, 1) 分别代表 (下跌, 无明显趋势, 上涨)
ADXm indicator and thread directions sequence. (-1, 0, 1) means for (Neagtive, No Trend, Positive)
"""
up = data.high.pct_change()
down = data.low.pct_change() * -1
trur = TA_HMA(talib.TRANGE(data.high.values, data.low.values, data.close.values) , period)
plus = 100 * TA_HMA(np.where(((up > down) & (up > 0)), up, 0), period) / trur
minus = 100 * TA_HMA(np.where(((down > up) & (down > 0)), down, 0), period) / trur
# 这里是dropna的替代解决办法,因为我觉得nparray的传递方式如果随便drop了可能会跟 data.index
# 对不上,所以我选择补零替代dropna
plus = np.r_[np.zeros(period + 2), plus[(period + 2):]]
minus = np.r_[np.zeros(period + 2), minus[(period + 2):]]
sum = plus + minus
adx = 100 * TA_HMA(abs(plus - minus) / (np.where((sum == 0), 1, sum)), smooth)
adx = np.r_[np.zeros(smooth + 2), adx[(smooth + 2):]]
ADXm = np.where(((adx > limit) & (plus > minus)), 1, np.where(((adx > limit) & (plus < minus)), -1, 0))
return adx, ADXm