TA
TA.MACD
The TA.MACD() function is used to calculate the Moving Average Convergence Divergence (MACD) indicator.
TA.MACD(inReal)
TA.MACD(inReal, optInFastPeriod, optInSlowPeriod, optInSignalPeriod)Examples
javascript
function main(){
// You can fill in different K-line periods, such as PERIOD_M1, PERIOD_M30, PERIOD_H1......
var records = exchange.GetRecords(PERIOD_M15)
var macd = TA.MACD(records, 12, 26, 9)
// Checking the logs shows that three arrays are returned, corresponding to DIF, DEA, and MACD respectively
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])
rust
fn main() {
// You can fill in different K-line periods, such as PERIOD_M1, PERIOD_M30, PERIOD_H1......
let records = exchange.GetRecords(None, PERIOD_M15, None).unwrap();
let macd = TA.MACD(&records, 12, 26, 9);
// Checking the logs shows that three arrays are returned, corresponding to DIF, DEA, and MACD respectively
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 return value of 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 the algorithms of commonly used indicators and supports calls from JavaScript, Python, and C++ strategies. For details, see the open-source TA library code.
The default values of 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 (KDJ).
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])
rust
fn main() {
let records = exchange.GetRecords(None, PERIOD_M15, None).unwrap();
let kdj = TA.KDJ(&records, 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 return value of 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 of 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 (RSI).
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)
rust
fn main() {
let records = exchange.GetRecords(None, PERIOD_M30, None).unwrap();
let rsi = TA.RSI(&records, 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 of the TA.RSI() function is: 14.
TA.ATR
The TA.ATR() function is used to calculate the Average True Range indicator (ATR).
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)
rust
fn main() {
let records = exchange.GetRecords(None, PERIOD_M30, None).unwrap();
let atr = TA.ATR(&records, 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 return value of the |
Arguments
| Name | Type | Required | Description |
inPriceHLC |
| Yes | The |
optInTimePeriod | number | No | The |
See Also
Remarks
The default value of the optInTimePeriod parameter of the TA.ATR() function is: 14.
TA.OBV
TA.OBV() function is used to calculate the On-Balance Volume (OBV).
TA.OBV(inReal)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)
rust
fn main() {
let records = exchange.GetRecords(None, PERIOD_M30, None).unwrap();
let obv = TA.OBV(&records);
Log!(obv);
}
c++
void main() {
auto r = exchange.GetRecords(PERIOD_M30);
auto obv = TA.OBV(r);
Log(obv);
}Returns
| Type | Description |
array | The return value of the |
Arguments
| Name | Type | Required | Description |
inReal |
| Yes | The |
See Also
TA.MA
The TA.MA() function is used to calculate the Moving Average indicator (Moving Average).
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)
rust
fn main() {
let records = exchange.GetRecords(None, PERIOD_M30, None).unwrap();
let ma = TA.MA(&records, 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 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 of the TA.MA() function is: 9.
TA.EMA
The TA.EMA() function is used to calculate the Exponential Moving Average (EMA) indicator.
TA.EMA(inReal)
TA.EMA(inReal, optInTimePeriod)Examples
javascript
function main(){
var records = exchange.GetRecords()
// Check whether the number of K-line Bars meets the period required for indicator calculation
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)
rust
fn main() {
let records = exchange.GetRecords(None, None, None).unwrap();
// Check whether the number of K-line Bars meets the period required for indicator calculation
if records.len() > 9 {
let ema = TA.EMA(&records, 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 of 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)
rust
fn main() {
let records = exchange.GetRecords(None, None, None).unwrap();
if records.len() > 20 {
let boll = TA.BOLL(&records, 20, 2.0);
let [upLine, midLine, downLine] = boll;
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 return value of the |
Arguments
| Name | Type | Required | Description |
inReal |
| Yes | The |
period | number | No | The |
multiplier | number | No | The |
See Also
Remarks
The default values of the period and multiplier parameters of the TA.BOLL() function are 20 and 2, respectively.
TA.Alligator
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])
rust
fn main() {
let records = exchange.GetRecords(None, None, None).unwrap();
let alligator = TA.Alligator(&records, None, None, None);
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 return value of 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 of 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 (CMF) indicator.
TA.CMF(inReal)
TA.CMF(inReal, periods)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)
rust
fn main() {
let records = exchange.GetRecords(None, None, None).unwrap();
let cmf = TA.CMF(&records, None);
Log!(cmf);
}
c++
void main() {
auto records = exchange.GetRecords();
auto cmf = TA.CMF(records);
Log(cmf);
}Returns
| Type | Description |
array | The return value of the |
Arguments
| Name | Type | Required | Description |
inReal |
| Yes | The |
periods | number | No | The |
See Also
TA.Highest
The TA.Highest() function is used to calculate the highest price within a 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)
rust
fn main() {
let records = exchange.GetRecords(None, None, None).unwrap();
// Rust's TA.Highest has no attribute name parameter; first extract the opening price numeric sequence, then calculate (not including the current Bar)
let opens: Vec<f64> = records.iter().map(|r| r.Open).collect();
let highestForOpen = TA.Highest(&opens, 10);
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 the TA.Highest(records, 30, "High") function, if the period parameter period is set to 0, it means calculating all Bar in the K-line data passed in by the inReal parameter; if the attribute parameter attr is not specified, the data passed in by the inReal parameter is treated as an ordinary array.
TA.Lowest
The TA.Lowest() function is used to calculate the lowest price over a period.
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)
rust
fn main() {
let records = exchange.GetRecords(None, None, None).unwrap();
// Rust's TA.Lowest has no attribute-name parameter; first extract the opening price numeric sequence, then calculate (not including the current Bar)
let opens: Vec<f64> = records.iter().map(|r| r.Open).collect();
let lowestForOpen = TA.Lowest(&opens, 10);
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 the TA.Lowest(records, 30, "Low") function: if the period parameter period is set to 0, it means calculating over all Bar of the K-line data passed in via the inReal parameter; if the attribute parameter attr is not specified, the K-line data passed in via the inReal parameter is treated as an ordinary array.
When using the TA.Highest() and TA.Lowest() functions in a C++ strategy, note the following: the Highest() and Lowest() functions each have only 2 parameters, and the first parameter passed in is not the K-line data r obtained from calling auto r = exchange.GetRecords(), but rather requires calling a method of r to pass in specific attribute data. For example, pass in r.Close() for closing price data. The calling method for Close, High, Low, Open, Volume is the same as r.Close().
Test example for a C++ language strategy:
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 passed in is not r; you 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 (SMA) 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)
rust
fn main() {
let records = exchange.GetRecords(None, PERIOD_M30, None).unwrap();
let sma = TA.SMA(&records, 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 of the TA.SMA() function is: 9.