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 burtoninlondon, Today, 12:38 AM
      0 responses
      5 views
      0 likes
      Last Post burtoninlondon  
      Started by AaronKoRn, Yesterday, 09:49 PM
      0 responses
      12 views
      0 likes
      Last Post AaronKoRn  
      Started by carnitron, Yesterday, 08:42 PM
      0 responses
      11 views
      0 likes
      Last Post carnitron  
      Started by strategist007, Yesterday, 07:51 PM
      0 responses
      13 views
      0 likes
      Last Post strategist007  
      Started by StockTrader88, 03-06-2021, 08:58 AM
      44 responses
      3,982 views
      3 likes
      Last Post jhudas88  
      Working...
      X