> ## Documentation Index
> Fetch the complete documentation index at: https://gocharting.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Reading a strategy's results

> The strategy variables for position, equity and profit, and the functions that read single open and closed trades.

A strategy reads its simulated account through `strategy.*` variables, which update as orders fill, and through functions that look at one trade by number. Use them to size orders, plot equity or label results.

| Variable | Meaning |
| - | - |
| `strategy.position_size` | Net quantity: positive long, negative short, 0 flat. |
| `strategy.position_avg_price` | Average entry price of the open entries. |
| `strategy.initial_capital` | The `initial_capital` of `strategy()`. |
| `strategy.equity` | `initial_capital + netprofit + openprofit`. |
| `strategy.netprofit` | Profit of closed trades, after commission on every fill. |
| `strategy.openprofit` | Unrealized profit of the open entries. |
| `strategy.grossprofit`, `strategy.grossloss` | Sum of winning and of losing closed trades (the loss is negative, before commission). |
| `strategy.wintrades`, `strategy.losstrades` | Closed trades with profit above zero, and all others. |
| `strategy.max_drawdown`, `strategy.max_runup` | Largest fall from an equity peak, largest rise from an equity low. |
| `strategy.opentrades`, `strategy.closedtrades` | Counts. Closing part of an entry counts one closed trade. |
| `strategy.account_currency` | The instrument's currency. |

All are series floats except the counts (ints) and `account_currency` (string).

## One trade at a time

Trade functions take a zero-based `trade_num` and return `na` when there is no such trade. Open trades are `0` to `strategy.opentrades - 1`, oldest first. Closed trades are numbered from the first ever closed, so the latest is `strategy.closedtrades - 1`; only the latest 1000 are kept.

* `strategy.opentrades_` followed by `entry_id`, `entry_price`, `size`, `profit`, `entry_bar_index`, `entry_time`, `entry_comment`, `max_drawdown` or `max_runup`: `strategy.opentrades_profit(0)`.
* `strategy.closedtrades_` followed by the same names, plus `exit_price`, `exit_bar_index`, `exit_time` and `commission`.

`_entry_bar_index` is the bar the order was placed on. A default market order fills on the next bar's open, so bars since entry are `bar_index - strategy.opentrades_entry_bar_index(0) - 1` (no `- 1` with `process_orders_on_close=true`). For a closed trade `exit_bar_index`, `max_drawdown` and `max_runup` always return 0 (they are not recorded); only the open-trade excursions are tracked. `_size` is unsigned; the open position's direction is the sign of `strategy.position_size`, and a closed trade's direction you keep yourself. Times are in milliseconds.

> [!WARNING]
>
> GoCharting is a charting and analytics tool. This is not investment advice. Trading and investing carry a high risk of loss and are not suitable for everyone. You can lose some or all of your money.

> [!WARNING]
>
> These results are based on simulated or hypothetical performance that has inherent limitations. They do not represent actual trading and were not executed, and may under- or over-compensate for market factors such as liquidity. Simulated results are designed with the benefit of hindsight. No representation is made that any account will or is likely to achieve similar profits or losses.

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
strategy("Equity and last trade", initial_capital=10000)
if talib.crossover(close, talib.sma(close, 20)) {
    strategy.entry("Long", strategy.long)
}
if talib.crossunder(close, talib.sma(close, 20)) {
    strategy.close("Long")
}
if barstate.islast and strategy.closedtrades > 0 {
    lastTrade = strategy.closedtrades - 1
    label.new(bar_index, close, text="Last trade: " + str.tostring(strategy.closedtrades_profit(lastTrade)))
}
plot(strategy.equity, title="Equity")
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.