Calculate no. of bars from a specific date and time

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #236666 quote
    Madokin
    Participant
    New

    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

    #236667 quote
    JS
    Participant
    Senior

    Hi,

    Try this one:

     

    myDate=20240523
    myHour=10
    
    If Date=myDate and OpenHour=myHour then
    myBarIndex=BarIndex
    EndIf
    
    myNumberOfBars=BarIndex-myBarIndex
    
    Return myNumberOfBars
    druby and Madokin thanked this post
    #236668 quote
    druby
    Participant
    New

    Hi,

    or this:

     

    myDate = 20240523
    myTime = 100000
    
    condition = ((opendate = myDate) and (opentime = myTime))
    
    bars = barssince(condition,0)
     
    return bars
    JS and Madokin thanked this post
    #236696 quote
    Madokin
    Participant
    New

    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.

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

Calculate no. of bars from a specific date and time


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Madokin @madokin Participant
Summary

This topic contains 3 replies,
has 3 voices, and was last updated by Madokin
1 year, 5 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/24/2024
Status: Active
Attachments: No files
Logo Logo
Loading...