Used in tick bars, or at least not in time, to evaluate the duration of the bar in seconds.
Returns the number of seconds elapsed to complete each individual bar.
Could be useful to measure the market speed in non-time-dependent charts: ticks charts, range bars, renko bars, etc.
Code emerged from discussion here: Indicator for bar duration
// utilizzato nelle barre a tick, o comunque non a tempo, per valutare la durata della barra in secondi
// ritorna il numero di secondi trascorsi per il completamento di ogni singola barra
ptime = Time[1]
ctime = Time
// estraggo la differenza in ore
if ctime>=10000 then
hend = (ctime - (ctime mod 10000))/10000
ctime = (ctime mod 10000)
else
hend = 0
endif
if ptime>=10000 then
hstart = (ptime - (ptime mod 10000))/10000
ptime = (ptime mod 10000)
else
hstart = 0
endif
// estraggo la differenza in minuti
if ctime>=100 then
mend = (ctime - (ctime mod 100))/100
ctime = (ctime mod 100)
else
mend = 0
endif
if ptime>=100 then
mstart = (ptime - (ptime mod 100))/100
ptime = (ptime mod 100)
else
mstart = 0
endif
secstarttime = hstart*3600+mstart*60+ptime
secendtime = hend*3600+mend*60+ctime
barsec = secendtime-secstarttime
// correggo l'eventuale cambio di giorno
if barsec<0 then
barsec = 3600*24-secstarttime+secendtime
endif
return barsec as "seconds/bar"