Built-in Libraries
Strategies can use the platform's built-in TA and talib indicator libraries and each language's JSON support without importing anything. Availability by language:
| Library | JavaScript | Python | Rust |
|---|---|---|---|
TA indicators | ✓ | ✓ | ✓ |
talib indicators | ✓ | ✓ (needs TA-Lib and numpy on the docker's machine) | ✗ |
| JSON | the language's built-in JSON | the standard json module | JSONParse()/JsonValue |
For the full list of functions and their arguments see TA and Talib in the reference.
TA indicator library
The platform's TA library optimizes the common indicator algorithms (open-source TA library code). Where there are not enough K-lines to compute an indicator, invalid values are returned at those positions.
javascript
function main(){
var records = exchange.GetRecords()
if (!records) {
return
}
var macd = TA.MACD(records)
var atr = TA.ATR(records, 14)
// print the last set of indicator values
Log(macd[0][records.length-1], macd[1][records.length-1], macd[2][records.length-1])
Log(atr[atr.length-1])
}
rust
fn main() {
let r = exchange.GetRecords(None, None, None).unwrap();
let macd = TA.MACD(&r, None, None, None);
let atr = TA.ATR(&r, 14);
Log!(macd[0][r.len() - 1], macd[1][r.len() - 1], macd[2][r.len() - 1]);
Log!(atr[atr.len() - 1]);
}
talib indicator library
javascript
function main() {
var records = exchange.GetRecords()
if (!records) {
return
}
var cci = talib.CCI(records, 14)
Log(cci)
}
python
# needs TA-Lib and numpy on the docker's machine, otherwise talib raises an error
def main():
records = exchange.GetRecords()
if not records:
return
cci = talib.CCI(records.High, records.Low, records.Close, 14)
Log(cci)
JavaScript: loading third-party libraries dynamically
Other third-party JavaScript libraries can be downloaded at run time and loaded with eval:
javascript
function main() {
// via. https://cdnjs.com/libraries
eval(HttpQuery("https://cdnjs.cloudflare.com/ajax/libs/mathjs/13.2.0/math.min.js"))
Log(math.round(math.e, 3)) // 2.718
Log(math.atan2(3, -3) / math.pi) // 0.75
Log(math.log(10000, 10)) // 4
Log(math.sqrt(-4)) // {"mathjs":"Complex","re":0,"im":2}
}