Bruce Ecurb
Bruce Ecurb

Reputation: 124

Get date of a candle

I'm trying to get the date of the last candle, but at the moment I get only the current date.

What I'm looking for is this data:

Year => 2022
Month => December
Day => 24

At this moment I get this values using:

year(timenow)
month(timenow)
dayofmonth(timenow)

But what I would like is getting this value based on last daily candle. If I use Bareplay, using timenow, the value doesn't change.

Upvotes: 0

Views: 3942

Answers (1)

G.Lebret
G.Lebret

Reputation: 3058

You should use the time function:

The time function returns the UNIX time of the current bar for the specified timeframe and session or NaN if the time point is out of session.

See: https://www.tradingview.com/pine-script-reference/v5/#fun_time

time(timeframe.period) will return you the time of the actual bar, not the time now. Then you can use year( ), month( ) and dayofthemonth( ) to retrieve your values.

Upvotes: 1

Related Questions