资源加载中... loading...

TA

TA.MACD

TA.MACD()函数用于计算指数平滑异同平均线指标

TA.MACD()函数的返回值为二维数组,结构为:[DIF, DEA, MACD]。 array

TA.MACD(inReal) TA.MACD(inReal, optInFastPeriod, optInSlowPeriod, optInSignalPeriod)

inReal参数用于指定K线数据。 inReal true {@struct/Record Record}结构数组、数值数组 optInFastPeriod参数用于设置快周期。 optInFastPeriod false number optInSlowPeriod参数用于设置慢周期。 optInSlowPeriod false number optInSignalPeriod参数用于设置信号周期。 optInSignalPeriod false number

function main(){
    // 可以填入不同k线周期,比如PERIOD_M1,PERIOD_M30,PERIOD_H1......
    var records = exchange.GetRecords(PERIOD_M15)
    var macd = TA.MACD(records, 12, 26, 9)
    // 观看日志可得知返回三个数组,分别对应DIF,DEA,MACD
    Log("DIF:", macd[0], "DEA:", macd[1], "MACD:", macd[2])
}
def main():
    r = exchange.GetRecords(PERIOD_M15)
    macd = TA.MACD(r, 12, 26, 9)
    Log("DIF:", macd[0], "DEA:", macd[1], "MACD:", macd[2])
void main() {
    auto r = exchange.GetRecords(PERIOD_M15);
    auto macd = TA.MACD(r, 12, 26, 9);
    Log("DIF:", macd[0], "DEA:", macd[1], "MACD:", macd[2]);
}

测试TA.MACD()函数:

优宽量化的TA指标库,优化了常用指标算法。 支持JavaScriptPythonC++语言策略的调用,开源TA库代码TA.MACD()函数的optInFastPeriodoptInSlowPeriodoptInSignalPeriod参数的默认值为:12269

{@fun/TA/TA.KDJ TA.KDJ}, {@fun/TA/TA.RSI TA.RSI}, {@fun/TA/TA.ATR TA.ATR}, {@fun/TA/TA.OBV TA.OBV}, {@fun/TA/TA.MA TA.MA}, {@fun/TA/TA.EMA TA.EMA}, {@fun/TA/TA.BOLL TA.BOLL}, {@fun/TA/TA.Alligator TA.Alligator}, {@fun/TA/TA.CMF TA.CMF}, {@fun/TA/TA.Highest TA.Highest}, {@fun/TA/TA.Lowest TA.Lowest}

TA.KDJ

TA.KDJ()函数用于计算随机指标

TA.KDJ()函数的返回值为二维数组,结构为:[K, D, J]。 array

TA.KDJ(inReal) TA.KDJ(inReal, period, kPeriod, dPeriod)

inReal参数用于指定K线数据。 inReal true {@struct/Record Record}结构数组、数值数组 period参数用于设置周期1。 period false number kPeriod参数用于设置周期2。 kPeriod false number dPeriod参数用于设置周期3。 dPeriod false number

function main(){
    var records = exchange.GetRecords(PERIOD_M15)
    var kdj = TA.KDJ(records, 9, 3, 3)
    Log("k:", kdj[0], "d:", kdj[1], "j:", kdj[2])
}
def main():
    r = exchange.GetRecords(PERIOD_M15)
    kdj = TA.KDJ(r, 9, 3, 3)
    Log("k:", kdj[0], "d:", kdj[1], "j:", kdj[2])
void main() {
    auto r = exchange.GetRecords();
    auto kdj = TA.KDJ(r, 9, 3, 3);
    Log("k:", kdj[0], "d:", kdj[1], "j:", kdj[2]);
}

测试TA.KDJ()函数:

TA.KDJ()函数的periodkPerioddPeriod参数的默认值为:933

{@fun/TA/TA.MACD TA.MACD}, {@fun/TA/TA.RSI TA.RSI}, {@fun/TA/TA.ATR TA.ATR}, {@fun/TA/TA.OBV TA.OBV}, {@fun/TA/TA.MA TA.MA}, {@fun/TA/TA.EMA TA.EMA}, {@fun/TA/TA.BOLL TA.BOLL}, {@fun/TA/TA.Alligator TA.Alligator}, {@fun/TA/TA.CMF TA.CMF}, {@fun/TA/TA.Highest TA.Highest}, {@fun/TA/TA.Lowest TA.Lowest}

TA.RSI

TA.RSI()函数用于计算强弱指标

TA.RSI()函数的返回值为:一维数组。 array

TA.RSI(inReal) TA.RSI(inReal, optInTimePeriod)

inReal参数用于指定K线数据。 inReal true {@struct/Record Record}结构数组、数值数组 optInTimePeriod参数用于设置周期。 optInTimePeriod false number

function main(){
    var records = exchange.GetRecords(PERIOD_M30)
    var rsi = TA.RSI(records, 14)
    Log(rsi)
}
def main():
    r = exchange.GetRecords(PERIOD_M30)
    rsi = TA.RSI(r, 14)
    Log(rsi)
void main() {
    auto r = exchange.GetRecords(PERIOD_M30);
    auto rsi = TA.RSI(r, 14);
    Log(rsi); 
}

测试TA.RSI()函数:

TA.RSI()函数的optInTimePeriod参数的默认值为:14

{@fun/TA/TA.MACD TA.MACD}, {@fun/TA/TA.KDJ TA.KDJ}, {@fun/TA/TA.ATR TA.ATR}, {@fun/TA/TA.OBV TA.OBV}, {@fun/TA/TA.MA TA.MA}, {@fun/TA/TA.EMA TA.EMA}, {@fun/TA/TA.BOLL TA.BOLL}, {@fun/TA/TA.Alligator TA.Alligator}, {@fun/TA/TA.CMF TA.CMF}, {@fun/TA/TA.Highest TA.Highest}, {@fun/TA/TA.Lowest TA.Lowest}

TA.ATR

TA.ATR()函数用于计算平均真实波幅指标

TA.ATR()函数的返回值为:一维数组。 array

TA.ATR(inPriceHLC) TA.ATR(inPriceHLC, optInTimePeriod)

inPriceHLC参数用于指定K线数据。 inPriceHLC true {@struct/Record Record}结构数组 optInTimePeriod参数用于设置周期。 optInTimePeriod false number

function main(){
    var records = exchange.GetRecords(PERIOD_M30)
    var atr = TA.ATR(records, 14)
    Log(atr)
}
def main():
    r = exchange.GetRecords(PERIOD_M30)
    atr = TA.ATR(r, 14)
    Log(atr)
void main() {
    auto r = exchange.GetRecords(PERIOD_M30);
    auto atr = TA.ATR(r, 14);
    Log(atr);
}

测试TA.ATR()函数:

TA.ATR()函数的optInTimePeriod参数的默认值为:14

{@fun/TA/TA.MACD TA.MACD}, {@fun/TA/TA.KDJ TA.KDJ}, {@fun/TA/TA.RSI TA.RSI}, {@fun/TA/TA.OBV TA.OBV}, {@fun/TA/TA.MA TA.MA}, {@fun/TA/TA.EMA TA.EMA}, {@fun/TA/TA.BOLL TA.BOLL}, {@fun/TA/TA.Alligator TA.Alligator}, {@fun/TA/TA.CMF TA.CMF}, {@fun/TA/TA.Highest TA.Highest}, {@fun/TA/TA.Lowest TA.Lowest}

TA.OBV

TA.OBV()函数用于计算能量潮指标

TA.OBV()函数的返回值为:一维数组。 array

TA.OBV(inReal) TA.OBV(inReal, inPriceV)

inReal参数用于指定K线数据。 inReal true {@struct/Record Record}结构数组、数值数组 inPriceV参数用于指定成交量数据。 inPriceV false {@struct/Record Record}结构数组

function main(){
    var records = exchange.GetRecords(PERIOD_M30)
    var obv = TA.OBV(records)
    Log(obv)
}
def main():
    r = exchange.GetRecords(PERIOD_M30)
    obv = TA.OBV(r)
    Log(obv)
void main() {
    auto r = exchange.GetRecords(PERIOD_M30);
    auto obv = TA.OBV(r);
    Log(obv);
}

测试TA.OBV()函数:

{@fun/TA/TA.MACD TA.MACD}, {@fun/TA/TA.KDJ TA.KDJ}, {@fun/TA/TA.RSI TA.RSI}, {@fun/TA/TA.ATR TA.ATR}, {@fun/TA/TA.MA TA.MA}, {@fun/TA/TA.EMA TA.EMA}, {@fun/TA/TA.BOLL TA.BOLL}, {@fun/TA/TA.Alligator TA.Alligator}, {@fun/TA/TA.CMF TA.CMF}, {@fun/TA/TA.Highest TA.Highest}, {@fun/TA/TA.Lowest TA.Lowest}

TA.MA

TA.MA()函数用于计算移动平均线指标

TA.MA()函数的返回值为:一维数组。 array

TA.MA(inReal) TA.MA(inReal, optInTimePeriod)

inReal参数用于指定K线数据。 inReal true {@struct/Record Record}结构数组、数值数组 optInTimePeriod参数用于设置周期。 optInTimePeriod false number

function main(){
    var records = exchange.GetRecords(PERIOD_M30)
    var ma = TA.MA(records, 14)
    Log(ma)
}
def main():
    r = exchange.GetRecords(PERIOD_M30)
    ma = TA.MA(r, 14)
    Log(ma)
void main() {
    auto r = exchange.GetRecords(PERIOD_M30);
    auto ma = TA.MA(r, 14);
    Log(ma);
}

测试TA.MA()函数:

TA.MA()函数的optInTimePeriod参数的默认值为:9

{@fun/TA/TA.MACD TA.MACD}, {@fun/TA/TA.KDJ TA.KDJ}, {@fun/TA/TA.RSI TA.RSI}, {@fun/TA/TA.ATR TA.ATR}, {@fun/TA/TA.OBV TA.OBV}, {@fun/TA/TA.EMA TA.EMA}, {@fun/TA/TA.BOLL TA.BOLL}, {@fun/TA/TA.Alligator TA.Alligator}, {@fun/TA/TA.CMF TA.CMF}, {@fun/TA/TA.Highest TA.Highest}, {@fun/TA/TA.Lowest TA.Lowest}

TA.EMA

TA.EMA()函数用于计算指数平均数指标

TA.EMA()函数的返回值为:一维数组。 array

TA.EMA(inReal) TA.EMA(inReal, optInTimePeriod)

inReal参数用于指定K线数据。 inReal true {@struct/Record Record}结构数组、数值数组 optInTimePeriod参数用于设置周期。 optInTimePeriod false number

function main(){
    var records = exchange.GetRecords()
    // 判断K线bar数量是否满足指标计算周期
    if (records && records.length > 9) {
        var ema = TA.EMA(records, 9)          
        Log(ema)
    }
}
def main():
    r = exchange.GetRecords()
    if r and len(r) > 9:
        ema = TA.EMA(r, 9)
        Log(ema)
void main() {
    auto r = exchange.GetRecords();
    if(r.Valid && r.size() > 9) {
        auto ema = TA.EMA(r, 9);
        Log(ema);
    }
}

测试TA.EMA()函数:

TA.EMA()函数的optInTimePeriod参数的默认值为:9

{@fun/TA/TA.MACD TA.MACD}, {@fun/TA/TA.KDJ TA.KDJ}, {@fun/TA/TA.RSI TA.RSI}, {@fun/TA/TA.ATR TA.ATR}, {@fun/TA/TA.OBV TA.OBV}, {@fun/TA/TA.MA TA.MA}, {@fun/TA/TA.BOLL TA.BOLL}, {@fun/TA/TA.Alligator TA.Alligator}, {@fun/TA/TA.CMF TA.CMF}, {@fun/TA/TA.Highest TA.Highest}, {@fun/TA/TA.Lowest TA.Lowest}

TA.BOLL

TA.BOLL()函数用于计算布林带指标

TA.BOLL()函数的返回值为二维数组,结构为:[upLine, midLine, downLine]。 array

TA.BOLL(inReal) TA.BOLL(inReal, period, multiplier)

inReal参数用于指定K线数据。 inReal true {@struct/Record Record}结构数组、数值数组 period参数用于设置周期。 period false number multiplier参数用于设置乘数。 multiplier false number

function main() {
    var records = exchange.GetRecords()
    if(records && records.length > 20) {
        var boll = TA.BOLL(records, 20, 2)
        var upLine = boll[0]
        var midLine = boll[1]
        var downLine = boll[2]
        Log(upLine)
        Log(midLine)
        Log(downLine)
    }
}
def main():
    r = exchange.GetRecords()
    if r and len(r) > 20:
        boll = TA.BOLL(r, 20, 2)
        upLine = boll[0]
        midLine = boll[1]
        downLine = boll[2]
        Log(upLine)
        Log(midLine)
        Log(downLine)
void main() {
    auto r = exchange.GetRecords();
    if(r.Valid && r.size() > 20) {
        auto boll = TA.BOLL(r, 20, 2);
        auto upLine = boll[0];
        auto midLine = boll[1];
        auto downLine = boll[2];
        Log(upLine);
        Log(midLine);
        Log(downLine);
    }
}

测试TA.BOLL()函数:

TA.BOLL()函数的periodmultiplier参数的默认值为:202

{@fun/TA/TA.MACD TA.MACD}, {@fun/TA/TA.KDJ TA.KDJ}, {@fun/TA/TA.RSI TA.RSI}, {@fun/TA/TA.ATR TA.ATR}, {@fun/TA/TA.OBV TA.OBV}, {@fun/TA/TA.MA TA.MA}, {@fun/TA/TA.EMA TA.EMA}, {@fun/TA/TA.Alligator TA.Alligator}, {@fun/TA/TA.CMF TA.CMF}, {@fun/TA/TA.Highest TA.Highest}, {@fun/TA/TA.Lowest TA.Lowest}

TA.Alligator

TA.Alligator()函数用于计算鳄鱼线指标

TA.Alligator()函数的返回值为二维数组,结构为:[jawLine, teethLine, lipsLine]。 array

TA.Alligator(inReal) TA.Alligator(inReal, jawLength, teethLength, lipsLength)

inReal参数用于指定K线数据。 inReal true {@struct/Record Record}结构数组、数值数组 jawLength参数用于设置下颚周期。 jawLength false number teethLength参数用于设置牙齿周期。 teethLength false number lipsLength参数用于设置上唇周期。 lipsLength false number

function main(){
    var records = exchange.GetRecords()
    var alligator = TA.Alligator(records)
    Log("jawLine:", alligator[0])
    Log("teethLine:", alligator[1])
    Log("lipsLine:", alligator[2])
}
def main():
    records = exchange.GetRecords()
    alligator = TA.Alligator(records)
    Log("jawLine:", alligator[0])
    Log("teethLine:", alligator[1])
    Log("lipsLine:", alligator[2])
void main() {
    auto records = exchange.GetRecords();
    auto alligator = TA.Alligator(records);
    Log("jawLine:", alligator[0]);
    Log("teethLine:", alligator[1]);
    Log("lipsLine:", alligator[2]);
}

测试TA.Alligator()函数:

TA.Alligator()函数的jawLengthteethLengthlipsLength参数的默认值为:1385

{@fun/TA/TA.MACD TA.MACD}, {@fun/TA/TA.KDJ TA.KDJ}, {@fun/TA/TA.RSI TA.RSI}, {@fun/TA/TA.ATR TA.ATR}, {@fun/TA/TA.OBV TA.OBV}, {@fun/TA/TA.MA TA.MA}, {@fun/TA/TA.EMA TA.EMA}, {@fun/TA/TA.BOLL TA.BOLL}, {@fun/TA/TA.CMF TA.CMF}, {@fun/TA/TA.Highest TA.Highest}, {@fun/TA/TA.Lowest TA.Lowest}

TA.CMF

TA.CMF()函数用于计算蔡金货币流量指标

TA.CMF()函数的返回值为:一维数组。 array

TA.CMF(inReal) TA.CMF(inReal, inPriceV)

inReal参数用于指定K线数据。 inReal true {@struct/Record Record}结构数组、数值数组 inPriceV参数用于指定成交量数据。 inPriceV false {@struct/Record Record}结构数组

function main() {
    var records = exchange.GetRecords()
    var cmf = TA.CMF(records)
    Log(cmf)
}
def main():
    records = exchange.GetRecords()
    cmf = TA.CMF(records)
    Log(cmf)
void main() {
    auto records = exchange.GetRecords();
    auto cmf = TA.CMF(records);
    Log(cmf);
}

测试TA.CMF()函数:

{@fun/TA/TA.MACD TA.MACD}, {@fun/TA/TA.KDJ TA.KDJ}, {@fun/TA/TA.RSI TA.RSI}, {@fun/TA/TA.ATR TA.ATR}, {@fun/TA/TA.OBV TA.OBV}, {@fun/TA/TA.MA TA.MA}, {@fun/TA/TA.EMA TA.EMA}, {@fun/TA/TA.BOLL TA.BOLL}, {@fun/TA/TA.Alligator TA.Alligator}, {@fun/TA/TA.Highest TA.Highest}, {@fun/TA/TA.Lowest TA.Lowest}

TA.Highest

TA.Highest()函数用于计算周期最高价

TA.Highest()函数返回最近一定周期内的某个属性的最大值,不包含当前Bar。 number

TA.Highest(inReal) TA.Highest(inReal, period, attr)

inReal参数用于指定K线数据。 inReal true {@struct/Record Record}结构数组、数值数组 period参数用于设置周期。 period false number attr参数用于设置属性,可选:OpenCloseLowHighVolumeOpenInterest。 attr false string

function main() {
    var records = exchange.GetRecords()
    var highestForOpen = TA.Highest(records, 10, "Open")
    Log(highestForOpen)
}
def main():
    records = exchange.GetRecords()
    highestForOpen = TA.Highest(records, 10, "Open")
    Log(highestForOpen)
void main() {
    auto records = exchange.GetRecords();
    auto highestForOpen = TA.Highest(records.Open(), 10);
    Log(highestForOpen);
}

测试TA.Highest()函数:

例如调用TA.Highest(records, 30, "High")函数,如果周期参数period设置为0, 指计算inReal参数传入的K线数据的所有Bar;如果属性参数attr不指定,则视为inReal参数传入的K线数据为普通数组。

{@fun/TA/TA.MACD TA.MACD}, {@fun/TA/TA.KDJ TA.KDJ}, {@fun/TA/TA.RSI TA.RSI}, {@fun/TA/TA.ATR TA.ATR}, {@fun/TA/TA.OBV TA.OBV}, {@fun/TA/TA.MA TA.MA}, {@fun/TA/TA.EMA TA.EMA}, {@fun/TA/TA.BOLL TA.BOLL}, {@fun/TA/TA.Alligator TA.Alligator}, {@fun/TA/TA.CMF TA.CMF}, {@fun/TA/TA.Lowest TA.Lowest}

TA.Lowest

TA.Lowest()函数用于计算周期最低价

TA.Lowest()函数返回最近一定周期内的某个属性的最小值,不包含当前Bar。 number

TA.Lowest(inReal) TA.Lowest(inReal, period, attr)

inReal参数用于指定K线数据。 inReal true {@struct/Record Record}结构数组、数值数组 period参数用于设置周期。 period false number attr参数用于设置属性,可选:OpenCloseLowHighVolumeOpenInterest。 attr false string

function main() {
    var records = exchange.GetRecords()
    var lowestForOpen = TA.Lowest(records, 10, "Open")
    Log(lowestForOpen)
}
def main():
    records = exchange.GetRecords()
    lowestForOpen = TA.Lowest(records, 10, "Open")
    Log(lowestForOpen)
void main() {
    auto records = exchange.GetRecords();
    auto lowestForOpen = TA.Lowest(records.Open(), 10);
    Log(lowestForOpen);
}

测试TA.Lowest()函数:

例如调用TA.Lowest(records, 30, "Low")函数,如果周期参数period设置为0, 指计算inReal参数传入的K线数据的所有Bar;如果属性参数attr不指定,则视为inReal参数传入的K线数据为普通数组。 C++策略中TA.Highest()TA.Lowest()函数的使用需注意,Highest()Lowest()函数各自只有2个参数, 并且第一个参数传入的不是auto r = exchange.GetRecords()函数调用时获取的K线数据r。 需要调用r的方法,传入具体属性数据。例如传入r.Close()收盘价数据。 CloseHighLowOpenVolume如同r.Close()调用方式。

C++语言策略的测试范例:

void main() { 
    Records r;
    r.Valid = true;
    for (auto i = 0; i < 10; i++) {
        Record ele;
        ele.Time = i * 100000;
        ele.High = i * 10000;
        ele.Low = i * 1000;
        ele.Close = i * 100;
        ele.Open = i * 10;
        ele.Volume = i * 1;
        r.push_back(ele);
    }            

    for(int j = 0; j < r.size(); j++){
        Log(r[j]);
    }            

    // 注意:第一个参数传入的不是r,需要调用r.Close()
    auto highest = TA.Highest(r.Close(), 8);   
    Log(highest);                     
}

{@fun/TA/TA.MACD TA.MACD}, {@fun/TA/TA.KDJ TA.KDJ}, {@fun/TA/TA.RSI TA.RSI}, {@fun/TA/TA.ATR TA.ATR}, {@fun/TA/TA.OBV TA.OBV}, {@fun/TA/TA.MA TA.MA}, {@fun/TA/TA.EMA TA.EMA}, {@fun/TA/TA.BOLL TA.BOLL}, {@fun/TA/TA.Alligator TA.Alligator}, {@fun/TA/TA.CMF TA.CMF}, {@fun/TA/TA.Highest TA.Highest}

TA.SMA

TA.SMA()函数用于计算简单移动平均指标

TA.SMA()函数的返回值为:一维数组。 array

TA.SMA(inReal) TA.SMA(inReal, optInTimePeriod)

inReal参数用于指定K线数据。 inReal true {@struct/Record Record}结构数组、数值数组 optInTimePeriod参数用于设置周期。 optInTimePeriod false number

function main(){
    var records = exchange.GetRecords(PERIOD_M30)
    var sma = TA.SMA(records, 14)
    Log(sma)
}
def main():
    r = exchange.GetRecords(PERIOD_M30)
    sma = TA.SMA(r, 14)
    Log(sma)
void main() {
    auto r = exchange.GetRecords(PERIOD_M30);
    auto sma = TA.SMA(r, 14);
    Log(sma);
}

测试TA.SMA()函数:

TA.SMA()函数的optInTimePeriod参数的默认值为:9

{@fun/TA/TA.MACD TA.MACD}, {@fun/TA/TA.KDJ TA.KDJ}, {@fun/TA/TA.RSI TA.RSI}, {@fun/TA/TA.ATR TA.ATR}, {@fun/TA/TA.OBV TA.OBV}, {@fun/TA/TA.MA TA.MA}, {@fun/TA/TA.EMA TA.EMA}, {@fun/TA/TA.BOLL TA.BOLL}, {@fun/TA/TA.Alligator TA.Alligator}, {@fun/TA/TA.CMF TA.CMF}, {@fun/TA/TA.Highest TA.Highest}, {@fun/TA/TA.Lowest TA.Lowest}

Threads Talib