本文整理匯總了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