dorien
dorien

Reputation: 5387

Getting time of day of bar close

I would like to see if the bar close is 8am UTC (for every bar in a strategy) in pinescript.

I figure I can maybe use time_close (although that may not be dynamic). Since this returns a unix timestamp I am a bit at a loss on how to test if the close price was at 8amUTC or not. First step would be to extract time of day from the unix timestamp...

Upvotes: 0

Views: 1959

Answers (2)

dorien
dorien

Reputation: 5387

You can just use the built-in variable 'hour', which returns the closing hour of the current bar.

Upvotes: 0

Andrey D
Andrey D

Reputation: 1694

The hour() function can accept time:

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © adolgov

//@version=4
study("My Script")
plot(hour(time_close))

Upvotes: 1

Related Questions