Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

IsFirstBarOfSession && IsFirstTickOfBar

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

    IsFirstBarOfSession && IsFirstTickOfBar

    Hello,

    Can you please help me understand why the following code always spits out the first bars close time? I have Calculate set to Calculate.OnEachTick and TickReplay enabled on the chart. I am expecting it to fire at 5:00pm when the session restarts and the first trade occurs...? I am using NQ futures, standard trading hours, 15 min chart.


    protected override void OnBarUpdate()
    {

    if (Bars.IsFirstBarOfSession && IsFirstTickOfBar) {
    Print("Condition met at: " + Time[0].ToString() );
    }
    }


    ---------------------------------------------------------------------------
    Output:
    Condition met at: 12/26/2019 5:15:00 PM
    Condition met at: 12/29/2019 5:15:00 PM
    Condition met at: 12/30/2019 5:15:00 PM

    #2
    Hello NickyD,

    If the session opens at 5:00 and the chart is a 15 minute chart, then the first bar close will be at 5:15..

    Are you running the script with Calculate set to On each tick?

    Is TickReplay enabled?

    Is this historical or real-time?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      1) Yes.
      2) Yes.
      3) Historical.

      Comment


        #4
        Hello NickyD,

        If you print the time outside of any conditions, do you see multiple prints for each bar?

        I think either TickReplay isn't enabled or the Calculate setting for the running instance isn't set to On each tick.

        May I have a screenshot of the Data Series window and a screenshot of the Indicator window with this instance's settings?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I will send you the screenshots Jan 2.

          thanks.

          Comment


            #6
            Chelsea,

            I have figured out that Time[0] will only ever give me the timestamp on the bar currently processing of the primary series, even in RealTime. So if I am using a 15 minute series, the timestamp of the first bar of the session is 5:15. So the code above won't print out the time of the first tick as I was thinking it would.

            How can I access intrabar times in OnBarUpdate in State.Historical? The only way I know currently is in OnMarketData.

            Comment


              #7
              Hello NickyD,

              This would likely be due to your code.

              Time[0] will return for every series updating in OnBarUpdate.

              If Calculate is On bar close, this will be the close time of the most recently fully closed bar (not the updating bar).

              If Calculate is On price change or On each tick (in real-time or with TickReplay in historical) this will be the close time of the currently open updating bar.

              You can add a 1 tick series to get the time stamps of individual ticks.
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

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