Pine Script Import
Import a TradingView Pine Script v5 strategy and run it against your own data, with PSO optimization and walk-forward validation that TradingView doesn't offer.
How to use it
- Open the workspace and open or create any strategy.
- Click Pine Import in the graph editor toolbar.
- Paste your Pine Script v5 strategy code into the text area.
- Give it a name, then click Convert to graph.
- Review the converted graph, then click Save & open to open it in the editor. Review the blocks. All
input()variables become tunable constants automatically. - Run a backtest or PSO optimisation as usual.
What gets converted
| Pine Script construct | Graph block |
|---|---|
ta.ema(src, len) | Indicator.EMA |
ta.sma(src, len) | Indicator.SMA |
ta.rsi(src, len) | Indicator.RSI |
ta.atr(len) | Indicator.ATR |
ta.macd(...) | Indicator.MACD |
ta.bb(src, len, mult) | Indicator.BollingerBands |
ta.stoch(k, d, ...) | Indicator.Stochastic |
ta.highest(src, len) | Indicator.Highest |
ta.lowest(src, len) | Indicator.Lowest |
ta.crossover(a, b) | Math.CrossesAbove |
ta.crossunder(a, b) | Math.CrossesBelow |
strategy.entry("Long", strategy.long) | Sink.Entry.Long |
strategy.entry("Short", strategy.short) | Sink.Entry.Short |
strategy.close(...) | Sink.Exit |
input.int / input.float | Source.Constant.Number (tunable) |
input.bool | Source.Constant.Boolean |
and / or / not | Logic.And / Or / Not |
condition ? a : b | Logic.IfThenElse |
>, <, >=, <=, == | Compare.GT / LT / GTE / LTE / EQ |
+, -, *, / | Math.Add / Sub / Mul / Div |
close / open / high / low | Source.Bar.Field |
Limitations: what doesn't convert
partiqon's graph system covers indicator-based trading logic. Some Pine Script features have no equivalent:
- Pine Script v4: only v5 is supported. Use TradingView's built-in Pine converter to upgrade v4 scripts first.
request.security(): multi-timeframe data fetching. Use partiqon's Aggregator blocks (M15, M30, H1, D1) instead; they're natively available as graph blocks.- Custom user-defined functions (complex ones): simple helper functions are usually inlined by the converter; deeply recursive or stateful functions may not map cleanly.
- Arrays and matrices: Pine's array.* and matrix.* API has no block equivalent.
- Drawing functions: plotshape, label.new, line.new etc. are visualization-only; they're ignored during import.
- alert() / alertcondition(): alert triggers are not carried over.
- table.*: dashboard tables are not converted.
- Indicators-only scripts: scripts without
strategy.entry()calls produce no entry nodes. Add entry logic manually after import.
Example: EMA crossover
Here's a simple Pine Script v5 strategy and what it becomes after import:
After import, the graph contains: two EMA blocks (fastLen and slowLen as tunable constants), a CrossesAbove block, a Mul + Sub for stop distance, Mul + Add for take profit, and an Entry LONG sink. All four input.* variables are marked tunable and ready for PSO optimisation.
Tips for best results
- Use
strategy.entry()with explicit stop and take-profit parameters where possible. The converter maps these directly to the entry block'sstop_loss_distanceandtake_profit_distanceinputs. - Avoid deeply nested if/else blocks. Flatten conditions with
and/oroperators where possible. - Name your
input()variables clearly, because the names become node labels in the graph. - If the converted graph does not validate, nothing is saved and the panel shows the reason. Simplify the script (see the limitations above) and convert again.
Exporting a graph to Pine Script
The Pine Export button in the toolbar turns the open strategy into a TradingView Pine Script v5 strategy. The script is written to trade the way partiqon's backtest trades the same graph:
- An entry signalled on a bar's close fills at the next bar's open, with its stop and target distances measured from the actual fill. Stops and targets are active from the fill on, including the rest of the bar the entry fills on.
- With the default of one position at a time the script enters only while flat, one entry per bar. With higher position limits it adds entries up to the limit of each direction. TradingView cannot hold a long and a short at the same time, so a strategy that allows hedging is not reproduced exactly, and the top of the file says so.
- Exit blocks close at the signal bar's close, per side, and partly when a fraction is set. Stop updates only ever tighten the stop.
- Blocks behind an aggregator are calculated on that timeframe's bars and, on historical bars, read on the chart when the higher-timeframe bar completes, as in partiqon. Apply the script to a chart of the timeframe named at the top of the file.
- Indicators use partiqon's own definitions where TradingView's built-ins differ (for example how an EMA starts).
What the script cannot reproduce is listed at the top of the file:
- Blocks with no Pine equivalent (for example the regime and volatility gates) are named there. Gates are treated as always open, so the script can trade more often than partiqon.
- Spread, slippage and commission are not charged. Set them in the strategy's properties in TradingView. partiqon applies slippage to entries and stops but not to targets, which are resting limit orders and pay the spread only; TradingView's slippage setting likewise applies to market and stop orders, not to limit orders.
- When a bar touches both the stop and the target after opening between them, partiqon books the stop; TradingView decides the fill by its own rules, so the two can differ on such a bar.
- On live bars TradingView shows a higher-timeframe bar while it is still forming (the script reads it with
request.securityand lookahead off), and its value changes until the bar closes. partiqon only ever reads completed bars, so a live signal can differ from the backtest until that bar closes. The top of the file says so whenever the script uses a higher timeframe. - TradingView's data feed differs from your dataset, so individual bars and trades can differ.
When some blocks could not be translated, partiqon says so right after the export.