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-basedtrade_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 byentry_id,entry_price,size,profit,entry_bar_index,entry_time,entry_comment,max_drawdownormax_runup:strategy.opentrades_profit(0).strategy.closedtrades_followed by the same names, plusexit_price,exit_bar_index,exit_timeandcommission.
_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.