QuantScript draws heavy inspiration from Pine Script's concise indicator syntax while using standard JavaScript syntax. Here's how to translate your knowledge.
| Pine Script | QuantScript |
|---|---|
| Implicit per-bar execution | df.forEach((frame) => { ... }) |
close, volume (implicit globals) | frame.close, frame.volume (explicit) |
var x = 0 (persists across bars) | let x = 0; declared outside the loop |
na (missing value) | null (standard JS) |
| Runs only in TradingView UI | quantscript run strategy.qs --mode backtest |
//@version=5
indicator("My Indicator")
plot(close)indicator("My Indicator");
df.forEach((frame) => {
chart.plot(frame.close, "Close");
});myVar = 10
const PI = 3.14159let myVar = 10;
const PI = 3.14159;smaValue = ta.sma(close, 20)
plot(smaValue, "SMA", color.blue)df.forEach((frame) => {
let smaValue = ta.sma(frame.close, 20);
chart.plot(smaValue, "SMA", "#0000FF");
});rsiValue = ta.rsi(close, 14)
hline(70, "Overbought")
hline(30, "Oversold")
plot(rsiValue, "RSI")df.forEach((frame) => {
let rsi = ta.rsi(frame.close, 14);
chart.hline(70, "Overbought");
chart.hline(30, "Oversold");
chart.plot(rsi, "RSI");
});if close > open
label.new(bar_index, high, "Bullish")df.forEach((frame) => {
if (frame.close > frame.open) {
console.log("Bullish bar");
}
});strategy("My Strategy")
if ta.crossover(ta.sma(close, 10), ta.sma(close, 20))
strategy.entry("Long", strategy.long)
if ta.crossunder(ta.sma(close, 10), ta.sma(close, 20))
strategy.close("Long")strategy("My Strategy");
df.forEach((frame) => {
let fast = ta.sma(frame.close, 10);
let slow = ta.sma(frame.close, 20);
if (ta.crossover(fast, slow))
strategy.entry("Long", "long");
if (ta.crossunder(fast, slow))
strategy.close("Long");
});[macdLine, signalLine, hist] = ta.macd(close, 12, 26, 9)
plot(macdLine, "MACD", color.blue)
plot(signalLine, "Signal", color.red)
plot(hist, "Histogram", color.green)df.forEach((frame) => {
let [macd, signal, hist] = ta.macd(frame.close, 12, 26, 9);
chart.plot(macd, "MACD", "#0000FF");
chart.plot(signal, "Signal", "#FF0000");
chart.plot(hist, "Histogram", "#00FF00");
});[lower, middle, upper] = ta.bb(close, 20, 2)
plot(lower, "Lower Band")
plot(middle, "Middle Band")
plot(upper, "Upper Band")df.forEach((frame) => {
let [lower, middle, upper] = ta.bbands(frame.close, 20, 2);
chart.plot(lower, "Lower Band");
chart.plot(middle, "Middle Band");
chart.plot(upper, "Upper Band");
});df.forEach((frame) => { ... }).close directly. In QuantScript, use frame.close inside the loop.close[1]. QuantScript uses the same syntax: close[1].color.blue. QuantScript uses hex colors: "#0000FF".ta. for technical analysis functions, but syntax may differ slightly.QuantScript is actively implementing Pine Script V6 features. Here's the current coverage by category:
| Category | Coverage | Status |
|---|---|---|
| ta.* Technical Indicators | 35 / ~100+ functions (~35%) | In Progress |
| math.* Math Functions | 24 / ~40 functions | Mostly Complete |
| str.* String Functions | 17 / ~25 functions | Mostly Complete |
| array.* Array Functions | 28 / ~50 functions | In Progress |
| strategy.* Trading | 8 / ~25 functions | In Progress |
| chart.* Drawing System | 5 basic functions | In Progress |
| Operators & Control Flow | All core operators, if/for/while | Complete |
| Type System | Dynamic typing (no annotations) | Planned |
| Drawing Objects (line, label, table) | Not yet implemented | Planned |
| Multi-symbol (request.security) | Not yet implemented | Planned |
ta.atr(), ta.tr(), ta.vwma(), ta.vwap(), input.*() family, var keywordta.adx(), ta.dmi(), ta.cci(), ta.obv(), ta.mfi()color.* constants, fill(), line.*, label.*strategy.risk.*, request.security()export/import, type declarations, matrix.*/map.*