Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to find the bar contains a certain time.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to find the bar contains a certain time.

    I want to find out if the bar (any, even in history) contains a certain time.

    For example, I indicated 00:30. Now I want to check every day if there is a bar on the chart that contains this time. Function "ChartBars.GetBarIdxByTime()" is not what I need. This function will return the nearest bar, which may not contain this time.

    For example, today the first bar opened (began to form) at 10:00. This means that today there is no bar on the chart that contains 00:30.

    In the end, I want to know if there is a bar that contains a certain time - true or false.


    #2
    Hello webus,

    Thanks for your message. bar timestamps will reflect the timestamp of when the bar closes. You can check Time[0] to check the timestamp of the bar that is processing in OnBarUpdate. Since NinjaScripts process historical bars from the first bar on the chart to the last historical bar, and then onto realtime bars, you could check if (ToTime(Time[0]) == 100000) to check if one of the bars that has been processed has the timestamp of 10:00.

    If you want to check this at the end of the day, you could loop through bars to check this.

    Code:
    protected override void OnBarUpdate()
    {
        for (int i = ChartBars.GetBarIdxByTime(ChartControl, DATETIMETOSTART); i < CurrentBar; i++)
        {
            if (ToTime(Time[CurrentBar-i]) == 100000)
            {
                // Do Something
            }
        }
    }
    ToTime - https://ninjatrader.com/support/help...t8/?totime.htm

    Please let us know if we can be of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, Yesterday, 11:51 AM
    0 responses
    19 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, Yesterday, 11:48 AM
    0 responses
    23 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-25-2026, 09:53 PM
    0 responses
    30 views
    0 likes
    Last Post CaptainJack  
    Started by CaptainJack, 03-25-2026, 09:51 PM
    0 responses
    18 views
    0 likes
    Last Post CaptainJack  
    Started by Mindset, 03-23-2026, 11:13 AM
    0 responses
    23 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X