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 andrewtrades, Today, 04:57 PM
    1 response
    5 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by chbruno, Today, 04:10 PM
    0 responses
    3 views
    0 likes
    Last Post chbruno
    by chbruno
     
    Started by josh18955, 03-25-2023, 11:16 AM
    6 responses
    436 views
    0 likes
    Last Post Delerium  
    Started by FAQtrader, Today, 03:35 PM
    0 responses
    6 views
    0 likes
    Last Post FAQtrader  
    Started by rocketman7, Today, 09:41 AM
    5 responses
    19 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X