Skip to main content
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. 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.
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.
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.