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.
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Segwin, 05-07-2018, 02:15 PM
    14 responses
    1,789 views
    0 likes
    Last Post aligator  
    Started by Jimmyk, 01-26-2018, 05:19 AM
    6 responses
    837 views
    0 likes
    Last Post emuns
    by emuns
     
    Started by jxs_xrj, 01-12-2020, 09:49 AM
    6 responses
    3,293 views
    1 like
    Last Post jgualdronc  
    Started by Touch-Ups, Today, 10:36 AM
    0 responses
    13 views
    0 likes
    Last Post Touch-Ups  
    Started by geddyisodin, 04-25-2024, 05:20 AM
    11 responses
    63 views
    0 likes
    Last Post halgo_boulder  
    Working...
    X