Skip to content
Algo Trade Analytics Docs

strategy - Pine Script Variable

Performance and position statistics for strategy scripts.

FieldTypeDescription
strategy.account_currencysimple stringReturns the currency used to calculate results, which can be set in the strategy’s properties.
strategy.avg_losing_tradeseries floatReturns the average amount of money lost per losing trade. Calculated as the sum of losses divided by the number of losing trades.
strategy.avg_losing_trade_percentseries floatReturns the average percentage loss per losing trade. Calculated as the sum of loss percentages divided by the number of losing trades.
strategy.avg_tradeseries floatReturns the average amount of money gained or lost per trade. Calculated as the sum of all profits and losses divided by the number of closed trades.
strategy.avg_trade_percentseries floatReturns the average percentage gain or loss per trade. Calculated as the sum of all profit and loss percentages divided by the number of closed trades.
strategy.avg_winning_tradeseries floatReturns the average amount of money gained per winning trade. Calculated as the sum of profits divided by the number of winning trades.
strategy.avg_winning_trade_percentseries floatReturns the average percentage gain per winning trade. Calculated as the sum of profit percentages divided by the number of winning trades.
strategy.closedtrades.first_indexseries intThe index, or trade number, of the first (oldest) trade listed in the List of Trades. This number is usually zero. If more trades than the allowed limit have been closed, the oldest trades are removed, and this number is the index of the oldest remaining trade.
strategy.equityseries floatCurrent equity (strategy.initial_capital + strategy.netprofit + strategy.openprofit).
strategy.eventradesseries intNumber of breakeven trades for the whole trading range.
strategy.grosslossseries floatTotal currency value of all completed losing trades.
strategy.grossloss_percentseries floatThe total value of all completed losing trades, expressed as a percentage of the initial capital.
strategy.grossprofitseries floatTotal currency value of all completed winning trades.
strategy.grossprofit_percentseries floatThe total currency value of all completed winning trades, expressed as a percentage of the initial capital.
strategy.initial_capitalseries floatThe amount of initial capital set in the strategy properties.
strategy.losstradesseries intNumber of unprofitable trades for the whole trading range.
strategy.margin_liquidation_priceseries floatWhen margin is used in a strategy, returns the price point where a simulated margin call will occur and liquidate enough of the position to meet the margin requirements.
strategy.max_contracts_held_allseries floatMaximum number of contracts/shares/lots/units in one trade for the whole trading range.
strategy.max_contracts_held_longseries floatMaximum number of contracts/shares/lots/units in one long trade for the whole trading range.
strategy.max_contracts_held_shortseries floatMaximum number of contracts/shares/lots/units in one short trade for the whole trading range.
strategy.max_drawdownseries floatMaximum equity drawdown value for the whole trading range.
strategy.max_drawdown_percentseries floatThe maximum equity drawdown value for the whole trading range, expressed as a percentage and calculated by formula: Lowest Value During Trade / (Entry Price x Quantity) * 100.
strategy.max_runupseries floatMaximum equity run-up value for the whole trading range.
strategy.max_runup_percentseries floatThe maximum equity run-up value for the whole trading range, expressed as a percentage and calculated by formula: Highest Value During Trade / (Entry Price x Quantity) * 100.
strategy.netprofitseries floatTotal currency value of all completed trades.
strategy.netprofit_percentseries floatThe total value of all completed trades, expressed as a percentage of the initial capital.
strategy.openprofitseries floatCurrent unrealized profit or loss for all open positions.
strategy.openprofit_percentseries floatThe current unrealized profit or loss for all open positions, expressed as a percentage and calculated by formula: openPL / realizedEquity * 100.
strategy.opentrades.capital_heldseries floatReturns the capital amount currently held by open trades.
strategy.position_avg_priceseries floatAverage entry price of current market position. If the market position is flat, ‘NaN’ is returned.
strategy.position_entry_nameseries stringName of the order that initially opened current market position.
strategy.position_sizeseries floatDirection and size of the current market position. If the value is > 0, the market position is long. If the value is < 0, the market position is short. The absolute value is the number of contracts/shares/lots/units in trade (position size).
strategy.wintradesseries intNumber of profitable trades for the whole trading range.
  • Values are only available in strategy() scripts and may be na until trades are present.
  • Metrics update as bars complete on historical data. Use barstate.isconfirmed to avoid partial-bar reads.
  • strategy.margin_liquidation_price: The variable returns na if the strategy does not use margin, i.e., the strategy declaration statement does not specify an argument for the margin_long or margin_short parameter.
  • strategy.opentrades.capital_held: This variable returns na if the strategy does not simulate funding trades with a portion of the hypothetical account, i.e., if the strategy function does not include nonzero margin_long or margin_short arguments.
//@version=6
strategy("Strategy snapshot", overlay=true, max_labels_count=1)
if barstate.islast
winRate = strategy.closedtrades > 0
? strategy.wintrades / strategy.closedtrades * 100
: na
label.new(bar_index, high,
text=str.format("Equity: {0}\nOpen trades: {1}\nWin rate: {2,number,#.##}%",
strategy.equity, strategy.opentrades, winRate),
style=label.style_label_left)