Skip to content

The engines ​

Which engine runs your script, and can two of them give different answers? Four engines run AmenoScript and Pine Script here, and they are held to the same answer to the last bit of every value. You choose between them only for speed, and the terminal chooses for you unless you ask.

EngineWhat it isWhere it runs
InterpreterWritten in TypeScript, it walks the script's syntax tree statement by statement. The reference every other engine is checked against.Your browser and the terminal's server
JITCompiles the whole script to JavaScript once, so a change of inputs reuses the code. On by default.Your browser and the server
Rust walkerThe interpreter's twin, written in Rust.The server
Rust nativeCompiles the whole script to machine code once, with the Rust walker as its fallback.The server

How they are held equal ​

Equal means bit for bit. One different last digit can flip a crossover, and every trade after it, so a value has to be na on both engines or share all 64 bits, and a trade has to agree on its side, times, prices, size and profit.

  • The corpus. Every example script in the engines' test suites runs on all four, and each plot and trade is compared.
  • Fuzzing. Mutated copies of those scripts run on the TypeScript and the Rust engines to find a case the corpus misses.
  • TradingView is the ground truth. Where TradingView and the engines disagree, TradingView's output decides, and the engines are fixed together. The strategy emulator is checked against TradingView's own results, trade for trade.
  • Maths is the same everywhere. math.exp, math.log, math.log10, math.pow, math.sin, math.cos and math.tan are ports of the routines TradingView itself runs, and math.asin, math.acos and math.atan are ports of Java's StrictMath. Each gives the same bits on every machine.

Which engine runs where ​

WhereEngine
A script on the chartRust native on the server, by default. A script with a strategy() declaration or varip, or one that reads timenow or imports a library other than the technical-analysis ones, runs on the JIT in your browser instead.
An Optimizer sweep or a Screener scanRust native on the server, and the JIT in your browser for anything the server doesn't answer.
The profilerThe engine the chart would run the script on, unless you pick another. See The profiler.

When an engine can't run a script, the next one takes it, and the answer is the same. Rust falls back to your browser, and the JIT falls back to the interpreter and says so in the run's warnings.

The Script Editor's More menu has two switches: JIT compiler and Rust engine on chart. Turn one off to rule an engine out when you think it's wrong. If an answer changes, that is an engine bug: report it with the script.

Differences between engines ​

None are intended. A difference between engines is a bug, fixed in both, and a difference from TradingView is a bug unless the Pine compatibility page lists it.

What can differ is speed, and how an engine reports a failure:

  • A script the JIT can't compile runs on the interpreter, more slowly, with a warning saying why.
  • A script that fails on the server runs again in your browser, so the chart still draws.
  • An error stops the run on every engine. The chart shows the error and nothing else, as TradingView does.

See also ​

AmenoScript is compatible with Pine Script v6. Pine Script is a trademark of TradingView, Inc., which has no part in AmenoScript.