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.

    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 argusthome, 03-08-2026, 10:06 AM
      0 responses
      105 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      52 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      34 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      38 views
      0 likes
      Last Post TheRealMorford  
      Started by Mindset, 02-28-2026, 06:16 AM
      0 responses
      74 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Working...
      X