Function Req, next bar is open after trade

 

Chart time frame : H1

I have a trade opened at 16:20 ( of course it can be anytime, like 16:30, 16:55) within a current H1 bar.

I want to run a indicator check when the next hourly bar starts , say at 17:05 or greater

Like if(TimeCurrent() > "17:05")

- So I need to find the seconds diff btw 16:30 and 17:05, no knowing what 16:30 will be each time as its based on trade execution time.

How do I determine the next hour start time, no matter when trade time opens, and taking into account 23:00 rolls over to 00:00 ???

 

secondsUntilNextBar = Period()*60 - MathMod(TimeCurrent, Period()*60);