Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how to skip past sessions when using FirstBarOfSession

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

    how to skip past sessions when using FirstBarOfSession

    how can i condition a code to the first bar of the last session on the chart?

    #2
    Hello savekad,
    You can use the below code to do it.

    Code:
    if (FirstTickOfBar && Bars.LastBarOfSession)
    {
       //do something
    }


    The LastBarOfSession is not officially supported and thus not documented.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      how will i be able to skip sessions that already ended?

      the main idea is to load a lot of historical data but to execute a code only when reaching the first tick of the first bar of the current session, avoiding redundant evaluations of past sessions.

      Comment


        #4
        Hello savekad,
        If you do not want to evaluate your code for historical data you can simply use the below code to filter it out.

        Code:
        if (Historical) return;
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          but that's not it.

          i want the code to run once when OBU() evaluating the first bar of the current session. if i use:

          if (Bars.FirstBarOfSession && FirstTickOfBar)
          {
          // code
          }

          then the code will run one time for each past session and i want to avoid that.

          how do i do that?

          Comment


            #6
            Hello savekad,
            You can further check for the time too to do it.

            If you try the below code then are you able to get the correct values

            Code:
            if (Bars.FirstBarOfSession && this.FirstTickOfBar && Bars.GetTradingDayFromLocal(Time[0]).Date == DateTime.Now.Date)
            {
              // do something
            }
            JoydeepNinjaTrader Customer Service

            Comment


              #7
              please refer me to some reading about Bars.GetTradingDayFromLocal.

              i've looked for it and couldn't find anything.

              Comment


                #8
                Hello savekad,
                Unfortunately the Bars.GetTradingDayFromLocal function is not officially supported and thus not documented.
                JoydeepNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                649 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                370 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                109 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                573 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                576 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X