Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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,


    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,


      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:


        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 frankthearm, Today, 09:08 AM
            7 responses
            29 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Started by NRITV, Today, 01:15 PM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by maybeimnotrader, Yesterday, 05:46 PM
            5 responses
            25 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by quantismo, Yesterday, 05:13 PM
            2 responses
            17 views
            0 likes
            Last Post quantismo  
            Started by adeelshahzad, Today, 03:54 AM
            5 responses
            33 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Working...
            X