Calling on PRC experts 🙂
If I am on a 15min chart, is there a way to capture the remaining time left of the current bar in a variable which I can store and use (for example multiply the remaining time left by a number)
Tnx Noobywan. I got your email. it works. what would be the same code for 1Hr and 5Hr charts?
How do I capture the IntraDayBarIndex of the 10am bar that will be correct on all intraday timeframes?
Hi, what I first posted, calling it “fast and lazy coding only for ut15” was too fast and too lazy, there was an issue with it. Although I removed it almost straight away when seeing it, I couldn’t prevent the email notification, sorry about that… Here’s a less lazy version correcting the issue, and it should be ok with your other 1h and 5h request too:
defparam DRAWONLASTBARONLY=true
//
diff=opentime-opentime[1]
if diff=diff[1] then
ut=diff
elsif diff[1]=diff[2] then
ut=diff[1]
elsif diff[2]=diff[3] then
ut=diff[2]
endif
//
hut=(ut-ut mod 10000)/10000
temput=(ut-hut*10000)
mnut=(temput-temput mod 100)/100
sut=temput-mnut*100
//
if time-opentime>0 and time-opentime<=ut then
duree=time-opentime
elsif time-opentime<=0 then
duree=time+240000-opentime
endif
//
hduree=(duree-duree mod 10000)/10000
tempduree=(duree-hduree*10000)
mnduree=(tempduree-tempduree mod 100)/100
sduree=tempduree-mnduree*100
//
if islastbarupdate then
sleft=sut-sduree
if sleft<0 then
mnret=1
sleft=60+sut-sduree
else
mnret=0
endif
mnleft=mnut-mnduree-mnret
if mnleft<0 then
hret=1
mnleft=60+mnut-mnduree-mnret
else
hret=0
endif
hleft=hut-hduree-hret
else
hleft=0
mnleft=0
sleft=0
endif
left=hleft*10000+mnleft*100+sleft
DRAWTEXT("#hleft#h #mnleft#mn #sleft#s", barindex, left)
DRAWTEXT("#left#", barindex, left*0.9)
return left as "time left in candle"
You can either use the variable “left” as an integer storing the requested value, or the subcomponents hleft, mnleft, sleft if you need in more details the hour minute and second component of the time left.
For your 10am intradaybarindex request, this would reset it at 0 each day, and providing you have a bar starting at 10am in the chosen timeframe it will store its intradaybarindex in the “mybar” variable:
if opentime=100000 then
mybar=IntradayBarIndex
elsif IntradayBarIndex<IntradayBarIndex[1] then
mybar=0
endif
return mybar
Tnx Noobywan, I am also learning French in the process 🙂
Also, where is the time elapsed variable captured in the code above? How would you captured it (if not already captured in your code above)?
I am guessing time_elapsed would simply be
elapsed=(hduree*10000+mnduree*100+sduree)
Hi, yes, that’s the time elapsed, recreated into a single number in hhmmss format.