Appearance
Runtime Environment
dxScript executes with ECMAScript 2024 (ES15) support.
Available JS Features
Standard JavaScript features are fully supported:
javascript
// Arrow functions
const double = x => x * 2;
// Destructuring
const {min, max} = Math;
// Template literals
const msg = `Price: ${close}`;
// Array methods
const values = [1, 2, 3].map(x => x * 2);
// Spread operator
const combined = [...arr1, ...arr2];
// Optional chaining
const value = obj?.nested?.prop;
// Nullish coalescing
const fallback = value ?? defaultValue;Not Available
dxScript runs in a sandboxed environment without access to:
- Timers (
setTimeout,setInterval) - Network (
fetch,XMLHttpRequest) - Module system (
import,require,module,exports) - Node.js APIs (
process,Buffer,__dirname,__filename) - Browser globals (
window,self,document)
Example
javascript
// INIT
const threshold = 0.5;
const labels = ["Low", "Medium", "High"];
function classify(value) {
if (value < threshold) return labels[0];
if (value < threshold * 2) return labels[1];
return labels[2];
}
// TICK
function onTick() {
const sma = ta.sma(close, 20);
const distance = Math.abs(close - sma) / sma * 100;
spline(sma, {title: "SMA"});
spline(distance, {title: classify(distance)});
}