Docs menu

Import a Pine script

Paste a TradingView Pine v5 or v6 strategy into the Builder, see which parts were read and which lines were not, and the units it converts.

Paste Pine script turns a TradingView Pine v5 or v6 strategy() script into a flow on the canvas. It uses fixed rules inside your browser. It does not use AI, and nothing is sent anywhere. It is not a Pro feature. It only produces the flow (parts and settings), never source code.

Paste and place

  1. In the Builder toolbar, open the … menu and choose Paste Pine script.
  2. Paste the script into the box. The result updates as you type.
  3. Read the result under the box:
    • Can place: N parts from X of Y entries. The script was read.
    • These do not fit (N). Each line that could not be read is listed with its line number, the line text and the reason. Nothing is dropped silently.
    • Notes. Things that were read but differ slightly (see below).
  4. Click Place. When some lines do not fit, the button says Place without these, so you choose to place the rest.

Placing replaces the canvas, like opening a template. If nothing in the script can be placed, the button stays disabled and the box shows why.

What is read

  • //@version=5 or //@version=6, and the strategy(...) declaration.
  • input.int, input.float, input.bool and input.source. The default value is used.
  • Assignments with = and :=, and if blocks.
  • Indicators: ta.sma, ta.ema, ta.wma, ta.rma, ta.atr, ta.rsi, ta.cci, ta.wpr, ta.bb, ta.macd, ta.highest, ta.lowest and ta.sar, where the Builder has a matching part.
  • Comparisons, ta.crossover, ta.crossunder, and and, or, not.
  • strategy.entry, strategy.close and strategy.exit with a stop and a limit in pips.
  • A stand-alone hour or dayofweek condition. It becomes a time window or a weekday filter.
  • request.security with a constant timeframe string. lookahead_on is not read.
  • Scripts exported by the Builder’s own Pine export are read back to the parts they came from.

What is rejected

A script that cannot be placed at all stops with one reason:

  • no //@version, a version other than 5 or 6, or no strategy() call
  • indicator() scripts
  • pyramiding above 1
  • calc_on_every_tick=true
  • process_orders_on_close=true
  • use_bar_magnifier

Inside a script that can be placed, these lines are listed with a reason and are not placed:

  • arrays, matrices and maps
  • loops (for, while), switch, and var state that persists across bars
  • user functions that cannot be inlined
  • arithmetic between series, math.max, math.min, math.abs and similar, na() tests, and a series that refers to its own past value (x := f(x[1]))
  • ta.* functions without a matching part, the MACD histogram, and ta.cross (use ta.crossover or ta.crossunder)
  • limit and stop entry orders (the Builder enters at the market), and trailing exits written as an absolute price (trail_price)
  • an hour condition that is not one continuous window, or a weekday condition that includes Saturday or Sunday

If an if block cannot be read, every variable assigned in it is treated as unreadable, so an entry that depends on it is rejected instead of using an old value.

Units

  • Pips and ticks. strategy.exit with loss, profit, trail_points or trail_offset is in ticks. Ticks are read at 10 ticks per pip, the Builder pip definition for 5- and 3-digit quotes (the same one the Pine and MQL5 export use). loss=500 becomes a 50 pip stop, and loss=55 becomes 5.5 pips: a whole number of ticks is always exact in decimal pips, and nothing is rounded. Each converted value gets a note saying so. On metals, indices or 2- and 4-digit quotes a pip is not 10 ticks, so check the stop and target after placing. A value that is not a positive whole number of ticks is rejected. Values written as N * pip / syminfo.mintick are read as N pips.
  • Trailing. trail_points (the profit at which trailing starts) and trail_offset (the distance) become a fixed trailing stop with the step set to 0.1 pip. Pine trails on every tick; the Builder checks at the bar close. trail_price is rejected.
  • Absolute prices. stop= and limit= are read only when written as a distance from strategy.position_avg_price in pips or ATR; any other price expression is rejected.
  • Lot. A fixed order size in units is converted at 100000 units per lot, only when it is a whole 0.01 lot. Otherwise the lot stays at the Builder default 0.01 and a note says so.
  • Bar shift. close[1] in Pine is read as the Builder shift 2. The Builder export runs once per bar at the bar close, and Pine [j] is Builder shift j + 1.
  • Time zone. hour and dayofweek use the exchange time zone of the chart in TradingView. The Builder uses its server time, and a note asks you to check that they match.
  • MACD signal. TradingView uses an EMA for the signal line. The Builder signal line is an SMA of the MACD line, so values differ slightly. A note says so.

Round trip with the Builder’s own export

The importer was checked against the Builder’s Pine export for all 91 non-portfolio templates (the 9 portfolio templates are not single flows). Parts match for 19 of them; for 14 of those the settings (lot, filters, exits) match as well, and for 5 the settings are not read back from the script. 5 come back changed (3 partial exits are listed as not read, 2 composite parts come back as basic parts). 15 cannot be exported to Pine, and 52 contain constructs from the rejected list above. The same counts are pinned in npm run pine:roundtrip:test.

Next steps