Skip to content

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) → void

Declares a study that plots, draws or computes, with no orders.

ParameterDefaultDescription
title
const string
The name the chart's legend and the study list show.
shorttitle
const string
Accepted. The legend shows title, and shorttitle stands in only when title is left out.
overlay
const bool
falsetrue draws on the price pane, and false in a pane of its own.
format
const string
format.inheritHow the study's values read, unless a plot sets its own: format.price, format.percent, format.volume or format.mintick. See plot.
precision
const int
The decimals the study's values show. Left out, the symbol's own.
scaleNo effect here
const scale_type
Accepted, and changes nothing.
max_bars_backNo effect here
const int
Accepted, and changes nothing: every bar keeps its history.
timeframeNo effect here
const string
Accepted, and changes nothing. A study runs on the chart's own timeframe here. To read another, use request.security.
timeframe_gapsNo effect here
const bool
Accepted, and changes nothing.
explicit_plot_zorder
const bool
falsetrue stacks plots, lines and fills in the order the script writes them.
max_lines_count
const int
50How many lines stay drawn, the newest.
max_labels_count
const int
50How many labels stay drawn, the newest.
max_boxes_count
const int
50How many boxes stay drawn, the newest.
calc_bars_count
const 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_count
const int
50How many polylines stay drawn, the newest.
dynamic_requestsNo effect here
const bool
trueAccepted. Requests may always sit in loops and branches here.
behind_chart
const bool
truefalse draws an overlay in front of the candles.
warmupAmenoScript only
const 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) → void

Declares 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.

ParameterDefaultDescription
title
const string
The name the chart's legend, the study list and the Strategy Tester show.
shorttitle
const string
Accepted. It stands in only when title is left out.
overlay
const bool
truetrue draws on the price pane, and false in a pane of its own.
format
const string
format.inheritHow the strategy's values read, unless a plot sets its own.
precision
const int
The decimals its values show. Left out, the symbol's own.
scaleNo effect here
const scale_type
Accepted, and changes nothing.
pyramiding
const int
0How many entries may stack in one direction. 0 and 1 both allow one. See sizes.
calc_on_order_fillsNo effect here
const bool
falseAccepted on history, where a run happens once a bar. Leak-safe AmenoScript refuses true.
calc_on_every_tick
const bool
falsetrue runs the script on every update of a live bar. Leak-safe AmenoScript refuses true. See when your script runs.
max_bars_backNo effect here
const int
Accepted, and changes nothing.
backtest_fill_limits_assumptionNo effect here
const int
0Accepted, and changes nothing: a limit fills when the price touches it.
default_qty_type
const string
strategy.fixedHow an order with no qty is sized: strategy.fixed units, strategy.cash money, or strategy.percent_of_equity.
default_qty_value
const int/float
1The units, money or percent that default_qty_type sizes with.
initial_capital
const int/float
1000000The money the account starts with.
currencyNo effect here
const string
currency.NONEAccepted. Amounts stay in the symbol's currency.
slippage
const int
0Ticks a market order, a stop and a trailing stop fill against you. A limit never slips. See slippage.
commission_type
const string
strategy.commission.percentstrategy.commission.percent, strategy.commission.cash_per_contract or strategy.commission.cash_per_order.
commission_value
const int/float
0The commission, in the type's unit.
process_orders_on_close
const bool
falsetrue fills a market order at the close that placed it. See at the close.
close_entries_rule
const string
"FIFO""FIFO" closes the oldest lot first, whichever entry an order names. "ANY" closes the lots the order names.
margin_long
const int/float
100The percent of a long's value that equity must cover. 0 turns margin off. See margin.
margin_short
const int/float
100The same for a short.
explicit_plot_zorder
const bool
falsetrue stacks plots, lines and fills in the order the script writes them.
max_lines_count
const int
50How many lines stay drawn, the newest.
max_labels_count
const int
50How many labels stay drawn, the newest.
max_boxes_count
const int
50How many boxes stay drawn, the newest.
calc_bars_count
const int
0Changes nothing, since every bar runs. Leak-safe AmenoScript refuses it.
risk_free_rate
const int/float
2A percent a year, taken off before the Sharpe and Sortino ratios. See the report.
use_bar_magnifierNo effect here
const bool
falseAccepted, and changes nothing: fills read each bar's own four prices.
fill_orders_on_standard_ohlcNo effect here
const bool
falseAccepted, and changes nothing.
max_polylines_count
const int
50How many polylines stay drawn, the newest.
dynamic_requestsNo effect here
const bool
trueAccepted. Requests may always sit in loops and branches here.
behind_chart
const bool
truefalse draws an overlay in front of the candles.
warmupAmenoScript only
const int
A whole number of bars: how much history the strategy's state needs. Has no effect here.
qty_stepAmenoScript only
const 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 only
const bool
truetrue 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) → void

Declares 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.

ParameterDefaultDescription
title
const 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.
overlay
const bool
falseWhere the library's own plots draw when it runs on a chart.
dynamic_requestsNo effect here
const bool
trueAccepted.

See also ​

AmenoScript is compatible with Pine Script v6. Pine Script is a trademark of TradingView, Inc., which has no part in AmenoScript.