Strategy Backtester

Supported Pine Script features

What the Pine to strategy converter understands today, and what it will tell you it cannot do.

The converter is a real Pine parser and code generator that runs in your browser. Anything it cannot convert is reported with a line number instead of being guessed. To try a script, open the backtester.

Language features

  • Pine v4, v5 and v6 syntax, including v3-style boolean directions
  • var and varip variables, := reassignment and compound assignment
  • if / else if / else, switch, for, for-in and while, also as expressions
  • User-defined functions with default and typed parameters
  • Tuples such as [macd, signal, hist] = ta.macd(...)
  • History references such as close[1], x[2] and (a + b)[1]
  • input.int, input.float, input.bool, input.string and input.source become editable settings
  • request.security on the chart symbol, non-repainting by default
  • Indicator-only scripts that use alertcondition or plotshape with buy and sell signals
  • Indicators that track their own trades with flags such as call_active / put_active: the trade opens and closes with the flag
  • Drawing calls (line.new, label.new, box.new, table.new) are skipped but return a handle, so guards like not na(line) still work

Indicators (ta.*)

Moving averages, oscillators, volatility, channels, pivots and crossover detection. Legacy v4 names such as sma() and crossover() also work.

  • ta.alma
  • ta.atr
  • ta.barssince
  • ta.bb
  • ta.bbw
  • ta.cci
  • ta.change
  • ta.cmo
  • ta.correlation
  • ta.cross
  • ta.crossover
  • ta.crossunder
  • ta.cum
  • ta.dev
  • ta.dmi
  • ta.ema
  • ta.falling
  • ta.highest
  • ta.highestbars
  • ta.hma
  • ta.kc
  • ta.linreg
  • ta.lowest
  • ta.lowestbars
  • ta.macd
  • ta.max
  • ta.median
  • ta.mfi
  • ta.min
  • ta.mom
  • ta.percentrank
  • ta.pivothigh
  • ta.pivotlow
  • ta.range
  • ta.rising
  • ta.rma
  • ta.roc
  • ta.rsi
  • ta.sar
  • ta.sma
  • ta.stdev
  • ta.stoch
  • ta.supertrend
  • ta.swma
  • ta.tr
  • ta.valuewhen
  • ta.variance
  • ta.vwap
  • ta.vwma
  • ta.wma
  • ta.wpr

Strategy orders (strategy.*)

Entries, exits with stop, limit, tick-based profit and loss and trailing stops, closes and cancels. Order size comes from the Size settings.

  • strategy.cancel
  • strategy.cancel_all
  • strategy.close
  • strategy.close_all
  • strategy.entry
  • strategy.exit
  • strategy.order

Math (math.*)

Arithmetic, rounding, powers, logarithms and trigonometry.

  • math.abs
  • math.acos
  • math.asin
  • math.atan
  • math.avg
  • math.ceil
  • math.cos
  • math.exp
  • math.floor
  • math.log
  • math.log10
  • math.max
  • math.min
  • math.pow
  • math.random
  • math.round
  • math.round_to_mintick
  • math.sign
  • math.sin
  • math.sqrt
  • math.sum
  • math.tan
  • math.todegrees
  • math.toradians

Arrays (array.*)

Creating, reading, updating, sorting and summarising arrays.

  • array.avg
  • array.clear
  • array.concat
  • array.copy
  • array.fill
  • array.first
  • array.from
  • array.get
  • array.includes
  • array.indexof
  • array.insert
  • array.join
  • array.last
  • array.max
  • array.median
  • array.min
  • array.new
  • array.new_bool
  • array.new_float
  • array.new_int
  • array.new_string
  • array.pop
  • array.push
  • array.remove
  • array.reverse
  • array.set
  • array.shift
  • array.size
  • array.slice
  • array.sort
  • array.stdev
  • array.sum
  • array.unshift

Time and sessions

Session filters with time(timeframe.period, "0915-1530"), timeframe.change and date parts.

  • dayofmonth
  • dayofweek
  • hour
  • minute
  • month
  • second
  • time
  • timeframe.change
  • timeframe.in_seconds
  • timestamp
  • year

Utility

na handling, casts and basic string helpers.

  • bool
  • color.new
  • color.rgb
  • fixnan
  • float
  • int
  • na
  • nz
  • str.contains
  • str.length
  • str.lower
  • str.tonumber
  • str.tostring
  • str.upper

Skipped because they do not affect trades

These are parsed and ignored:

  • plot
  • plotshape
  • plotchar
  • plotcandle
  • bgcolor
  • barcolor
  • hline
  • fill
  • label.*
  • line.*
  • box.*
  • table.*
  • alert
  • alertcondition

Not supported

  • Other symbols in request.security or ticker.*: only the uploaded data is loaded
  • Maps, matrices, user-defined types, methods and imported libraries
  • Per-trade queries such as strategy.opentrades.entry_price()
  • Partial exits (qty and qty_percent) and percent-of-equity order sizing
  • Real-time-only features: calc_on_every_tick and varip behaviour differ from live charts

Missing something you need? Tell us.