remaining time left in a bar

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #174224 quote
    IG_CFD_Trader
    Participant
    Average

    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)

    #174273 quote
    IG_CFD_Trader
    Participant
    Average

    Tnx Noobywan. I got your email. it works. what would be the same code for 1Hr and 5Hr charts?

    #174298 quote
    IG_CFD_Trader
    Participant
    Average

    How do I capture the IntraDayBarIndex of the 10am bar that will be correct on all intraday timeframes?

    #174300 quote
    JC_Bywan
    Moderator
    Master

    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.

    #174302 quote
    JC_Bywan
    Moderator
    Master

    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
    #174318 quote
    IG_CFD_Trader
    Participant
    Average

    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)?

    #174320 quote
    IG_CFD_Trader
    Participant
    Average

    I am guessing time_elapsed would simply be

    elapsed=(hduree*10000+mnduree*100+sduree)

    #174325 quote
    JC_Bywan
    Moderator
    Master

    Hi, yes, that’s the time elapsed, recreated into a single number in hhmmss format.

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.

remaining time left in a bar


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
IG_CFD_Trader @wnakhoul Participant
Summary

This topic contains 7 replies,
has 2 voices, and was last updated by JC_Bywan
4 years, 6 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 07/27/2021
Status: Active
Attachments: No files
Logo Logo
Loading...