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

Accessing Bar Data

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

    Accessing Bar Data

    I am trying to get the close and the RSI for the last 14 bars. As a test I tried to get the data for 5 bars back.

    DrawTextFixed("X", Close[-5] + " - " + RSI(14,3)[-5], TextPosition.TopLeft);

    I am getting an out of range error.
    What is the best practice method for getting the data I am looking for?

    Thanks

    #2
    Hello tupchurch,

    To access 5 bars back you would use a positive number like "Close[5]" and "RSI(14,3)[5]"to get 5 bars back inside of NinjaTrader.

    Here is a good thread that goes over using the Brackets "[]" inside of NinjaTrader to access previous values that you may view.
    JCNinjaTrader Customer Service

    Comment


      #3
      Using positive five is when I get the out of range error. Your link doesn't address this problem. I tried using if (Bars.Count > 20) but it didn't help. What is the best practice method of avoid the out of range error at the beginning of a series?



      Originally posted by NinjaTrader_JC View Post
      Hello tupchurch,

      To access 5 bars back you would use a positive number like "Close[5]" and "RSI(14,3)[5]"to get 5 bars back inside of NinjaTrader.

      Here is a good thread that goes over using the Brackets "[]" inside of NinjaTrader to access previous values that you may view.
      http://www.ninjatrader.com/support/f...ad.php?t=19346

      Comment


        #4
        Hello tupchurch,

        To make sure that you have enough data before you start to make your calculations you will want to use "CurrentBar" to check to see what bar is being processed. So in your example:

        Code:
        protected override void OnBarUpdate()
        {
            // Makes sure there is at least 15 bars before moving on
            if (CurrentBar < 14)
                return;
        
           // Rest of code that can access up to 15 bars ago.
        }
        Last edited by NinjaTrader_JC; 12-03-2013, 03:48 PM. Reason: Typo
        JCNinjaTrader Customer Service

        Comment


          #5
          Got it, thanks.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by trilliantrader, Today, 03:01 PM
          0 responses
          2 views
          0 likes
          Last Post trilliantrader  
          Started by pechtri, 06-22-2023, 02:31 AM
          9 responses
          122 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by frankthearm, 04-18-2024, 09:08 AM
          16 responses
          67 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by habeebft, Today, 01:18 PM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by benmarkal, Today, 12:52 PM
          2 responses
          19 views
          0 likes
          Last Post benmarkal  
          Working...
          X