I was considering coding an indicator to detect the time frame of a chart but I was getting strange results on a 1 second chart. Here is a simple code that should calculate what the current seconds are from the open time but sometimes it returns a negative number for the seconds!
The 2nd image is returning just SS.
hhmmss = opentime
hhmm = (round(opentime/100))*100
hh = (round(opentime/10000))*10000
ss = hhmmss - hhmm
return ss as "ss", hhmmss as "hhmmss", hhmm as "hhmm", hh as "hh"
After a little further testing it seems that on a 20 second or 30 second or 40 second or 50 second chart it Calculates SS correctly but on any other chart it returns minus numbers.
Rounding hhmm when it’s 204040 will return 204000, when it’s 204050 will return 204100.
You should subtract-0.5 to return always 204000.
Thanks Roberto – I knew that it was something obvious that I had forgotten!
hhmmss = opentime
hhmm00 = (round(opentime/100-0.5))*100
hh0000 = (round(opentime/10000-0.5))*10000
ss = hhmmss - hhmm00
mm = (hhmmss - hh0000 - ss)/100
hh = hh0000/10000
return mm as "mm", ss as "ss", hh as "hh", hhmmss as "hhmmss"