The time a closed trade was exited, as a UNIX timestamp in milliseconds.
strategy.closedtrades.exit_time(trade_num) returns the time of the bar the closing order filled on, in milliseconds since 1970-01-01 UTC.
Subtract strategy.closedtrades.entry_time to get the holding time in milliseconds.
Syntax
strategy.closedtrades.exit_time(trade_num: series int) -> series intArguments
| Name | Type | Default | Description |
|---|---|---|---|
| trade_num | series int | required | Zero-based index of the closed trade. 0 is the first trade the strategy closed and strategy.closedtrades - 1 is the most recent. |
Returns
series int: The open time of the exit bar as a UNIX timestamp in milliseconds. na when the trade does not exist.
Remarks
- Returns na when trade_num is negative, is not below
strategy.closedtrades, or points at a trade that has dropped out of the history (seestrategy.closedtrades.first_index). - On intraday charts both times carry the bar's open time, so a trade held inside one bar returns equal entry and exit times.
Example
//@version=6
strategy("Hours held", overlay = false)
fast = ta.sma(close, 10)
slow = ta.sma(close, 30)
if ta.crossover(fast, slow)
strategy.entry("Long", strategy.long)
if ta.crossunder(fast, slow)
strategy.close("Long")
n = strategy.closedtrades - 1
hours = n >= 0 ? (strategy.closedtrades.exit_time(n) - strategy.closedtrades.entry_time(n)) / 3600000 : na
plot(hours, "Last trade, hours", color.blue, style = plot.style_stepline)See also
Runs on Sidechair