Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How can you detect the last session?

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

    How can you detect the last session?

    How can I programmatically determine the last session in a data series on a chart?

    For example, say I am charting NQ and have 20 RTH sessions loaded into the chart. I want my indicator to work through all the sessions from CurrentBar = 0 and then write out the results when it gets to the last session in the chart data series.

    The code below will not work properly because the RTH session for today may not have started yet so the last session in the chart will be yesterdays RTH session.

    PHP Code:
    today    = DateTime.Now;
    
    if ( Time[0].Day == today.Day
                        && Time[0].Month == today.Month
                        && Time[0].Year == today.Year )
    {
     do something....
    } 
    
    Any suggestions would be appreciated.

    Thanks

    Chris

    #2
    Chris, are you working in NT7 already? Then you could work with those session related methods - http://www.ninjatrader.com/support/h...t7/session.htm

    Comment


      #3
      Hi Bertrand

      Yes I am using NT 7.

      Bars.Session.GetNextBeginEnd(Time[0], out sessionBegin, out sessionEnd); doesn't work because it just gives you the start of the next session.

      I need to know when the indicator has worked through all the bars from CurrentBar = 0 until the very last bar in the last session displayed on the chart. When it hits the final bar then it displays the results.

      For example I want it to count the number of MA crossovers in the data series loaded onto the chart and then only display the results when the final bar in the data series is hit.

      Thanks

      Comment


        #4
        This would unfortunately not be supported, however in the ChartControl you could access the LastBarPainted which sounds like what you need - you can look into the PowerVolume indicators for ideas.

        Comment


          #5
          Thanks, Bertrand

          I'll have a look at ChartControl.LastBarPainted.

          If I get it working, I'll post the code here for others to use, if they need it.

          Chris

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          598 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          343 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          103 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          556 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          555 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X