• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calling last Bar Close at the end of session during breaks

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

    Calling last Bar Close at the end of session during breaks

    It's a simple question but NT8 has different ways and I'd like to know more reliable.

    After EOD, during the break, markets are inactive, no data comes at all, so at that moment I need to call simply the last Bar Close, so would these two be valid?

    1. myvariable = Close[0];

    2. myvariable = Bars.GetClose(0)

    Thanks

    #2
    Hello pstrusi,

    Close would take a bars ago value whereas Bars.GetClose takes an absolute barIndex.

    For example the following code in an indicator would print the first close on a chart, and would not change,

    Print(Bars.GetClose(0));

    While the following would print every close starting to from the left moving to the right.
    Print(Close[0]);

    If you were to pass the CurrentBar into GetClose, they would be the same. Please see the following explanation,
    http://ninjatrader.com/support/forum...ad.php?t=89799

    Please let us know if you need further assistance.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChrisL View Post
      Hello pstrusi,

      Close would take a bars ago value whereas Bars.GetClose takes an absolute barIndex.

      For example the following code in an indicator would print the first close on a chart, and would not change,

      Print(Bars.GetClose(0));

      While the following would print every close starting to from the left moving to the right.
      Print(Close[0]);

      If you were to pass the CurrentBar into GetClose, they would be the same. Please see the following explanation,
      http://ninjatrader.com/support/forum...ad.php?t=89799

      Please let us know if you need further assistance.
      Thank CrissL, so according to your answer, if I call Close[0] after EOD, during the break, with markets inactive, I will have the last Bar Close ?

      Comment


        #4
        Hello pstrusi,

        Thank you for the reply.

        If you would like to get the last bar of the session, use IsLastBarOfSession.

        Code:
        if(Bars.IsLastBarOfSession)
            Print(string.Format("Bar number {0} was the last bar processed of the session at {1}.", CurrentBar, Time[0]));
        }
        Then if you wanted to get the close of that bar, do something like this:

        Code:
        if(Bars.IsLastBarOfSession)
        
             Print(Bars.GetClose(CurrentBar););
            
        }
        More on IsLastBarOfSession here:
        https://ninjatrader.com/support/help...rofsession.htm

        Please let me know if I may be of any further assistance.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Thanks CrissL for the snippet.

          But I want to know something:
          During market-brakes ( the period after the old Session and before the new session begins ) where there's not stream data, so the last bar check is obviously True, if I call "Bars.GetClose(CurrentBar);" would I have the very same last close, wouldn't I ? Logic says yes, but I don't if any technical reason would prevent it.

          Comment


            #6
            Hello pstrusi,

            Thanks for the reply.

            Your code will not run while out of session. Using IsLastBarOfSession is the suggested way to get the Close of the last bar within the session.

            If there is anything else I may assist with please let me know.
            Chris L.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Goolden, Today, 09:51 AM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by ArmKnuckle, Today, 01:25 AM
            1 response
            25 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by 7robert, Today, 08:26 AM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by 7robert, Today, 08:08 AM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_Jim  
            Started by ttodua, Today, 08:09 AM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_Jim  
            Working...
            X