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 rhyminkevin, Today, 04:58 PM
    3 responses
    47 views
    0 likes
    Last Post Anfedport  
    Started by iceman2018, Today, 05:07 PM
    0 responses
    5 views
    0 likes
    Last Post iceman2018  
    Started by lightsun47, Today, 03:51 PM
    0 responses
    7 views
    0 likes
    Last Post lightsun47  
    Started by 00nevest, Today, 02:27 PM
    1 response
    14 views
    0 likes
    Last Post 00nevest  
    Started by futtrader, 04-21-2024, 01:50 AM
    4 responses
    50 views
    0 likes
    Last Post futtrader  
    Working...
    X