TA
TA.MACD
The TA.MACD() function is used to calculate the Moving Average Convergence Divergence indicator.
TA.MACD(inReal)
TA.MACD(inReal, optInFastPeriod, optInSlowPeriod, optInSignalPeriod)Examples
javascript
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])
}
python
def main():
r = exchange.GetRecords(PERIOD_M15)
macd = TA.MACD(r, 12, 26, 9)
Log("DIF:", macd[0], "DEA:", macd[1], "MACD:", macd[2])
c++
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]);
}Returns
| Type | Description |
array | The |
Arguments
| Name | Type | Required | Description |
inReal |
| Yes | The |
optInFastPeriod | number | No | The |
optInSlowPeriod | number | No | The |
optInSignalPeriod | number | No | The |
See Also
Remarks
FMZ Quant's TA indicator library optimizes common technical indicator algorithms. It supports strategy calls in JavaScript, Python, and C++ languages, open source TA library code.
The default values for the optInFastPeriod, optInSlowPeriod, and optInSignalPeriod parameters of the TA.MACD() function are: 12, 26, and 9 respectively.
TA.KDJ
The TA.KDJ() function is used to calculate the Stochastic Oscillator.
TA.KDJ(inReal)
TA.KDJ(inReal, period, kPeriod, dPeriod)Examples
javascript
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])
}
python
def main():
r = exchange.GetRecords(PERIOD_M15)
kdj = TA.KDJ(r, 9, 3, 3)
Log("k:", kdj[0], "d:", kdj[1], "j:", kdj[2])
c++
void main() {
auto r = exchange.GetRecords();
auto kdj = TA.KDJ(r, 9, 3, 3);
Log("k:", kdj[0], "d:", kdj[1], "j:", kdj[2]);
}Returns
| Type | Description |
array | The |
Arguments
| Name | Type | Required | Description |
inReal |
| Yes | The |
period | number | No | The |
kPeriod | number | No | The |
dPeriod | number | No | The |
See Also
Remarks
The default values for the period, kPeriod, and dPeriod parameters of the TA.KDJ() function are: 9, 3, and 3 respectively.
TA.RSI
The TA.RSI() function is used to calculate the Relative Strength Index.
TA.RSI(inReal)
TA.RSI(inReal, optInTimePeriod)Examples
javascript
function main(){
var records = exchange.GetRecords(PERIOD_M30)
var rsi = TA.RSI(records, 14)
Log(rsi)
}
python
def main():
r = exchange.GetRecords(PERIOD_M30)
rsi = TA.RSI(r, 14)
Log(rsi)
c++
void main() {
auto r = exchange.GetRecords(PERIOD_M30);
auto rsi = TA.RSI(r, 14);
Log(rsi);
}Returns
| Type | Description |
array | The return value of the |
Arguments
| Name | Type | Required | Description |
inReal |
| Yes | The |
optInTimePeriod | number | No | The |
See Also
Remarks
The default value of the optInTimePeriod parameter for the TA.RSI() function is: 14.
TA.ATR
The TA.ATR() function is used to calculate the Average True Range indicator.
TA.ATR(inPriceHLC)
TA.ATR(inPriceHLC, optInTimePeriod)Examples
javascript
function main(){
var records = exchange.GetRecords(PERIOD_M30)
var atr = TA.ATR(records, 14)
Log(atr)
}
python
def main():
r = exchange.GetRecords(PERIOD_M30)
atr = TA.ATR(r, 14)
Log(atr)
c++
void main() {
auto r = exchange.GetRecords(PERIOD_M30);
auto atr = TA.ATR(r, 14);
Log(atr);
}Returns
| Type | Description |
array | The |
Arguments
| Name | Type | Required | Description |
inPriceHLC |
| Yes | The |
optInTimePeriod | number | No | The |
See Also
Remarks
The default value of the optInTimePeriod parameter for the TA.ATR() function is: 14.
TA.OBV
The TA.OBV() function is used to calculate the On-Balance Volume indicator.
TA.OBV(inReal)
TA.OBV(inReal, inPriceV)Examples
javascript
function main(){
var records = exchange.GetRecords(PERIOD_M30)
var obv = TA.OBV(records)
Log(obv)
}
python
def main():
r = exchange.GetRecords(PERIOD_M30)
obv = TA.OBV(r)
Log(obv)
c++
void main() {
auto r = exchange.GetRecords(PERIOD_M30);
auto obv = TA.OBV(r);
Log(obv);
}Returns
| Type | Description |
array | The |
Arguments
| Name | Type | Required | Description |
inReal |
| Yes | The |
inPriceV |
| No | The |
See Also
TA.MA
The TA.MA() function is used to calculate the Moving Average indicator.
TA.MA(inReal)
TA.MA(inReal, optInTimePeriod)Examples
javascript
function main(){
var records = exchange.GetRecords(PERIOD_M30)
var ma = TA.MA(records, 14)
Log(ma)
}
python
def main():
r = exchange.GetRecords(PERIOD_M30)
ma = TA.MA(r, 14)
Log(ma)
c++
void main() {
auto r = exchange.GetRecords(PERIOD_M30);
auto ma = TA.MA(r, 14);
Log(ma);
}Returns
| Type | Description |
array | The |
Arguments
| Name | Type | Required | Description |
inReal |
| Yes | The |
optInTimePeriod | number | No | The |
See Also
Remarks
The default value of the optInTimePeriod parameter for the TA.MA() function is: 9.
TA.EMA
The TA.EMA() function is used to calculate the Exponential Moving Average indicator.
TA.EMA(inReal)
TA.EMA(inReal, optInTimePeriod)Examples
javascript
function main(){
var records = exchange.GetRecords()
// 判断K线bar数量是否满足指标计算周期
if (records && records.length > 9) {
var ema = TA.EMA(records, 9)
Log(ema)
}
}
python
def main():
r = exchange.GetRecords()
if r and len(r) > 9:
ema = TA.EMA(r, 9)
Log(ema)
c++
void main() {
auto r = exchange.GetRecords();
if(r.Valid && r.size() > 9) {
auto ema = TA.EMA(r, 9);
Log(ema);
}
}Returns
| Type | Description |
array | The return value of the |
Arguments
| Name | Type | Required | Description |
inReal |
| Yes | The |
optInTimePeriod | number | No | The |
See Also
Remarks
The default value of the optInTimePeriod parameter for the TA.EMA() function is: 9.
TA.BOLL
The TA.BOLL() function is used to calculate the Bollinger Bands indicator.
TA.BOLL(inReal)
TA.BOLL(inReal, period, multiplier)Examples
javascript
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)
}
}
python
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)
c++
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);
}
}Returns
| Type | Description |
array | The |
Arguments
| Name | Type | Required | Description |
inReal |
| Yes | The |
period | number | No | The |
multiplier | number | No | The |
See Also
Remarks
The default values for the period and multiplier parameters of the TA.BOLL() function are: 20 and 2 respectively.
TA.Alligator
The TA.Alligator() function is used to calculate the Alligator Indicator.
TA.Alligator(inReal)
TA.Alligator(inReal, jawLength, teethLength, lipsLength)Examples
javascript
function main(){
var records = exchange.GetRecords()
var alligator = TA.Alligator(records)
Log("jawLine:", alligator[0])
Log("teethLine:", alligator[1])
Log("lipsLine:", alligator[2])
}
python
def main():
records = exchange.GetRecords()
alligator = TA.Alligator(records)
Log("jawLine:", alligator[0])
Log("teethLine:", alligator[1])
Log("lipsLine:", alligator[2])
c++
void main() {
auto records = exchange.GetRecords();
auto alligator = TA.Alligator(records);
Log("jawLine:", alligator[0]);
Log("teethLine:", alligator[1]);
Log("lipsLine:", alligator[2]);
}Returns
| Type | Description |
array | The |
Arguments
| Name | Type | Required | Description |
inReal |
| Yes | The |
jawLength | number | No | The |
teethLength | number | No | The |
lipsLength | number | No | The |
See Also
Remarks
The default values for the jawLength, teethLength, and lipsLength parameters of the TA.Alligator() function are: 13, 8, and 5 respectively.
TA.CMF
The TA.CMF() function is used to calculate the Chaikin Money Flow indicator.
TA.CMF(inReal)
TA.CMF(inReal, inPriceV)Examples
javascript
function main() {
var records = exchange.GetRecords()
var cmf = TA.CMF(records)
Log(cmf)
}
python
def main():
records = exchange.GetRecords()
cmf = TA.CMF(records)
Log(cmf)
c++
void main() {
auto records = exchange.GetRecords();
auto cmf = TA.CMF(records);
Log(cmf);
}Returns
| Type | Description |
array | The |
Arguments
| Name | Type | Required | Description |
inReal |
| Yes | The |
inPriceV |
| No | The |
See Also
TA.Highest
The TA.Highest() function is used to calculate the highest price within a specified period.
TA.Highest(inReal)
TA.Highest(inReal, period, attr)Examples
javascript
function main() {
var records = exchange.GetRecords()
var highestForOpen = TA.Highest(records, 10, "Open")
Log(highestForOpen)
}
python
def main():
records = exchange.GetRecords()
highestForOpen = TA.Highest(records, 10, "Open")
Log(highestForOpen)
c++
void main() {
auto records = exchange.GetRecords();
auto highestForOpen = TA.Highest(records.Open(), 10);
Log(highestForOpen);
}Returns
| Type | Description |
number | The |
Arguments
| Name | Type | Required | Description |
inReal |
| Yes | The |
period | number | No | The |
attr | string | No | The |
See Also
Remarks
For example, when calling TA.Highest(records, 30, "High") function: If the period parameter period is set to 0, it calculates the highest value of all Bars in the K-line data passed by the inReal parameter; If the attribute parameter attr is not specified, the data passed by the inReal parameter is treated as a regular numeric array.
TA.Lowest
The TA.Lowest() function is used to calculate the period lowest price.
TA.Lowest(inReal)
TA.Lowest(inReal, period, attr)Examples
javascript
function main() {
var records = exchange.GetRecords()
var lowestForOpen = TA.Lowest(records, 10, "Open")
Log(lowestForOpen)
}
python
def main():
records = exchange.GetRecords()
lowestForOpen = TA.Lowest(records, 10, "Open")
Log(lowestForOpen)
c++
void main() {
auto records = exchange.GetRecords();
auto lowestForOpen = TA.Lowest(records.Open(), 10);
Log(lowestForOpen);
}Returns
| Type | Description |
number | The |
Arguments
| Name | Type | Required | Description |
inReal |
| Yes | The |
period | number | No | The |
attr | string | No | The |
See Also
Remarks
For example, when calling TA.Lowest(records, 30, "Low") function, if the period parameter period is set to 0, it calculates all Bars of the K-line data passed in the inReal parameter; if the attribute parameter attr is not specified, the K-line data passed in the inReal parameter is treated as a regular array.
When using TA.Highest() and TA.Lowest() functions in C++ strategies, note that Highest() and Lowest() functions each have only 2 parameters, and the first parameter is not the K-line data r obtained by calling auto r = exchange.GetRecords() function. You need to call the method of r and pass in specific attribute data. For example, pass in r.Close() closing price data. Close, High, Low, Open, Volume all use the calling method like r.Close().
C++ language strategy test example:
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]);
}
// Note: The first parameter is not r, need to call r.Close()
auto highest = TA.Highest(r.Close(), 8);
Log(highest);
}
TA.SMA
The TA.SMA() function is used to calculate the Simple Moving Average indicator.
TA.SMA(inReal)
TA.SMA(inReal, optInTimePeriod)Examples
javascript
function main(){
var records = exchange.GetRecords(PERIOD_M30)
var sma = TA.SMA(records, 14)
Log(sma)
}
python
def main():
r = exchange.GetRecords(PERIOD_M30)
sma = TA.SMA(r, 14)
Log(sma)
c++
void main() {
auto r = exchange.GetRecords(PERIOD_M30);
auto sma = TA.SMA(r, 14);
Log(sma);
}Returns
| Type | Description |
array | The return value of the |
Arguments
| Name | Type | Required | Description |
inReal |
| Yes | The |
optInTimePeriod | number | No | The |
See Also
Remarks
The default value of the optInTimePeriod parameter for the TA.SMA() function is: 9.