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 CarlTrading, 03-31-2026, 09:41 PM
                1 response
                67 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by CarlTrading, 04-01-2026, 02:41 AM
                0 responses
                36 views
                0 likes
                Last Post CarlTrading  
                Started by CaptainJack, 03-31-2026, 11:44 PM
                0 responses
                59 views
                1 like
                Last Post CaptainJack  
                Started by CarlTrading, 03-30-2026, 11:51 AM
                0 responses
                62 views
                0 likes
                Last Post CarlTrading  
                Started by CarlTrading, 03-30-2026, 11:48 AM
                0 responses
                53 views
                0 likes
                Last Post CarlTrading  
                Working...
                X