Sidechair

strategy.closedtrades.entry_time()

Browse the reference

The time a closed trade was entered, as a UNIX timestamp in milliseconds.

Try it in the editor

strategy.closedtrades.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 and timenow.

Format it with str.format_time, or feed it to hour, dayofweek and the other calendar functions with an explicit timezone, to study when your entries happen.

Syntax

Pine Script
strategy.closedtrades.entry_time(trade_num: series int) -> series int

Arguments

NameTypeDefaultDescription
trade_numseries intrequiredZero-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 entry 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 (see strategy.closedtrades.first_index).
  • The value is in milliseconds, the unit of time and timenow, so it can be subtracted from either directly.

Example

Pine ScriptWhen the last trade beganOpen in editor
//@version=6
strategy("Entry time", overlay = true)
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")
if barstate.islast and strategy.closedtrades > 0
    t = strategy.closedtrades.entry_time(strategy.closedtrades - 1)
    label.new(bar_index, high, "Last entry " + str.format_time(t, "yyyy-MM-dd HH:mm"))

See also

Runs on Sidechair