| //@version=4, 5 and 6 | supported | the version line is optional; v4's un-namespaced sma(...), crossover(...), max(...), iff(...) and input(..., type=input.integer) are read as today's ta.*, math.* and typed inputs, and when= on strategy.entry/close works as an if around the call (security(...) is read as request.security(...), study(...) as indicator(...)); other version numbers are rejected |
| strategy(title, initial_capital, default_qty_type, default_qty_value, commission_type, commission_value, slippage) | supported | default_qty_type=strategy.fixed enters default_qty_value contracts on every entry, strategy.cash default_qty_value of money over the close of the signal bar, strategy.percent_of_equity a percentage of the equity; a default_qty_value with no type is fixed, as in TradingView; with neither, the Position size from the Parameters tab (TradingView enters 1 contract); a size the code sets disables the Position size field. A commission_type other than strategy.commission.percent falls back to the Parameters tab with a warning instead of erroring; other named arguments are accepted, and one QTrader does not recognize prints its own warning; a missing commission_value is the market's taker fee (TradingView uses 0). slippage=N moves market and stop fills N price steps worse (not limit fills, not with pyramiding, partial exits or strategy.order yet), in place of the Slippage setting. A robot started before engine version 6 sizes from the Parameters tab and ignores slippage |
| strategy.entry(id, strategy.long | strategy.short) | supported | several ids per direction open the same position (one entry at a time unless strategy(pyramiding=N)), and an exit or close from any of them closes it; the same id cannot be used for both long and short; qty=N enters N contracts (coins) instead of the position size from strategy(...)'s default_qty_type/default_qty_value or the Parameters tab -- N computed on the bar too, e.g. strategy.equity * risk / stopDistance, taken where the call is; an entry whose margin (N times the price, over the leverage) is more than the equity is not opened (Pine v6's margin of 100%; the Notes tab says from when), and a qty that is na or not above 0 drops the entry, as in TradingView; a live robot sends N as the order's quantity, rounded down to the exchange's lot size. qty= sizes an entry at a price (stop=/limit=) the same way -- a robot started before engine version 4 ignores it there with a warning -- and a robot started before engine version 3 ignores qty= (sizing from the settings, as it always did); if a long and a short entry both fire on the same bar while flat, they fill in the order the script's strategy.entry calls run, as in TradingView: with a position size over half the equity (Pine v6's default margin of 100%) the first opens and the second is rejected; with half or less the first opens and at once reverses into the second at the same open, a trade that opens and closes on one price; v4 and v5 scripts are treated as v6 here (in TradingView their default margin is 0, and they always reverse); a robot started before engine version 2 still opens the long |
| opposite-side strategy.entry while a position is open | supported | reverses the position — closes the current side and opens the other at the same next-bar open — exactly as in TradingView |
| strategy.close(id), strategy.close_all() | supported | closes the entry on the matching side (long or short); qty_percent=X closes X% of the position at the next open, the oldest entries first (each closed part is a trade of its own); qty= in contracts is not supported yet. Backtests only: a live robot refuses partial closes for now |
| strategy.position_size, strategy.position_avg_price | supported | read-only, translated to position.size and position.entry_price |
| strategy.exit(id, from_entry, stop=, limit=) | supported | stop and limit at any price -- close - 2 * ta.atr(14), low[1], a value from an input: the level is set where the strategy.exit call is reached (inside an if: on the bars the if runs, kept until it runs again), as TradingView places or replaces the exit order there; on a live robot it closes at market within about a minute after the price touches it. strategy.position_avg_price * F stays a percent of the entry fill (F is a number or (1 - x) / (1 + x) with x a number or an input), which a live robot's TradeAdapter connection mirrors as its own stop/target; with both, the stricter stop and the nearer target win. from_entry picks the side (omitted: every side the script enters). loss= and profit= are ticks of syminfo.mintick from the entry fill, active from the fill bar. On that bar, as in TradingView, a stop or target its open is already past (a price set on the signal bar, before a gap) fills at the open. trail_points (or trail_price) with trail_offset is a trailing stop in ticks: once the price has gone that far in the position's favour, the stop follows the best price since entry -- moved once a bar here, inside the bar on TradingView; with loss= too, the stricter stop wins. qty_percent makes an exit ladder: each strategy.exit of that entry is a step with its own stop and/or target (stop=/limit= prices, loss=/profit= ticks, strategy.position_avg_price * F, a trailing stop as above -- with loss= too, the stricter), closing its qty_percent of the position as entered -- one without qty_percent closes what is left -- up to 4 steps a side, as TradingView's take-profit ladders (TP1 50%, TP2 the rest trailing); backtests only, not together with pyramiding yet. qty= in contracts is not supported yet From engine version 5, as TradingView places an order: its stop and limit prices, loss=/profit= ticks and a trailing stop's prices are rounded to syminfo.mintick (a long's stop and a short's target down, a long's target and a short's stop up; a trailing offset cut to whole ticks); strategy.position_avg_price * F works from the bar after the entry -- TradingView places it at a bar's close, where the average price is first known (with process_orders_on_close, a close already past it fills it there) -- and with several lots at their average price, for every lot; a price set for one trade ends with it (before, it could stop the next trade of that side) |
| limit and stop orders (limit=, stop= on strategy.entry), strategy.cancel, strategy.cancel_all | supported | the order is placed where the call is reached and waits until the price reaches it (at the bar's open when it gaps past), it's cancelled, or the position is on its side; an order on the other side of a position reverses it. Its strategy.exit stop and target are armed at the fill and see the rest of that bar -- the extremes after the fill and the move to the close, as TradingView's broker emulator walks it. A live robot sends a market order within about a minute after the price touches the order's price (not under strategy.risk.allow_entry_in yet). oca_name with oca_type=strategy.oca.cancel (or reduce) drops the other orders of the group once one fills. From engine version 5 the price is rounded to syminfo.mintick as TradingView places it (a buy limit and a sell stop down, a buy stop and a sell limit up), and an order that filled and closed on one bar doesn't fill again |
| input.int, input.float, and untyped input(...) | supported | group, tooltip, inline, step, confirm and display are ignored; input(defval, ...) takes its type from the default -- a whole number, a fraction, true/false, text or a price series |
| name = input.int(...) * NUMBER or / NUMBER | supported | the TradingView percent idiom (e.g. pct = input.float(2.0, "Stop Loss (%)") * 0.01): the parameter itself stays the raw value, and every later use of name in an expression is scaled automatically |
| input.bool, input.source, input.time | supported | input.bool is a checkbox in the Parameters tab (the run reads it as 1 or 0); input.source is a select of the price series (open, high, low, close, hl2, hlc3, ohlc4, hlcc4), fed wherever the input is read; input.time is fixed to its default value, with a warning -- change it in the code |
| input.string | supported | a select of its options= in the Parameters tab, a text field without them; comparing it with text (== / !=, switch) is decided when compiling, so maType == "EMA" ? ta.ema(close, 20) : ta.sma(close, 20) computes only the branch it picks -- another value compiles the script again with that value, as if written in the code. An input.string inside an expression (long = input.string("Long") == "Long") has no name to edit: it stays fixed to its default, with a warning |
| input.timeframe | supported | a select of the timeframes ("" for the chart's own, 1, 5, 15 ... 240, D, W, M) or of its options= in the Parameters tab -- for request.security(syminfo.tickerid, tf, ...) and comparisons; like input.string it's decided when compiling. The backtest itself always runs on the chart's timeframe |
| input.symbol, input.text_area | supported | fixed to their default text, with a warning -- the backtest always runs on the chart's market |
| input.color, color.*, colour variables | ignored | a variable holding a colour (color.*, color.new/rgb, #RRGGBB / #RRGGBBAA literals) is dropped with a warning: colours only reach the drawing calls, which QTrader ignores |
| text in variables: grp = "Risk", longId = "Long", msg = "Buy " + str.tostring(close) | supported | a name given text once (never changed with :=) is that text wherever it is read -- a group= or title, a strategy.entry/close/exit id, a comparison with an input.string (mode == "Fast" is decided when compiling); text built from values (+ of texts, str.tostring) or a string changed with := only reaches what takes text -- comment=, alert_message=, alert(), labels; anywhere else is an error saying so. syminfo.ticker, tickerid, prefix, root, basecurrency, currency (the run's market: BTCUSDT, BINANCE:BTCUSDT, BINANCE, BTCUSDT, BTC, USDT; a perpetual's ticker ends in .P), syminfo.type ("crypto"), volumetype ("base"), timezone ("Etc/UTC") and session ("24x7") are text known when compiling: compare them (syminfo.type == "crypto") or test them with str.contains / str.startswith / str.endswith, also through str.upper / str.lower and variables holding them; syminfo.description isn't known. A true/false variable built from them isn't known when compiling, so it can't be a ta.* length (a direct syminfo.type == "crypto" ? 14 : 10 can) |
| if / else, nested if, around orders | supported | a ta.* call inside a nested if runs on every bar in QTrader, unlike TradingView — assign it to a variable at the top level for identical results |
| := / += inside if blocks | supported | change a variable declared at the top level (var or plain) from any depth of if/else; a variable declared inside an if lives in that block only, as in TradingView -- also when := changes it there (float x = na, then x := ...) |
| var, varip, :=, +=, -=, *=, /=, %= | supported | var / varip keep a value from bar to bar; :=, +=, -=, *=, /=, %= change it. strategy.position_* can be read where such a variable is updated (it's the position after that bar's fills). A ta.* function over such a variable works outside its updates (smooth = ta.ema(acc, 10) at the top level), computed once the variable's values are known -- not where it's updated, and not when those updates read strategy.position_* |
| user-defined functions (name(x, y) => ...) | supported | one-line and multi-line, typed parameters, defaults and named arguments; expanded where they're called, so ta.* inside get concrete arguments; an if/else the function ends with is its value (e.g. picking ta.ema or ta.sma by an input.string); [x, y] at its end returns several values, unpacked with [a, b] = f(...). A function may keep state -- var, :=, if blocks and loops in its body -- and each place it's called keeps its own, as in TradingView; such a function is called on its own line or in a condition, not inside ?: or after and/or. methods too: method f(x, y) => ... is called as x.f(y) (or f(x, y)). Not yet: recursion |
| switch (x = switch subject / x = switch, or as a statement) | supported | as a value over an input.string it picks its arm when compiling; otherwise a chain of ?: (a ta.* inside warns: it runs on every bar). As a statement it's an if / else if chain: an arm runs the call after => or the block below it, `=> na` does nothing. Not yet: value arms with a block below => |
| for i = a to b [by step] | supported | a loop that only computes values (:=, +=, if, break/continue, its own variables) runs as a real loop: any bounds -- numbers, inputs, values computed on the bar (no loop while an end is na) -- counting down when a > b, as in TradingView; close[i] reads i bars back. Every loop pass on a bar counts against 10,000; past that the backtest stops with the loop's line. A loop that places orders (strategy.* inside) is unrolled when compiling, up to 200 passes: bounds are numbers, or an input.int with a maxval. for v in a and for [i, v] in a go over an array |
| while | supported | a loop that only computes values (:=, +=, if, break/continue, its own variables); orders go after it. Counts against the same 10,000 passes a bar as for loops |
| array.* (float[], array<float>, array.new<float>, a.push(x), ...) | supported | arrays of numbers or true/false: array.new_float/int/bool and array.new<T>, array.from, size, get, set, push, pop, shift, unshift, insert, remove, clear, includes, indexof, lastindexof, sum, avg, min, max, range, median, stdev, variance, sort (order.ascending / order.descending), copy, slice, first, last, fill, reverse, concat, abs -- as functions or methods (w.push(close)); a negative index counts from the end. An array is kept from bar to bar with var, else made anew on every bar -- also in a strategy that reads strategy.position_* where it changes the array. and / or and ?: skip the array reads they skip, as in TradingView: array.size(a) > 0 and array.get(a, 0) > close never reads past an empty array. Every element statistic skips na, as in TradingView. Arrays of objects of a type (array.new<Trade>()) are in the type row below. Not yet: arrays of strings, colours or drawings, array.slice as a view of the original (here a copy) -- matrices are in the matrix.* row below |
| type (user-defined types): type Trade, Trade.new(...), t.stop, t.stop := x, methods | supported | fields of type float, int, bool, string, an array, a map or another type, with defaults (a bool field without one is false, the rest na); Trade.new(...) with positional and named arguments; t.stop reads a field, t.stop := x / t.bars += 1 sets it -- also through a call, pivots.get(0).price := x. Objects are references, as in TradingView: every name holding one sees a change made through any of them, copy() (or Trade.copy(t)) makes a new one holding the same values. var Trade t = na keeps an object from bar to bar, na(t) tests it, a field of an na object reads na and setting one stops the backtest with an error. Objects go into functions and come out of them, method update(Trade this, float price) => ... is called as t.update(close) (a method ending with an if or a change is a statement), array.new<Trade>() holds objects (size, get, set, push, pop, shift, unshift, insert, remove, clear, copy, slice, first, last, reverse, concat, fill; for p in pivots). An entry reads a field where the script reads it -- after the lines above it on that bar, as in TradingView. Text in a field is compared with == / != (and goes into maps): text in quotes, a name holding it or an input.string -- text computed on the bar (str.tostring, syminfo.ticker) can't be stored, nor written into a log line. Fields holding a colour or a drawing (line, label, box, chart.point) are kept nowhere: drawings are ignored. A robot replays a script with objects from the start on every tick (an object changes in place, a snapshot can't hold it), as with arrays. History, as in TradingView: t[1] is the object the variable held a bar back -- the same one for a var changed in place, so t[1].stop reads its stop as it is now; t.stop[1] is the field's value as the script read it there a bar back (on the last bar it got there, inside an if block); the same for a value read out of a map or a matrix, m.get(key)[1]. A field may hold an enum's member. Not yet: history of an object or a field inside a function or a loop (read it at the top level into a variable), == between objects, array.sum/sort/includes & co. on an array of objects, request.security reading a field, a field read of a parameter written without its type (write f(Trade t)) |
| map.* (map.new<string, float>(), m.put(k, v), m.get(k), for [k, v] in m) | supported | keys are numbers, true/false, an enum's members or text (in quotes, a name holding text chosen between texts in quotes, an input.string); values are numbers, true/false, text, arrays or objects of a type. put (gives the value the key had, na if none), get (na for a missing key), contains, remove, size, keys and values (new arrays, in the order the keys were first put), clear, copy, put_all -- as functions or methods. var keeps a map from bar to bar, else it's made anew on every bar; for [key, value] in m goes over it in the order the keys were first put; an entry reads a map where the script reads it. At most 50,000 keys, as in TradingView. A robot replays a script with a map from the start on every tick, as with arrays. Not yet: text keys computed on the bar (str.tostring(close), syminfo.ticker) |
| matrix.* (matrix.new<float>(rows, columns, initial), m.get(i, j), m.set(i, j, x)) | supported | matrices of numbers or true/false (matrix<float>, matrix<int>, matrix<bool>): new, get, set, rows, columns, elements_count, row and col (new arrays), add_row and add_col (with an array of values or na), remove_row and remove_col (give the removed values), fill (with from_row/to_row/from_column/to_column), copy, submatrix, transpose, reverse, reshape, concat, swap_rows, swap_columns, sort (by a column, order.ascending / order.descending), sum and diff (a matrix or a number), mult (a matrix, an array or a number), pow, kron, avg, max, min, median, mode, trace, det, inv, is_square, is_zero, is_identity, is_symmetric, is_diagonal, is_binary -- as functions or methods, named arguments too. var keeps a matrix from bar to bar, else it's made anew on every bar; an index outside the matrix stops the backtest with an error, an na index of get() reads na; statistics skip na; inv of a singular matrix stops the backtest, as in PyneCore. At most 100,000 elements. A robot replays a script with a matrix from the start on every tick, as with arrays. Not yet: matrices of text, objects or drawings, for row in m (loop over m.rows()), eigenvalues, eigenvectors, pinv, rank and the other is_* checks |
| enum (enum Mode, Mode.fast, input.enum(Mode.fast, "Mode")) | supported | members with or without a title (fast = "Fast MA"; without one the title is the member's name); == and != between members of the same enum, var / := of an enum type (var Mode m = Mode.fast), enum fields of a type, enum parameters (f(Mode m) => ...), map<Mode, float> keys, array<Mode>, switch over a member. str.tostring(member) -- and a member in str.format or log.info -- writes its title. input.enum is a select of the members, by their titles (or of its options=), in the Parameters tab: a comparison with it is decided when compiling (also inside a function it's passed to), so mode == Mode.fast ? ta.ema(...) : ta.sma(...) or switch mode picks its branch before anything runs -- another member compiles the script again with it. Comparing a member with a number or with another enum's, or < / >, is an error, as in TradingView. A robot resumes an enum from a snapshot like any number |
| ?:, and / or / not, arithmetic, comparisons | supported | a ta.* call inside a ?: branch runs on every bar in QTrader (TradingView only on the bars that branch is taken) -- a warning says so; identical when the condition is decided when compiling (an input.string comparison) |
| history: close[1] | supported | any price series, ta.* result, var variable, or arithmetic and comparisons of them can be indexed -- (close - open)[1], (close > open)[2], an inlined function's value; the offset may be an input.int (close[length]) or an input.int plus or minus a whole number (close[length - 1], as in Ichimoku's displaced spans) or a value computed on the bar -- a loop's counter or a var variable (close[i]); only past bars (offset ≥ 0) are available |
| ta.* functions (see the table below) | supported | the ta.* functions listed on this page. A length may be a number, an input.int or arithmetic of numbers and inputs -- length / 2, math.round(math.sqrt(length)), int(length * 1.5) -- computed for the run's parameters with its fraction dropped (a Hull MA written out by hand works); a length computed on the bar is an error. ta.kc / ta.kcw take useTrueRange=true (their default); false is not supported yet |
| [a, b, c] = ta.macd(...) tuple assignment | supported | unpacks a multi-result ta.* call (ta.macd, ta.bb, ta.kc, ta.dmi, ta.supertrend); use _ to skip an output, only at the top level of the script |
| arithmetic ta.* sources and values, e.g. ta.sma(close - open, 10) | supported | the source (and value) argument of a ta.* call can be a price series, a ta.* result, or arithmetic of them -- numbers, input parameters, + - * / %, unary -, math.* functions, nz(x[, y]), and history [..] (including on a name bound to arithmetic, e.g. ta.sma(diff[1], 5) after diff = close - open) -- computed as a whole array before the bar loop, not just a bare series/ta.*/name |
| math.* (abs, max, min, avg, round, floor, ceil, sign, sqrt, pow, exp, log, log10, round_to_mintick, trigonometry; math.pi, math.e) | supported | na in, na out; math.round_to_mintick(x) rounds to the price step, a half away from zero (1.005 -> 1.01) |
| plot, plotshape, plotchar, plotarrow, plotcandle, plotbar, bgcolor, barcolor, hline, fill, alertcondition, label.*, line.*, box.*, table.*, linefill.*, polyline.* | ignored | in a strategy the calls are ignored, and so are variables holding a drawing (var label lbl = na, lbl := label.new(...), var table t = table.new(...)): QTrader draws the trades and every ta.* line the script computes by itself; an indicator(...) draws its plot() and hline() lines (see indicator(...) scripts) and ignores the rest, fill included -- the chart has no shading between two lines yet |
| alert(...) | ignored | QTrader does not send alerts yet |
| na, is_na(x)/na(x), nz(x)/nz(x, y) | supported | na is the missing-data value; any comparison with na, including na == na, is false, matching TradingView. is_na(x) (Pine: na(x)) tests for it. not na(x) and x == true also work as the condition of ta.barssince / ta.valuewhen; fixnan(x) is the last value of x that wasn't na. int(x) drops the fraction (na stays na), float(x) is x. nz(x) / nz(x, y) substitutes a fallback (default 0) when x is na, and is also usable inside an arithmetic ta.* source or value expression, e.g. ta.sma(nz(close - close[1], 0), 10) |
| time, bar_index, year, month, dayofmonth, dayofweek (and dayofweek.sunday … saturday), hour, minute, timestamp(...) | supported | calendar fields are UTC (a crypto exchange's time in TradingView); bar_index counts the bars loaded for the backtest, warm-up included, so it starts lower than TradingView's; timestamp takes numbers (inputs too), a leading UTC or fixed-offset zone like "GMT+3", or one date string like "2024-03-01" -- named zones like "America/New_York" aren't supported yet |
| hlcc4, second | supported | hlcc4 is (high + low + close + close) / 4; second is always 0 — bars are a minute or longer |
| timeframe.isintraday, isdaily, isweekly, ismonthly, isdwm, isminutes, multiplier, timeframe.in_seconds(...), timeframe.change(tf), timeframe.period == "60"; syminfo.pointvalue, minmove, pricescale | supported | read off the chart's bar length (time_close - time), so the same code follows the timeframe it runs on; timeframe.in_seconds("240") is a timeframe string's seconds; timeframe.period itself is text -- compare it, or pass it to request.security. A crypto market's point is worth 1 (syminfo.pointvalue, minmove 1, pricescale 1 / syminfo.mintick). timeframe.change("D") is true on the first bar of each day (UTC; "W" from Monday 00:00, "M" from the 1st, or a timeframe that divides a day like "60" or "240") -- false on the first bar and when the chart's bar is longer than tf; "3D", "2W" and "7" are errors |
| last_bar_index, time_close, timenow | supported | last_bar_index is the last loaded bar's bar_index (warm-up included); time_close is the bar's open time plus one bar; timenow is the last loaded bar's close time -- in a backtest that's the end of the period, for a live robot it's now |
| time(timeframe, session[, timezone]), time_close(...), hour(time[, tz]), minute(...), dayofweek(...), input.session | supported | session filters: time(timeframe.period, "0930-1600") is na outside the session ("2200-0400" overnight, several with commas, ":23456" for weekdays 1 = Sunday … 7 = Saturday, "24x7"), in UTC or a fixed offset like "GMT-5"; time("D") is the start of the bar's day, so ta.change(time("D")) marks a new day; input.session is a text field in the Parameters tab, checked as HHMM-HHMM (several with commas, optionally :days) before it's used |
| strategy.opentrades, strategy.initial_capital, strategy.max_drawdown, strategy.max_drawdown_percent, input.price | supported | strategy.opentrades is the number of open trades: the lots of a position built with pyramiding or strategy.order, else 1 while a position is open (a robot started before engine version 4: 1 while in a position, whatever its lots); strategy.opentrades.entry_price(n) and the other strategy.opentrades.*(n) are trade n's (0 the oldest), na when there is none -- before engine version 4, entry_price(n) and entry_bar_index(n) were the position's whatever n, and an error with pyramiding. strategy.position_size[1], position_avg_price[1], opentrades[1], equity[1], netprofit[1], closedtrades[1] & co. read the value the script saw k bars back -- strategy.position_size[1] == 0 marks the bar after an entry filled; strategy.initial_capital is the run's capital (known on warm-up bars too); strategy.max_drawdown / max_drawdown_percent are TradingView's: from the peak of the closed trades' equity down to the open position's worst price within a bar, in money / percent of that peak; input.price is a number parameter |
| barstate.isconfirmed, ishistory, isnew, isrealtime, isfirst, islast | supported | on a backtest's bars: confirmed, history and new are true, realtime false; isfirst is the first loaded bar, islast the last -- a live robot also runs on closed bars |
| strategy.risk.allow_entry_in(strategy.direction.long | short | all) | supported | entries open positions on that side only: with long, a strategy.entry short opens nothing while flat and closes the long instead of reversing it (an entry at a price closes it where the price is reached) -- TradingView's 'long exit trades instead of reverse trades' -- and a strategy.order short only takes from the long; short is the mirror. At the top level (inside an if it is ignored with a warning; called twice, the last call counts); the direction may be chosen by an input.string (dir == "Long" ? strategy.direction.long : strategy.direction.all). A robot started before engine version 3 ignores it with a warning: Start again to use it |
| strategy.risk.max_drawdown, max_intraday_loss and the other risk limits | ignored | risk limits in the code are ignored with a warning |
| a var / := value an order reads and the script changes after the order on the same bar | supported | as in TradingView, a strategy.entry / close / close_all / order reads the script's variables as they are at its line -- if not tradedToday / strategy.entry(...) / tradedToday := true trades once a day; its qty= and qty_percent= too. A robot started before engine version 3 keeps deciding such an order with the values at the end of the bar (it never fires in that example), with a warning naming the order and the variable: Start again to switch |
| strategy.order(id, strategy.long | strategy.short, qty, limit=, stop=) | supported | a market order that adds to or takes from the position, as in TradingView: a buy adds a trade to a long (beyond pyramiding) or opens one, and takes qty from a short, oldest trades first -- past zero the rest opens a long, no reversal of its own; without qty it is sized as an entry. It fills at the next open (with process_orders_on_close, at the close), before the bar's strategy.entry/close, which then act on what it left; strategy.close_all closes what it opened, and from engine version 4 strategy.close(id) of the order's id does, when that id is the only one its side opens with (with several, closing only one id's trades is not supported yet: an error). From engine version 5, limit= or stop= makes it an order at a price: placed where the call is reached (its price rounded to syminfo.mintick), replaced by the next call of its id, waiting until the price reaches it -- several of a bar fill in the order the bar's path reaches them, after the bar's stops and targets -- and dropped by strategy.cancel(id) / cancel_all; an na price makes it a market order, as in TradingView; the script sees the fill at the bar's close (strategy.position_size, position_avg_price, opentrades). Not yet: both limit= and stop= (a stop-limit order), one id at market and at a price, and together with strategy.entry at a price. Backtests only: a live robot refuses it, as pyramiding; a robot started before engine version 3 never had it (it was an error) |
| strategy.closedtrades.*(n), strategy.opentrades.*(n), strategy.closedtrades.first_index | supported | the script's list of trades, as TradingView's strategy sees it on each bar: a trade closed on a bar's path (an order at the open, a stop, a target) is in the list on that bar, one filled at the close (process_orders_on_close) on the next. Closed trades: entry_price, exit_price, entry_bar_index, exit_bar_index, entry_time, exit_time, profit (after both fees), profit_percent (of the entry's value plus its fee), size (negative for a short), commission, max_runup, max_drawdown and their _percent -- the best and worst profit on a bar's high or low while it was open; open trades: entry_price, entry_bar_index, entry_time, size, profit and profit_percent at the bar's close (the exit fee estimated), commission, max_runup, max_drawdown. n is cut to a whole number as int() does; a trade that doesn't exist gives na for a price, a time or a bar index and 0 for the rest; the latest 9,000 closed trades are kept (first_index). Each lot of a pyramided position is a trade; a partial close splits one, its fees and excursions shared by size. entry_id(n) compares with an id -- strategy.closedtrades.entry_id(n) == "Long" -- told by the trade's side, when that id is the only one its side enters with. From engine version 5 strategy.closedtrades.exit_id(n), exit_comment(n), entry_comment(n) and strategy.opentrades.entry_comment(n) compare with text (== and !=), and work in na(), str.contains, str.startswith and str.endswith -- told by the trade's side and what closed it, with TradingView's texts: a strategy.exit's id and its comment_loss / comment_profit / comment_trailing (else comment), "Close entry(s) order L" for strategy.close("L"), "Close position order" for close_all, the entry's id for a reversal, the order's id for a strategy.order; when two texts can close a trade the same way (two strategy.close ids on one side, a comment computed on the bar) the comparison is an error, and the text itself can't be a value (a variable, a log line). A robot whose code reads the list is replayed from its start on every tick (its snapshot would carry every trade) |
| a variable computed from an array, a map, an object or a var after the script changed it on the bar; an if block's old = history.shift() | supported | as in TradingView, the script runs in order: total = m.get(1) or y = s * 2 after s := s + 1 is this bar's value where a := reads it, and an if block's variable set by a call that changes the array (shift, pop, remove...) calls it once, when the block runs. A robot started before engine version 4 keeps the old translation -- the previous bar's value there, and the call made at every read and on every bar -- until it is started again |
| import, renko and other chart types, request.security_lower_tf | unsupported | not supported: each is a compile error saying why and what to use instead -- import: a TradingView library's code lives on TradingView, where QTrader can't read it: paste the functions you use into the script; request.security_lower_tf: QTrader doesn't keep the bars of shorter timeframes for every market and period, use request.security with the chart's timeframe or a longer one; Renko, Kagi, Line Break and Point & Figure: no such bars |
| request.security(...) | supported | this chart's symbol (syminfo.tickerid) on a longer timeframe -- minutes like "240", "D", "W", "M" or an input.timeframe; the value is computed on the chart's candles merged into the longer bars and, as TradingView does by default, a chart bar sees a longer bar's value once that bar has closed; lookahead=barmerge.lookahead_on with expr[1] works too. Another market works as well, on the chart's timeframe or a longer one -- any ticker of the catalog, e.g. "BINANCE:BTCUSDT", "BYBIT:ETHUSDT.P" (perpetual), "OKX:SOLUSDT.P"; a bare symbol is Binance spot -- a live robot may get its newest bar a bar late. [h, l] = request.security(syminfo.tickerid, "D", [high, low]) -- or of a function ending with [a, b] -- is one request per value. From engine version 5 the symbol can be ticker.heikinashi(syminfo.tickerid) -- or of another market, also through a variable -- the value is then computed on Heikin Ashi bars of the requested timeframe (built from its own bars, as TradingView does), e.g. [o, c] = request.security(ticker.heikinashi(syminfo.tickerid), "240", [open, close]). Not yet: gaps=barmerge.gaps_on, a shorter timeframe than the chart's |
| market_data.<key> | supported | the Market data series as in Python, read as a series: fg = market_data.fear_n_greed, with history fg[1], na(fg), ta.* over it and plot(fg); a series of several values is unpacked, [liq_long, liq_short] = market_data.liquidations. Up to 3 series on a free account; not inside request.security |
| process_orders_on_close=true | supported | a signal fills at its own bar's close; the signal on the last bar stays pending, as a live robot sends it |
| strategy(pyramiding=N) | supported | up to N entries in one direction: each further entry signal while the position is open adds one, sized as strategy()'s default size (fixed contracts, cash, or percent of the equity, cut to what is left), each with its own stop/target from its own fill and each a trade of its own; strategy.position_avg_price is their average. Backtests only: a live robot refuses pyramiding for now. Not combined with entries at a price (stop=/limit=) yet |
| indicator(...) scripts (v4: study(...)) | supported | Backtest draws the lines the script plot()s and makes no trades -- the Notes tab says so. Each line is named by its plot title, else by the variable it plots, else by its call; with overlay=false (TradingView's default) every line goes to the indicator's own pane under the candles, named after its short title, with overlay=true each line sits where a strategy's would. Any number series is drawn: a ta.* result or request.security value, a price, arithmetic (plot(fast - slow), plot(close * 2)) or a var/:= value -- an untitled one is named by its expression; plot()'s colour, style and width are TradingView's look (the legend sets the chart's own) and offset= is ignored with a warning. hline(price, title) draws a dashed horizontal line at a number, an input or arithmetic of them (one at a series is a warning, as TradingView refuses it), in the indicator's pane -- with overlay=true over the candles when the level is on their scale, else by the indicator's first line under them; its colour and line style are ignored. fill(), plotshape, bgcolor and the other drawing calls are ignored with a warning. indicator()'s other arguments are accepted and ignored (timeframe= with a warning: use request.security). strategy.* calls and values are errors in an indicator, as in TradingView; an indicator can't run as a robot or be converted to Python |
| log.info / log.warning / log.error (Pine Logs) | supported | each call writes a line with its bar's time where the script reaches it -- in if/else, loops and functions alike -- to the backtest's Logs tab and the robot's; the message is text in quotes, + of texts, str.tostring(value[, "#.##"-style pattern]), str.format("{0} {1,number,#.##}", ...) or log.info(format, values...), and text ?: text; string variables, other str.* functions and the format.* constants (format.mintick) are not supported yet -- give a pattern |