Pine Script Online: Write, Run and Backtest Scripts in the Browser for Free
Pine Script is the de facto language for chart indicators: short, series-based, and readable by people who have never written a line of JavaScript. The usual way to use it ties you to one charting product. We wanted something different: to run Pine Script online, free and right in the browser, on our own charts, with no account and no install. So we wrote an interpreter for it.
This post is a hands-on tour. We will paste an indicator, break it on purpose to see what the errors look like, then turn it into a strategy and read a backtest report. Along the way I will explain what the engine does under the hood, because “it runs Pine Script” can mean very different things. If you just want to try it, here is the page: run Pine Script online, free and right in the browser.
Where the editor lives
The editor is part of FiRe Trading, the free charting terminal of BotHub FiRe. It accepts Pine Script compatible with TradingView, versions 5 and 6, alongside our own simpler formula language. You open it from the chart’s top bar: the ƒx button (“My indicators”) → New Pine Script indicator. On a narrow screen the button may sit in the “More” menu.
The editor detects the language from the //@version= line, so you can also paste a script into an ordinary “New indicator” window — the status line under the code switches to “Pine Script”. A script without a version line is read as v6. Versions 1–4 are rejected with a clear message (“Pine Script version 4 is not supported: use version 5 or 6”), because study(), the old sma() without a namespace and the rest of v4 would need a separate front end.
Nothing here requires signing in. Scripts are kept in the browser (IndexedDB); if you do log in, they also sync to your account and open on any device.
Step 1: an indicator
Let’s start with the classic — two exponential moving averages and markers where they cross:
//@version=6indicator("EMA cross", overlay = true)fastLen = input.int(20, "Fast EMA", minval = 1)slowLen = input.int(50, "Slow EMA", minval = 1)fast = ta.ema(close, fastLen)slow = ta.ema(close, slowLen)plot(fast, "Fast", color = color.orange)plot(slow, "Slow", color = color.blue)bull = ta.crossover(fast, slow)bear = ta.crossunder(fast, slow)plotshape(bull, "Buy", shape.triangleup, location.belowbar, color.green, size = size.small)plotshape(bear, "Sell", shape.triangledown, location.abovebar, color.red, size = size.small)alertcondition(bull, "Fast crossed above slow", "EMA cross up")alertcondition(bear, "Fast crossed below slow", "EMA cross down")
Paste it and press Apply to chart. Three things happen:
-
The two lines and the triangles appear on the price chart (the screenshot above is exactly this script on daily BTC).
-
Both
input.int()calls become number fields under the code. Change 20 to 9 and the chart recalculates — no need to touch the text. -
The status line says “No errors · Pine Script · On the price chart”. The last part comes from
overlay = true; without it the script gets its own pane.
Type a name, press Save, and the script appears in “My indicators” and in the regular Indicators dialog, so you can drop it on any other chart. The editor window can be pinned to the right side of the terminal (the pin icon in its header), which is what you see in the screenshot: code on the right, chart on the left, and every “Apply” redraws in place.
The alertcondition() lines are not decoration. The bell in the indicator’s legend lets you set an alert on any of them; a logged-in user’s alerts are checked by the server even when the tab is closed (up to 5 alerts on your own scripts).
Step 2: break it
An interpreter is only as pleasant as its error messages. Here is a mistake almost everyone makes once:
//@version=6indicator("Plot inside if", overlay = true)fast = ta.ema(close, 20)slow = ta.ema(close, 50)if fast > slow plot(fast, "Fast", color.green)
The editor highlights the line and says: Line 6, column 5 — plot() can be used only at the top level of the script, not inside a block or a function. That is the language’s own rule: the number of plots must be known before the first bar is calculated, so a conditional plot is illegal. The idiomatic fix is to plot conditionally by value — plot(fast > slow ? fast : na).
Two other messages you may meet, both with a position in the text:
-
import is not supported yet— libraries are not there yet (see “What is missing” below); -
There is no symbol …—request.security()asked for something we do not have. Withignore_invalid_symbol = truethe request returnsnainstead.
How the engine works
It is worth being precise here, because “Pine in the browser” is easy to fake with a regex-based translator to JavaScript and eval. We did not do that.
-
A real parser and interpreter. The text is parsed into a tree and executed bar by bar, as the language defines: the script runs once per candle,
varkeeps a value between bars,varipexists,x[n]works on the history of any expression. There is noevaland nonew Functionanywhere — the script has no access to the page, cookies or network. -
The whole v5/v6 syntax. Types and qualifiers,
if,switch,for,for…in,while, user functions and methods,type,enum, tuple returns[a, b] = f(). -
446 built-in functions and 330 variables and constants. All 59
ta.*functions of the v6 reference, with the original formulas: Wilder’s smoothing for RSI and ATR, seeding with the average of the first values,naat the start of a series.label.*,line.*,box.*,table.*,polyline.*(105 functions, with the language’s object limits),array.*,map.*,matrix.*(115),str.*,math.*,color.*,time()andsession.*with real exchange hours and DST. -
Other symbols and intervals.
request.securityandrequest.security_lower_tfwork without look-ahead;barmerge.lookahead_onbehaves as in the language. Exchange-prefixed names are mapped automatically:NASDAQ:AAPL,MOEX:SBER,BINANCE:BTCUSDT,CME_MINI:ES1!,TVC:DXYall resolve to our symbols. -
Budgets instead of freezes. A run has hard limits — 100,000 iterations per loop, 100,000 candles per calculation, 5,000 bars of
x[n]history, 64 plots, 500 inputs — and a time budget. A runawaywhileends with an error pointing at the line, not with a frozen tab.
How much of real-world code does that cover? On 28 November 2026 we ran 966 open-source scripts through the engine on five candle series of different length (Apple daily and hourly, bitcoin hourly, BTC/EUR and gold daily). 834 of 966 (86%) compile and run without an error as they are, 895 (93%) at least compile. Strategies do better than indicators: 251 of 262 (96%) against 583 of 704 (83%). Most failures are libraries (import) and drawing-heavy scripts that hit a missing corner.
Step 3: from indicator to strategy
Swap indicator() for strategy() and add orders:
//@version=6strategy("EMA cross strategy", overlay = true, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 90, commission_type = strategy.commission.percent, commission_value = 0.1)fastLen = input.int(20, "Fast EMA", minval = 1)slowLen = input.int(50, "Slow EMA", minval = 1)stopPct = input.float(5, "Stop, %", minval = 0.5, step = 0.5)fast = ta.ema(close, fastLen)slow = ta.ema(close, slowLen)plot(fast, "Fast", color.orange)plot(slow, "Slow", color.blue)if ta.crossover(fast, slow) strategy.entry("Long", strategy.long)if ta.crossunder(fast, slow) strategy.close("Long")stopPrice = strategy.position_avg_price * (1 - stopPct / 100)strategy.exit("Stop", "Long", stop = stopPrice)
After Apply to chart the trades appear on the chart and the tester panel opens under it: equity curve with drawdown, list of trades and a summary.
On daily BTC/USD, from 28 October 2025 to 4 December 2026 (403 candles — the depth of daily history on that chart), this strategy made three trades, one of them a winner, and ended at −1.94% ($9,806 out of $10,000, $51.91 of commission). Buy-and-hold over the same period lost 55.4%. Max drawdown was −10.4%. Do not read anything into these numbers beyond “the tester works”: three trades is not a sample, and a test on history does not promise the same result in the future.
What matters for a developer is how the tester fills orders, because that is where backtests usually lie:
-
The script runs once per candle, at its close, and sees the position after that candle’s fills. It never reads a later candle.
-
A market order fills at the open of the next candle; with
process_orders_on_close = true, at the close of the same one. -
Inside a candle the price goes from the open to the nearer extreme first, then to the farther one, then to the close. So a stop and a target in the same candle resolve deterministically.
-
A limit or stop fills at its own price, or at the market price after a gap.
-
slippage(in ticks) worsens market and stop fills; commission of any of the three kinds is charged on every fill;pyramiding, OCA groups and the risk rules are supported. -
There is no intrabar recalculation:
calc_on_order_fillsanduse_bar_magnifierare not implemented yet. The tester uses four prices per candle — open, high, low, close.
A strategy is tested on the symbol’s history, up to the last 20,000 candles of the chart’s interval.
What is missing
Honest list, as of December 2026:
-
importof libraries. -
Requests on special chart types:
ticker.renko,ticker.kagi,ticker.linebreak,ticker.pointfigure. -
plotcandleandplotbarare calculated, but the script’s own candles are not drawn yet. -
Spreads in a request (
"AAPL/MSFT") and exchange holidays inside session strings. -
Currency conversion in strategies.
-
Pixel-exact placement of labels and tables: colours and widths follow the script, text may sit a few pixels off.
-
Protected and invite-only scripts cannot be moved at all — their source is hidden by design.
Sharing and limits
Share gives a link to the chart; the texts of the scripts on it travel with the link (up to 120,000 bytes in total), and the recipient can save them. You can keep up to 50 scripts, each up to 262,144 characters, all texts together up to 4 MB — in the browser without an account, and in your account once you log in.
If Pine Script is overkill
Pine is a full language, and for “a moving average of the candle body” it is more than you need. The terminal has a second, much smaller formula language: name = formula lines, plot(), input(), a short list of functions, no types or blocks. It runs through the same chart, the same tester and the same alerts. The full guide with examples is here.
If you try your own scripts and hit something that should work but does not, tell us which function failed — the compatibility list grows from exactly those reports.
ссылка на оригинал статьи https://habr.com/ru/articles/1115934/