The time an open trade was entered, as a UNIX timestamp in milliseconds.
strategy.opentrades.entry_time(trade_num) returns the time of the bar the entry filled on, in milliseconds since 1970-01-01 UTC, the same unit as time.
Subtract it from time or timenow for how long the trade has been open.
Syntax
strategy.opentrades.entry_time(trade_num: series int) -> series intArguments
| Name | Type | Default | Description |
|---|---|---|---|
| trade_num | series int | required | Zero-based index of the open trade. 0 is the oldest open entry, the one a FIFO exit closes first, and strategy.opentrades - 1 is the newest. |
Returns
series int: The open time of the entry bar as a UNIX timestamp in milliseconds. na when the trade does not exist.
Remarks
- Returns na when trade_num is negative or is not below
strategy.opentrades, so guard every call with the open-trade count. - The value is in milliseconds. Divide by 1000 only if you need seconds.
Example
//@version=6
strategy("Days open", 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")
days = strategy.opentrades > 0 ? (time - strategy.opentrades.entry_time(0)) / 86400000 : na
plot(days, "Days open", color.blue, style = plot.style_linebr)See also
Runs on Sidechair