TVJS Scripts is a time-series engine, similar to the tradingview's PINE script. Syntax is based on javascript, in the future it will be possible to make custom code constructions with regular expressions (extend the language).
At this moment it's an experimental feature, breaking changes are very likely.
Timeseries (TS) is a regular js Array with __id__
and __len__
properties (id & buffer length). New elements are added at the beginning of the TS:
-> [2, 2, 2, 2, 2, 2]
The array is limited by __len__
(applied each step).
Std-lib is a collection of built-in functions:
atr()
bb()
cci()
cmo()
dmi()
ema()
...
Calculation object. Overlay returns the script object from calc()
:
calc() {
return {
props: {
start: { def: 10, text: 'Start Length' },
number: { def: 5, text: 'Number of Lines' },
step: { def: 10, text: 'Length Step' }
},
conf: {
renderer: 'Splines'
},
init: `
consol.log('init script')
`,
update: `
let res = []
for (var i = 0; i < number; i++) {
let l = start + i * step
var.push(ema(close, l)[0])
}
return res
`
}
}
init()
is called once, before any updates
update()
is executed at each step. Should return a new data point (or set this[0]
). Imagine that output of the function is pushed to your overlay's data
array.
If renderer
is specified, the lib will use another overlay for rendering the script (it should be added to the overlays
prop ofc).
If you need to create a persistent variable, just make a new property in this
:
{
init: `
this.state = 0
`,
update: `
this.state++
`
}
Both engines are very similar, except TVJS has less syntax sugar (this improvement is planned). For example:
// PINE:
hl2 = (high + low) / 2
// TVJS:
let hl2 = ts((high[0] + low[0]) / 2)
Sometimes you need to build a new TS with the ts(x)
function. This function takes x
and records it every step. Then you can use it as a source in the build-in functions:
let hl2 = ts((high[0] + low[0]) / 2)
return ema(hl2, 100)[0]
Currently you can get issues with the following code constructions:
// Avoid complex indices (brackets inside brackets):
ts1[[i][0] + arr[n]]
If you want to help the development you can try to reimplement your PINE scripts (see Squeeze Momentum as an example). Testing is crucial.
Or you could boost the std-lib (see TODOs):
https://github.com/tvjsx/trading-vue-js/blob/master/src/helpers/script_std.js