Skip to content
TradequixDocsOpen the terminal
OverviewStart here, search, progress
  • Introduction
  • Quickstart
  • How a script runs
  • Types and qualifiers
  • Operators, conditionals and loops
  • Functions and methods
  • Objects and enums
  • Arrays, matrices and maps
  • Strings and colours
  • Time and sessions
  • Bar states
  • Plotting
  • Inputs
  • Technical analysis
  • Drawings and tables
  • Multiple timeframes
  • Strategies
  • Alerts in scripts
  • Repainting
  • The Pine editor
  • Indicator settings
  • Coming from TradingView
  • The data
  • Publish and sell
  • Catalogue and community
  • Your dashboard and earnings
  • Errors and debugging
  • Limits
  • Coverage
  • Built-in catalogue
  • Cookbook
  • Write Pine with AI
  • FAQ
  • Glossary
  • Cheat sheet
  • Function reference
  • Will it run here?
  • Error index
Function reference

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

Verified
strategy.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.

ArgumentTypeMeaning
idseries stringNames the entry; exits refer to it.
directionstrategy_directionstrategy.long or strategy.short.
Runnablestrategy.entry
1//@version=62strategy("strategy.entry", overlay = true)3if ta.crossover(ta.ema(close, 9), ta.ema(close, 21))4 strategy.entry("Long", strategy.long)5if ta.crossunder(ta.ema(close, 9), ta.ema(close, 21))6 strategy.close("Long")

strategy.exit

Verified
strategy.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

Verified
strategy.close(id, comment, qty, qty_percent, alert_message, immediately)

Closes the position from entry id at market.

strategy.close_all

Supported
strategy.close_all(comment, alert_message, immediately)

Closes every open position.

strategy.order

Supported
strategy.order(id, direction, qty, limit, stop, …)

A raw order without entry's reversal logic.

strategy.cancel

Supported
strategy.cancel(id)  ·  strategy.cancel_all()

Cancels pending orders.

strategy.position_size

Supported
strategy.position_size

Current position: positive long, negative short, 0 flat.

strategy.netprofit

Supported
strategy.netprofit

Profit of closed trades so far.

strategy.openprofit

Supported
strategy.openprofit

Unrealised profit of the open position.

strategy.equity

Supported
strategy.equity

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

On this page

  • strategy.entry
  • strategy.exit
  • strategy.close
  • strategy.close_all
  • strategy.order
  • strategy.cancel
  • strategy.position_size
  • strategy.netprofit
  • strategy.openprofit
  • strategy.equity
  • Everything else (39)