Function reference
Runnablestrategy.entry
strategy
Orders and the backtest's running statistics. Declare strategy() instead of indicator() to use them.
49 names from PineTS 0.11.1 · 10 with full entries
strategy.entry
Verifiedstrategy.entry(id, direction, qty, limit, stop, oca_name, oca_type, comment, alert_message)
Opens or adds to a position. An entry in the opposite direction reverses it.
| Argument | Type | Meaning |
|---|---|---|
| id | series string | Names the entry; exits refer to it. |
| direction | strategy_direction | strategy.long or strategy.short. |
//@version=6strategy("strategy.entry", overlay = true)if ta.crossover(ta.ema(close, 9), ta.ema(close, 21)) strategy.entry("Long", strategy.long)if ta.crossunder(ta.ema(close, 9), ta.ema(close, 21)) strategy.close("Long")strategy.exit
Verifiedstrategy.exit(id, from_entry, qty, qty_percent, profit, limit, loss, stop, trail_price, trail_points, trail_offset, …)
Attaches a take-profit and/or stop-loss to an entry. limit/stop are prices; profit/loss are ticks.
strategy.close
Verifiedstrategy.close(id, comment, qty, qty_percent, alert_message, immediately)
Closes the position from entry id at market.
strategy.close_all
Supportedstrategy.close_all(comment, alert_message, immediately)
Closes every open position.
strategy.order
Supportedstrategy.order(id, direction, qty, limit, stop, …)
A raw order without entry's reversal logic.
strategy.cancel
Supportedstrategy.cancel(id) · strategy.cancel_all()
Cancels pending orders.
strategy.position_size
Supportedstrategy.position_sizeCurrent position: positive long, negative short, 0 flat.
strategy.netprofit
Supportedstrategy.netprofitProfit of closed trades so far.
strategy.openprofit
Supportedstrategy.openprofitUnrealised profit of the open position.
strategy.equity
Supportedstrategy.equityInitial capital + net profit + open profit.
Everything else in strategy
Also implemented. These follow TradingView’s Pine v6 reference for their arguments.
- strategy.account_currencySupportedAccount currency configured in the strategy() declaration's `currency=`.
- strategy.avg_losing_tradeSupportedAverage loss across losing closed trades, returned as a POSITIVE number (Pine convention: average loss is unsigned).
- strategy.avg_losing_trade_percentSupportedAverage per-trade loss (as a SIGNED negative percent) across losing closed trades.
- strategy.avg_tradeSupportedAverage profit/loss across all closed trades (post-commission).
- strategy.avg_trade_percentSupportedAverage per-trade return as a percent.
- strategy.avg_winning_tradeSupportedAverage profit across winning closed trades.
- strategy.avg_winning_trade_percentSupportedAverage per-trade return (as a percent) across winning closed trades.
- strategy.cancel_allSupportedCancel all pending orders — entries AND exits, as on TradingView.
- strategy.cashSupportedConstant for order sizing type: cash Used in default_qty_type parameter
- strategy.closedtradesSupportedPine's `strategy.closedtrades` serves a dual role: - As a scalar: a series int count of closed trades.
- strategy.convert_to_accountSupportedConvert a value from the symbol's currency to the account currency.
- strategy.convert_to_symbolSupportedInverse of convert_to_account: from account currency → symbol currency.
- strategy.default_entry_qtySupportedReturns the qty that would be used for an entry at the given fill price, given the strategy's `default_qty_type` and `default_qty_value`.
- strategy.eventradesSupportedCount of breakeven (profit === 0) closed trades.
- strategy.fixedSupportedConstant for order sizing type: fixed Used in default_qty_type parameter
- strategy.grosslossSupportedTotal currency value of all completed losing trades, as a POSITIVE number (the absolute sum of losses).
- strategy.grossloss_percentSupportedstrategy.grossloss as a percent of initial capital.
- strategy.grossprofitSupportedTotal currency value of all completed winning trades (post-commission).
- strategy.grossprofit_percentSupportedstrategy.grossprofit as a percent of initial capital.
- strategy.initial_capitalSupportedThe initial capital configured on the strategy() declaration.
- strategy.longVerifiedConstant representing long direction
- strategy.losstradesSupportedCount of closed trades with profit < 0.
- strategy.margin_liquidation_priceSupportedPrice at which the current leveraged position would be force-liquidated.
- strategy.max_contracts_held_allSupportedPeak |position_size| seen across the run.
- strategy.max_contracts_held_longSupportedPeak long-side position_size seen.
- strategy.max_contracts_held_shortSupportedPeak |short-side position_size| seen.
- strategy.max_drawdownSupportedMaximum peak-to-trough equity drawdown over the whole run (currency).
- strategy.max_drawdown_percentSupportedMaximum drawdown percent.
- strategy.max_runupSupportedMaximum equity run-up over the whole run (currency).
- strategy.max_runup_percentSupportedMaximum equity run-up percent.
- strategy.netprofit_percentSupportedRealized net profit expressed as a percent of initial capital.
- strategy.openprofit_percentSupportedUnrealized P&L expressed as a percent of initial capital.
- strategy.opentradesSupportedPine's `strategy.opentrades` mirrors strategy.closedtrades' dual-role pattern — see that file's header for the rationale.
- strategy.percent_of_equityVerifiedConstant for order sizing type: percent_of_equity Used in default_qty_type parameter
- strategy.position_avg_priceSupportedWeighted-average entry price of the current open position.
- strategy.position_entry_nameSupportedId string of the entry that initially opened the current position.
- strategy.riskSupported`strategy.risk` is a nested namespace with 6 setter functions that configure pre-trade risk rules.
- strategy.shortVerifiedConstant representing short direction
- strategy.wintradesSupportedCount of closed trades with profit > 0.