indicator()
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,
max_polylines_count, dynamic_requests, behind_chart)
| Parameter | Type | Default | Meaning |
|---|---|---|---|
title |
const string | required | Appears in the chart legend and the publish-to-marketplace flow. |
shorttitle |
const string | title |
Used when space is tight (legend chip). |
overlay |
const bool | false |
true renders on the price pane; false opens a separate pane. |
format |
const | format.inherit |
Default label format for plots. format.price, format.volume, format.percent, format.mintick. |
precision |
const int | – | Default decimal places for plot labels. Overridden per plot(). |
scale |
const | scale.right |
scale.left, scale.right, scale.none (no own axis). |
max_bars_back |
const int | – | Accepted; the runtime always keeps the full loaded history (5,000 bars), so this is a no-op. |
timeframe |
const string | "" |
Forces the script to compute at this timeframe. See Timeframes. |
timeframe_gaps |
const bool | true |
When timeframe= is set, fill gaps between upstream bars with the previous value. |
explicit_plot_zorder |
const bool | false |
Honored implicitly — plots always draw in declaration order. |
max_lines_count |
const int | 500 |
Cap on live line.new() objects; the oldest is dropped silently beyond it. Range 1–500. |
max_labels_count |
const int | 500 |
Cap on live label.new() objects. Range 1–500. |
max_boxes_count |
const int | 500 |
Cap on live box.new() objects. Range 1–500. |
max_polylines_count |
const int | 100 |
Cap on live polyline.new() objects. Range 1–100. |
dynamic_requests |
const bool | true |
Enables request.* calls whose arguments vary per bar. |
behind_chart |
const bool | false |
true renders this indicator behind the price series. |
//@version=1
indicator("Smoothed RSI", "sRSI", overlay=false, precision=2, max_labels_count=200)
strategy()
A strategy is an indicator that can place orders:
strategy(title, shorttitle, overlay, format, precision, scale,
pyramiding, calc_on_order_fills, calc_on_every_tick,
max_bars_back, process_orders_on_close, close_entries_rule,
slippage, commission_type, commission_value,
default_qty_type, default_qty_value, initial_capital,
currency, use_bar_magnifier, fill_orders_on_standard_ohlc,
calc_on_every_history_tick, margin_long, margin_short,
max_lines_count, max_labels_count, max_boxes_count,
max_polylines_count)
The visual-related parameters mirror indicator(). Strategy-specific parameters:
| Parameter | Type / values | Default | Meaning |
|---|---|---|---|
pyramiding |
const int | 1 |
Max simultaneous same-direction entries. |
slippage |
const int (ticks) | 0 |
Points worsened on every market/stop fill. |
commission_type |
strategy.commission.percent / cash_per_contract / cash_per_order |
percent |
How commission_value is interpreted. |
commission_value |
const float | 0 |
Rate for the chosen model. |
default_qty_type |
strategy.fixed / strategy.cash / strategy.percent_of_equity |
fixed |
How default_qty_value sizes an entry when qty= is omitted. |
default_qty_value |
const float | 1 |
Size in the chosen units. |
initial_capital |
const float | 100000 |
Starting equity for the backtester. |
currency |
const | ignored | Accepted for compatibility; backtest reports in the symbol's currency. |
process_orders_on_close |
const bool | false |
false queues market orders to fill at the next bar's open (platform default); true fills at the signal bar's close. |
calc_on_every_tick |
const bool | false |
Recalculate on every live price update of the forming bar (orders can fill intrabar), not only at bar close. Historical bars still calculate once per bar unless calc_on_every_history_tick is set. |
calc_on_every_history_tick |
const bool | false |
ChartScript extension: replay historical bars tick-by-tick as well (bar OHLC path, or lower-timeframe bars with use_bar_magnifier) so backtests match the live every-tick behaviour. Slower. |
calc_on_order_fills |
const bool | false |
After an order fills, run the script once more on the same bar so logic reading strategy.position_size reacts immediately. |
use_bar_magnifier |
const bool | false |
Resolve limit / stop / trailing fills against lower-timeframe bars inside each chart bar instead of the assumed OHLC path. The backtester uses the finest timeframe available and falls back to coarser ones; the report lists the tiers used. |
fill_orders_on_standard_ohlc |
const bool | false |
On Heikin Ashi, Renko and other non-standard charts, fill at the real OHLC prices rather than the synthetic bar's. |
margin_long / margin_short |
const float (%) | 100 |
Percent of a position's value that equity must cover (100 = no leverage, 50 = 2×). Entries that cannot be funded are rejected; a margin call liquidates part of the position. The report shows margin calls and the smallest account size that avoids them. |
close_entries_rule |
"FIFO" / "ANY" |
FIFO |
Which entry a partial strategy.close / strategy.exit reduces first. |
risk_free_rate, backtest_fill_limits_assumption |
const | – | Accepted for compatibility. |
//@version=1
strategy("SMA cross", overlay=true,
initial_capital=100000,
default_qty_type=strategy.cash,
default_qty_value=10000,
commission_type=strategy.commission.percent, commission_value=0.05,
slippage=1, process_orders_on_close=false)
See Strategies for the full picture, including strategy.risk.*.
library()
library(title, overlay, dynamic_requests)
| Parameter | Type | Default | Meaning |
|---|---|---|---|
title |
const string | required | The import name. Must match [A-Za-z0-9_]+ because it rides the import path (owner/Name/version). |
overlay |
const bool | false |
Advisory only; a library has no plots of its own. |
dynamic_requests |
const bool | true |
Allow request.* calls inside exported functions. |
A library must export at least one function, type, or enum:
//@version=1
library("MyMa")
export smooth(float source, int length) =>
ta.ema(source, length)
See Libraries for publishing and importing.
Property restrictions
- Every argument to a declaration statement must be a const value — a literal, a
color.*/shape.*/strategy.*member, or a value computed only from other const operands. - No
input.*()call may feed a declaration — the dialog does not exist yet when the declaration runs. - Only one declaration statement is allowed per script; the compiler rejects a second as "Script already declared".
See also
- Script structure — where the declaration sits
- Strategies — order-management semantics and risk limits
- Libraries — exporting and importing