Hi,
I am seeking help with code to calculate the number of bars from a specific date and time. For example, on an hourly chart, I would like to calculate the number of bars since 10am on 23 May 2024.
Thanks,
Madokin
JSParticipant
Senior
Hi,
Try this one:
myDate=20240523
myHour=10
If Date=myDate and OpenHour=myHour then
myBarIndex=BarIndex
EndIf
myNumberOfBars=BarIndex-myBarIndex
Return myNumberOfBars
Hi,
or this:
myDate = 20240523
myTime = 100000
condition = ((opendate = myDate) and (opentime = myTime))
bars = barssince(condition,0)
return bars
Thank you druby and JS for your help.
I had success with druby’s solution, although I had to adjust the result by adding 24 (working on an hourly chart)…so I’m wondering if it’s counting barssince the next opentime after the end of the opendate? It’s an easy adjustment for me to make, I was just interested to understand the logic.