Past the step budget a script stops with
OX2200, naming the line of the loop or call, and keeps what it had drawn. Counting steps rather than time makes the limit behave the same on a phone and a desktop. A model’s refit or a matrix decomposition counts too, about n³ steps for n inputs, so ml.pca refitting 30 inputs on every bar runs out where refit: 'auto' does not.
Long runs
A run replays every loaded bar, and every chart’s scripts share one worker. So a run hands the worker back about every 50 ms, between batches of 512 bars, and picks up where it stopped: other scripts keep updating while a heavy one works, and its legend says how far it has got (“Calculating 40%”). The chart keeps the run before until the new one has finished, and the result is the same wherever the pauses fall.- A slice that takes more than 5 seconds is stopped, and the same script with the same settings is not loaded again on the page until you change it.
- A run that works more than 60 seconds over all its slices stops with
OX2201. Do less per bar: refit less often, use fewer inputs or a shorter window, or load less history.
Keeping a script fast
- Work per bar, not per bar times history: keep running totals in state rather than looping back over old bars.
- Draw only on the newest bar (
chart.isLast) when only the newest bar’s drawing matters. - Sum events into tallies in their handlers; do the per-bar work once in
onBaroronClose.
The same result everywhere
A script gives the same output for the same data in every browser:- no clock, timers or
Math.random:random(seed)gives the same numbers for the same seed; Mathis the engine’s own, a port of fdlibm, soexp,log,powand the trigonometric functions give the same bits in Chrome, Safari and Firefox;ta.*follow TradingView’s formulas, seeds and running sums.