Using Technical Indicator and Sequence Functions on K-Line Data
Summary
This documentation describes two related tools for calculating technical signals from K-line data. The technical-indicator module provides named indicator functions that take a pandas DataFrame of bars and return a DataFrame of calculated series. MACD is shown as an example, with its difference series accessed from the result.
A separate sequence-function module supplies lower-level calculations that form the basis of indicators. These functions can also be used directly when a standard indicator’s input is too restrictive. For example, a moving average function can calculate an average from bar highs, whereas the standard moving-average indicator uses closing prices. The examples explain basic function roles and data flow, but the page does not assess signal quality, trading rules, or performance; users need the referenced function documentation for available calculations and parameters.
Key ideas
- Indicator functions accept bar data and return calculated series in a DataFrame.
- The MACD example shows how to retrieve one component of an indicator result.
- Lower-level sequence functions allow calculations on custom price series.
- A moving average can be applied to bar highs when a close-based indicator does not fit the task.
Tags
Full text
# ta
.. _ta:
技术指标与序列计算函数
====================================================
技术指标
----------------------------------------------------
tqsdk.ta 模块中包含了大量技术指标. 每个技术指标是一个函数, 函数名为全大写, 第一参数总是K线序列, 以pandas.DataFrame格式返回计算结果. 以MACD为例::
from tqsdk.ta import MACD
klines = api.get_kline_serial("SHFE.cu2607", 60) # 提取SHFE.cu2607的分钟线
result = MACD(klines, 12, 26, 9) # 计算MACD指标
print(result["diff"]) # MACD指标中的diff序列
tqsdk.ta 中目前提供的技术指标详表,请见 :ref:`tqsdk.ta`
序列计算函数
----------------------------------------------------
tqsdk.tafunc 模块中包含了一批序列计算函数. 它们是构成技术指标的基础. 在某些情况下, 您也可以直接使用这些序列计算函数以获取更大的灵活性.
例如, 技术指标MA(均线)总是按K线的收盘价来计算, 如果你需要计算最高价的均线, 可以使用ma函数::
from tqsdk.tafunc import ma
klines = api.get_kline_serial("SHFE.cu2607", 60) # 提取SHFE.cu2607的分钟线
result = ma(klines.high, 9) # 按K线的最高价序列做9分钟的移动平均
print(result) # 移动平均结果
tqsdk.tafunc 中目前提供的序列计算函数详表,请见 :ref:`tqsdk.tafunc`Shown in full with attribution under the source's licence. Licence: Apache-2.0
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.