strategy - Pine Script Variable
strategy
Section titled “strategy”Overview
Section titled “Overview”Performance and position statistics for strategy scripts.
Fields
Section titled “Fields”| Field | Type | Description |
|---|---|---|
strategy.account_currency | simple string | Returns the currency used to calculate results, which can be set in the strategy’s properties. |
strategy.avg_losing_trade | series float | Returns 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_percent | series float | Returns the average percentage loss per losing trade. Calculated as the sum of loss percentages divided by the number of losing trades. |
strategy.avg_trade | series float | Returns 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_percent | series float | Returns 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_trade | series float | Returns 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_percent | series float | Returns the average percentage gain per winning trade. Calculated as the sum of profit percentages divided by the number of winning trades. |
strategy.closedtrades.first_index | series int | The 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.equity | series float | Current equity (strategy.initial_capital + strategy.netprofit + strategy.openprofit). |
strategy.eventrades | series int | Number of breakeven trades for the whole trading range. |
strategy.grossloss | series float | Total currency value of all completed losing trades. |
strategy.grossloss_percent | series float | The total value of all completed losing trades, expressed as a percentage of the initial capital. |
strategy.grossprofit | series float | Total currency value of all completed winning trades. |
strategy.grossprofit_percent | series float | The total currency value of all completed winning trades, expressed as a percentage of the initial capital. |
strategy.initial_capital | series float | The amount of initial capital set in the strategy properties. |
strategy.losstrades | series int | Number of unprofitable trades for the whole trading range. |
strategy.margin_liquidation_price | series float | When 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_all | series float | Maximum number of contracts/shares/lots/units in one trade for the whole trading range. |
strategy.max_contracts_held_long | series float | Maximum number of contracts/shares/lots/units in one long trade for the whole trading range. |
strategy.max_contracts_held_short | series float | Maximum number of contracts/shares/lots/units in one short trade for the whole trading range. |
strategy.max_drawdown | series float | Maximum equity drawdown value for the whole trading range. |
strategy.max_drawdown_percent | series float | The 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_runup | series float | Maximum equity run-up value for the whole trading range. |
strategy.max_runup_percent | series float | The 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.netprofit | series float | Total currency value of all completed trades. |
strategy.netprofit_percent | series float | The total value of all completed trades, expressed as a percentage of the initial capital. |
strategy.openprofit | series float | Current unrealized profit or loss for all open positions. |
strategy.openprofit_percent | series float | The current unrealized profit or loss for all open positions, expressed as a percentage and calculated by formula: openPL / realizedEquity * 100. |
strategy.opentrades.capital_held | series float | Returns the capital amount currently held by open trades. |
strategy.position_avg_price | series float | Average entry price of current market position. If the market position is flat, ‘NaN’ is returned. |
strategy.position_entry_name | series string | Name of the order that initially opened current market position. |
strategy.position_size | series float | Direction 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.wintrades | series int | Number of profitable trades for the whole trading range. |
Remarks
Section titled “Remarks”- Values are only available in
strategy()scripts and may benauntil trades are present. - Metrics update as bars complete on historical data. Use
barstate.isconfirmedto 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.
Example
Section titled “Example”//@version=6strategy("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)