Feature
Pine Script indicator import
Paste the source of a TradingView Pine Script indicator or strategy and its plots, signals and orders become conditions in your rules. The script says what the market is doing; the bot decides what to do about it, with its own risk guards, fees and orders.
What the import reads
- The version:
//@version=5and 6 are recommended, version 4 imports with a warning, and versions 1 to 3 are rejected. - The
indicator(),study()orstrategy()title, used as the indicator's name in your rules. - Every input, with its type, default and limits, so you can change settings per bot.
- Every
plot()as a value you can compare, and everyplotshape(),plotchar()andalertcondition()as a signal that fires. - In strategy scripts, every
strategy.entry(),strategy.exit(),strategy.close()andstrategy.close_all()as a signal, one per order id.
Using outputs in rules
Values can be compared with a number, another output of the same indicator, or the close. Signals fire on the candles where they are true.
when pine("My RSI").rsi crosses above 70 and holding
then sell 100%
when pine("Supertrend").buy fires
then buy 100%
How your script runs in a simulation
On the Pro and Quant plans, every run executes your Pine code with stratester's own Pine interpreter, on our servers. The script runs once per closed candle, oldest first, over the run's warm-up and the period you chose, and your rules read its outputs on the same candle close. On other plans you can import and build rules, and a run that uses an imported indicator is refused with a message and costs nothing.
The interpreter covers the language: var and varip, history references like close[2], if, switch and loops, your own functions, methods, types and enums, tuples, and the ta, math, str, array, map, matrix, color, time and session libraries. request.security() reads BTC/USDT on the chart's timeframe or a higher one, so a daily filter on an hourly bot works.
Strategy scripts
A strategy() script's orders become signals for your bot. A market entry or close fires on the candle where the script places it. An order that waits for a price, such as an entry with a limit or stop, or a strategy.exit() take profit or stop loss, fires on the candle where it would fill.
A position tracker follows TradingView's fill rules, so scripts that check strategy.position_size behave as written. Market orders fill at the next open, or at the close with process_orders_on_close. Stops and limits fill where the candle reaches them, or at the open if it gaps past them, and an exit order is cancelled when its entry closes. Your bot does the actual trading: the script's own commission, sizing and backtest settings are not used.
What runs differently from TradingView
- Nothing reads the future. A negative
plot(offset = …)stays on its own candle,barstate.isconfirmedis always true, andvaripacts likevarbecause candles are already closed. - With
lookahead = barmerge.lookahead_on,request.security()behaves like TradingView's historical bars and can show a higher-timeframe value before that candle closed. Use it only with[1], as TradingView advises. - The script starts with the run's warm-up (up to 5,000 candles), not the first BTC candle ever, so running totals such as
ta.cumandbar_indexcount from there. - Drawings (lines, labels, boxes, tables) don't render,
alert()is ignored, andmath.random()is repeatable. - The strategy tracker has no commission, slippage, margin, trailing stops, partial exits or OCA groups.
- Not available: other symbols, lower timeframes, libraries,
ta.pivot_point_levelsand a few advanced matrix functions. These are reported with their line when you import or run.
Limits
- Up to 5 imported indicators per bot.
- Up to 32 KB of source per indicator.
- Each script runs in a sandbox with a time limit, a work budget and a 256 MB memory cap, so a runaway loop stops instead of hanging the run.
- A script that errors or hits a limit stops the run with the line and column of the problem, and the run costs nothing.
How we check it
Every ta.* built-in is compared, candle by candle on real BTC/USDT data, with a second, independent implementation written from TradingView's documentation. Across 78 series the largest difference is about one part in 100 billion.
Fourteen complete scripts written the way traders write them are recomputed independently and match on every candle. They span versions 4, 5 and 6 and include three strategies, with features such as daily and 4-hour request.security(), custom types, arrays and maps. Pine versions of our built-in MACD, Supertrend, Bollinger, Stochastic, ADX, EMA and moving-average blocks make exactly the same trades as the blocks, and thousands of deliberately broken scripts have never crashed the server.
These checks compare against TradingView's documented behaviour, not against TradingView itself. Where the documentation is silent, for example how ta.rising counts or how a crossover treats a missing value, we follow TradingView's measured behaviour. Values can also differ slightly in the first candles, before indicators have settled.
Pine Script indicator import: frequently asked questions
Can I run Pine Script strategies?
Yes. Import the strategy() script and its entries, exits and closes become signals your rules act on. The bot's own rules, fees and risk guards do the trading, not the script's backtest settings.
Do simulations run my Pine code?
Yes, on the Pro and Quant plans. Our own interpreter runs the script on every closed candle before your rules are checked, with no look-ahead. Values can differ slightly from TradingView near the start of the history, and drawings, other symbols and lower timeframes aren't supported.
Which versions are supported?
Versions 4, 5 and 6. Version 5 and 6 are recommended; version 4 imports with a warning, and its un-namespaced functions such as sma() and crossover() work. Older versions are rejected.
Will my indicator show exactly the same values as on TradingView?
It follows TradingView's definitions, and our tests match them closely on real data. Expect small differences in the first candles of a run, while indicators settle on the warm-up history, and in the cases listed above.
What happens if my script has an error?
Import reports syntax problems with their line. If the script fails during a run, for example by reading an array index that doesn't exist, the run stops with the line and column and does not use up a run.
Is my script shared?
No. Imported scripts are stored with your bot and only you can see them.
Related
Simulated results are hypothetical. They include only the fee and slippage you set on the bot, not every real-world cost or market condition, and past performance does not guarantee future results. Nothing here is financial advice.