Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to call the Last Session's Close

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

    How to call the Last Session's Close

    Hi Ninjas,

    Everytime I begin a code for a new session, I need to do a one time calculation:

    The difference between the Last Session's Close minus the very first Close[0] of the new session. Searching in the help guide, I've known this interesting method: Bars.GetDayBar(1).Close which, supposedly it will have that last session Close that I want to find. So I did a little snippet to be run under OnStartUp() method, this is as follows:

    Code:
    if ( (Close[0]-Bars.GetDayBar(1).Close) >= 0 )
    {
    	// Do something
    }
    else
    {
    	// Do otherwise
    }
    Here's my doubt:

    In Forex a new session begins at 17:15 hours, so the method Bars.GetDayBar(1).Close, would really give me the the very Last Close at 17:00 of the PAST last session?

    If not, please would you indicate how to address it correctly?

    Thanks

    #2
    Hello,

    Thank you for the question.

    Are you just trying to get the Prior sessions close? If so, you could use the PriorDayOHLC indicator to do this rather than re creating all new logic.



    The syntax to get the Close would be:

    double value = PriorDayOHLC().PriorClose[0];

    Also this would need to be called after OnStartUp as OnStartUp is happening prior to the bars being processed on the chart. This can go anywhere in OnBarUpdate or the other override methods that happen after OnStartUp.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks for your response Jesse, it seems that your solution is what I was looking for. I'll try it.

      Thanks again and best regards

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by ghoul, Today, 06:02 PM
      1 response
      10 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by jeronymite, 04-12-2024, 04:26 PM
      3 responses
      44 views
      0 likes
      Last Post jeronymite  
      Started by Barry Milan, Yesterday, 10:35 PM
      7 responses
      20 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by AttiM, 02-14-2024, 05:20 PM
      10 responses
      180 views
      0 likes
      Last Post jeronymite  
      Started by DanielSanMartin, Yesterday, 02:37 PM
      2 responses
      13 views
      0 likes
      Last Post DanielSanMartin  
      Working...
      X