Skip to content
AlertaChartAlertaScript / docs
AlertaScript / strategy
On this pageSignatureParametersReturnsExampleNotes

Metadata / Reference

strategy

TradingView-compatible spelling: strategy, runs without warnings

Defines the script as a strategy and sets backtesting properties. Use as the single script header (do not combine with indicator/study headers).

strategy(title, shorttitle, overlay, initial_capital, default_qty_value, default_qty_type, currency, pyramiding, commission_type, commission_value, slippage, process_orders_on_close, calc_on_order_fills, calc_on_every_tick, close_entries_rule, margin_long, margin_short, max_lines_count, max_labels_count, max_boxes_count, max_polylines_count, max_bars_back, risk_free_rate, use_bar_magnifier, fill_orders_on_standard_ohlc, scale) → void

Parameters

NameTypeRequiredDefaultDescription
titlestringYes—Title of the strategy.
shorttitlestringNot specified—Short title.
overlayboolNot specifiedtrueOverlay on main chart.
initial_capitalnumberNot specified10000Backtest starting capital.
default_qty_valuenumberNot specified1Default position size.
default_qty_typestringNot specifiedstrategy.fixedDefault quantity type. Pine v6: strategy.fixed (default_qty_value contracts) | strategy.contracts | strategy.cash (default_qty_value of cash per entry) | strategy.percent_of_equity (default_qty_value % of equity per entry, sized at the signal bar's close).
currencystringNot specifiedcurrency.NONEAccount currency. currency.NONE (default) is the symbol's own currency (USDT on BTCUSDT); no FX conversion is applied.
pyramidingnumberNot specified0Maximum entries in same direction.
commission_typestringNot specifiedpercentCommission mode.
commission_valuenumberNot specified0Commission amount.
slippagenumberNot specified0Per-order slippage in ticks.
process_orders_on_closeboolNot specifiedfalsePine v6: fill market-on-close orders at the closing price of the same bar.
calc_on_order_fillsboolNot specifiedfalseAccepted for compatibility. The strategy is calculated once per bar; a fill does not trigger another calculation on the same bar.
calc_on_every_tickboolNot specifiedfalseAccepted for compatibility. On a live chart a strategy is recalculated while the bar forms whether or not this is set; historical bars are calculated once.
close_entries_rulestringNot specifiedFIFOHow stacked entries are unwound by exit-by-contract orders. FIFO (default) or ANY.
margin_longnumberNot specified100Required margin (%) for long positions, 0..100.
margin_shortnumberNot specified100Required margin (%) for short positions, 0..100.
max_lines_countnumberNot specified50Max live line.new objects (50..500).
max_labels_countnumberNot specified50Max live label.new objects (50..500).
max_boxes_countnumberNot specified50Max live box.new objects (50..500).
max_polylines_countnumberNot specified50Max live polyline.new objects (1..100).
max_bars_backnumberNot specified—Accepted for compatibility and has no effect: every bar of a series' history can be referenced.
risk_free_ratenumberNot specified2.0Accepted for compatibility; the Strategy Report has no Sharpe or Sortino ratio, so it changes nothing.
use_bar_magnifierboolNot specifiedfalseAccepted for compatibility. Fills are simulated on the chart's own bars (see the note on the order within a bar); lower-timeframe data is not used.
fill_orders_on_standard_ohlcboolNot specifiedfalseAccepted for compatibility: strategies always run and fill on the standard OHLC bars, also when the chart draws Heikin Ashi candles.
scalestringNot specified—Price scale the strategy is drawn against: scale.right, scale.left or scale.none. Named only here: listed last so positional arguments keep their places.

Returns

void

Example

strategy
strategy("Trend Strategy", overlay=true)if bar_index == 1  strategy.entry("Long", "long")

Notes

  • Only one script header is allowed: indicator OR strategy OR study.
  • Orders fill in the order the price reaches them within a bar, as on TradingView: market orders at the open (a close first, then an entry), then every resting limit, stop and trailing order along the path open → nearer extreme → farther extreme → close. An entry filled on the way arms the exits placed with it for the rest of that bar, and an exit filled on the way lets a resting entry fill later in the bar. A bar whose low is nearer the open than its high reaches a stop below the price before a target above it.
  • On a live chart the forming bar follows the path the price really took, so live fills match the order of the ticks. Each fill can fire the strategy's order-fill alert, also when it happened between two updates of the chart.

Names and aliases

Guides and navigation are localized. Built-in reference descriptions and code examples are maintained in English.

AlertaScript

No results found.

Search by name, alias, or keyword.