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 zstheorist, Today, 07:52 PM
    0 responses
    3 views
    0 likes
    Last Post zstheorist  
    Started by pmachiraju, 11-01-2023, 04:46 AM
    8 responses
    149 views
    0 likes
    Last Post rehmans
    by rehmans
     
    Started by mattbsea, Today, 05:44 PM
    0 responses
    5 views
    0 likes
    Last Post mattbsea  
    Started by RideMe, 04-07-2024, 04:54 PM
    6 responses
    33 views
    0 likes
    Last Post RideMe
    by RideMe
     
    Started by tkaboris, Today, 05:13 PM
    0 responses
    5 views
    0 likes
    Last Post tkaboris  
    Working...
    X