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 run 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.
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.