Appearance
Declarations
How does a script say what it is? Its first statement declares it: indicator() for a study that plots, strategy() for one that trades on the backtester, or library() for functions other scripts import. The declaration names the script and sets where it draws, how many drawings it keeps and, for a strategy, how its account works.
pine
//@version=6
strategy("Breakout", overlay = true, initial_capital = 10000,
default_qty_type = strategy.percent_of_equity, default_qty_value = 100,
commission_value = 0.1, slippage = 2)
float upper = ta.highest(high, 20)[1]
if close > upper and strategy.position_size == 0
strategy.entry("Long", strategy.long)
if close < ta.lowest(low, 10)[1]
strategy.close("Long")
plot(upper, "Upper band")indicator
pine
indicator(title, shorttitle, overlay, format, precision, scale, max_bars_back, timeframe, timeframe_gaps, explicit_plot_zorder, max_lines_count, max_labels_count, max_boxes_count, calc_bars_count, max_polylines_count, dynamic_requests, behind_chart, warmup) → voidDeclares a study that plots, draws or computes, with no orders.
| Parameter | Default | Description |
|---|---|---|
titleconst string | The name the chart's legend and the study list show. | |
shorttitleconst string | Accepted. The legend shows title, and shorttitle stands in only when title is left out. | |
overlayconst bool | false | true draws on the price pane, and false in a pane of its own. |
formatconst string | format.inherit | How the study's values read, unless a plot sets its own: format.price, format.percent, format.volume or format.mintick. See plot. |
precisionconst int | The decimals the study's values show. Left out, the symbol's own. | |
scaleNo effect hereconst scale_type | Accepted, and changes nothing. | |
max_bars_backNo effect hereconst int | Accepted, and changes nothing: every bar keeps its history. | |
timeframeNo effect hereconst string | Accepted, and changes nothing. A study runs on the chart's own timeframe here. To read another, use request.security. | |
timeframe_gapsNo effect hereconst bool | Accepted, and changes nothing. | |
explicit_plot_zorderconst bool | false | true stacks plots, lines and fills in the order the script writes them. |
max_lines_countconst int | 50 | How many lines stay drawn, the newest. |
max_labels_countconst int | 50 | How many labels stay drawn, the newest. |
max_boxes_countconst int | 50 | How many boxes stay drawn, the newest. |
calc_bars_countconst int | Changes nothing, since every bar runs. Leak-safe AmenoScript refuses it, because a run that started where its data ends would read otherwise once more data came. | |
max_polylines_countconst int | 50 | How many polylines stay drawn, the newest. |
dynamic_requestsNo effect hereconst bool | true | Accepted. Requests may always sit in loops and branches here. |
behind_chartconst bool | true | false draws an overlay in front of the candles. |
warmupAmenoScript onlyconst int | A whole number of bars: how much history the script's state needs before older bars stop mattering. Has no effect here. |
strategy
pine
strategy(title, shorttitle, overlay, format, precision, scale, pyramiding, calc_on_order_fills, calc_on_every_tick, max_bars_back, backtest_fill_limits_assumption, default_qty_type, default_qty_value, initial_capital, currency, slippage, commission_type, commission_value, process_orders_on_close, close_entries_rule, margin_long, margin_short, explicit_plot_zorder, max_lines_count, max_labels_count, max_boxes_count, calc_bars_count, risk_free_rate, use_bar_magnifier, fill_orders_on_standard_ohlc, max_polylines_count, dynamic_requests, behind_chart, warmup, qty_step, close_on_end_of_data) → voidDeclares a strategy: a study whose orders the backtester fills, with the account its arguments describe.
The account's arguments are read once, on the first bar. How the emulator fills each order is on How a strategy fills.
A strategy with no overlay draws on the price pane here
This engine reads a missing overlay as true for strategy(). TradingView's default is false, which puts the strategy's plots in a pane of their own. Write overlay out if the pane matters.
| Parameter | Default | Description |
|---|---|---|
titleconst string | The name the chart's legend, the study list and the Strategy Tester show. | |
shorttitleconst string | Accepted. It stands in only when title is left out. | |
overlayconst bool | true | true draws on the price pane, and false in a pane of its own. |
formatconst string | format.inherit | How the strategy's values read, unless a plot sets its own. |
precisionconst int | The decimals its values show. Left out, the symbol's own. | |
scaleNo effect hereconst scale_type | Accepted, and changes nothing. | |
pyramidingconst int | 0 | How many entries may stack in one direction. 0 and 1 both allow one. See sizes. |
calc_on_order_fillsNo effect hereconst bool | false | Accepted on history, where a run happens once a bar. Leak-safe AmenoScript refuses true. |
calc_on_every_tickconst bool | false | true runs the script on every update of a live bar. Leak-safe AmenoScript refuses true. See when your script runs. |
max_bars_backNo effect hereconst int | Accepted, and changes nothing. | |
backtest_fill_limits_assumptionNo effect hereconst int | 0 | Accepted, and changes nothing: a limit fills when the price touches it. |
default_qty_typeconst string | strategy.fixed | How an order with no qty is sized: strategy.fixed units, strategy.cash money, or strategy.percent_of_equity. |
default_qty_valueconst int/float | 1 | The units, money or percent that default_qty_type sizes with. |
initial_capitalconst int/float | 1000000 | The money the account starts with. |
currencyNo effect hereconst string | currency.NONE | Accepted. Amounts stay in the symbol's currency. |
slippageconst int | 0 | Ticks a market order, a stop and a trailing stop fill against you. A limit never slips. See slippage. |
commission_typeconst string | strategy.commission.percent | strategy.commission.percent, strategy.commission.cash_per_contract or strategy.commission.cash_per_order. |
commission_valueconst int/float | 0 | The commission, in the type's unit. |
process_orders_on_closeconst bool | false | true fills a market order at the close that placed it. See at the close. |
close_entries_ruleconst string | "FIFO" | "FIFO" closes the oldest lot first, whichever entry an order names. "ANY" closes the lots the order names. |
margin_longconst int/float | 100 | The percent of a long's value that equity must cover. 0 turns margin off. See margin. |
margin_shortconst int/float | 100 | The same for a short. |
explicit_plot_zorderconst bool | false | true stacks plots, lines and fills in the order the script writes them. |
max_lines_countconst int | 50 | How many lines stay drawn, the newest. |
max_labels_countconst int | 50 | How many labels stay drawn, the newest. |
max_boxes_countconst int | 50 | How many boxes stay drawn, the newest. |
calc_bars_countconst int | 0 | Changes nothing, since every bar runs. Leak-safe AmenoScript refuses it. |
risk_free_rateconst int/float | 2 | A percent a year, taken off before the Sharpe and Sortino ratios. See the report. |
use_bar_magnifierNo effect hereconst bool | false | Accepted, and changes nothing: fills read each bar's own four prices. |
fill_orders_on_standard_ohlcNo effect hereconst bool | false | Accepted, and changes nothing. |
max_polylines_countconst int | 50 | How many polylines stay drawn, the newest. |
dynamic_requestsNo effect hereconst bool | true | Accepted. Requests may always sit in loops and branches here. |
behind_chartconst bool | true | false draws an overlay in front of the candles. |
warmupAmenoScript onlyconst int | A whole number of bars: how much history the strategy's state needs. Has no effect here. | |
qty_stepAmenoScript onlyconst float | The step every size is floored to. Left out, whole units for shares, funds, futures and forex, and millionths for crypto. | |
close_on_end_of_dataAmenoScript onlyconst bool | true | true closes whatever is still open at the last bar's close, so the trade list is complete. false leaves it open. |
library
pine
library(title, overlay, dynamic_requests) → voidDeclares a library: functions, types and constants that other scripts bring in with import.
Mark what an importer may use with export. An importer gets the library's exported functions, types, enums and constants under its alias, and nothing else of the library runs there: its plots and its own library() call stay with the library. See imports.
| Parameter | Default | Description |
|---|---|---|
titleconst string | The library's name in the legend. An import doesn't read it: it finds the library by the name you saved it under in your script store. | |
overlayconst bool | false | Where the library's own plots draw when it runs on a chart. |
dynamic_requestsNo effect hereconst bool | true | Accepted. |