Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to access data from yesterdays session

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

    How to access data from yesterdays session

    Hello,

    I am developing a simple indicator script which will plot lines of various key levels on a chart. The trading hours are set to ETH / <Use instrument settings>.

    When the current day RTH session starts I want to be able to plot the overnight session highs & lows along with the highs, lows & close from the previous days RTH session.

    I am aware that I can use the Prior Day OHLC indicator with a 'ghost' secondary data series to plot the lines but as I'm running a tick chart I don't want to load up my chart with unnecessary data.

    I am able to code a script to plot horizontal lines for the overnight sessions highs & lows and I'm able to use the ToTime() function to create a session range but I'm struggling to work out how to access the data from the previous session.

    Is there a similar function I can use which will help access the prior day values which I can then use the ToTime() function to create the prior day's RTH session?

    Thanks,

    Neil

    #2
    Hello Neil,

    Yes, this is likely possible to create.

    Data from previous bars is accessed with a BarsAgo index.

    For example Close[1] would provide the close price of the previous bar.

    Lets say that the Close price of a specific bar in yesterday's session was 1500 bars ago. We would use this as this as the BarsAgo index.

    Close[1500] would be the close price of the bar 1500 bars ago.

    You can get the bar number of a bar using Bars.GetBar() by providing a datetime object of the date and time of the bar number you want.
    Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.


    You can subtract that from CurrentBar to get a BarsAgo index.

    For example:

    Close[CurrentBar - Bars.GetBar(new DateTime(2025, 04, 10, 8, 30, 0))] would provide the close price of the bar from yesterday April 10th, at 8:30 am.


    However, you might find it easier to just save the highest high / low to variables and update the variables to the new high / low each time the new bar's high is higher or low is lower.

    Then stop updating the variable once the RTH hours are in session.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks NinjaTrader_ChelseaB.

      I think I'll head down the variables route as I can figure out the logic for that but how can I stop the variable updating for todays session?

      Comment


        #4
        Hello burtoninlondon,

        You can use time conditions.
        Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.

        Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.


        if (ToTime(Time[0]) < 83000 || ToTime(Time[0]) > 40000)
        {
        myVariableName = Math.Max(myVariableName, High[0]);
        }
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks, I tried the logic you provided and it is good for identifying the overnight levels.

          Let's say I want to find the high of the RTH session then I could use...

          if (ToTime(Time[0]) >= 83000 && ToTime(Time[0]) <= 150000)
          {
          myVariableName = Math.Max(myVariableName, High[0]);
          }

          However that would update when the current session is live, so right now I'd be calculating the high of the current session, not yesterdays. How would I disable this logic so that it doesn't update today.​

          Comment


            #6
            Hello burtoninlondon,

            You could use two variables.

            After a session set the second variable to the value of the first variable.

            The first variable would be updating for the current session for use tomorrow, the previous session would be saved to the second variable.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              That's worked, thanks for your help.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              558 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              324 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              101 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              545 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              547 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X