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

Problem with Close[1], High[1], Vol[1]

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

    Problem with Close[1], High[1], Vol[1]

    Hi,

    I am programming a personal indicator and I need to get the High, Low and Volume for the previous bar. When I try to get those values like the Manual shows, e.g.:

    // Low price of 10 bars ago
    double barLowPrice = Low[10];

    I get nothing, and the same for High, Vol on past bars. However, I can use those functionalities to get the values for the actual bar.

    I have followed the NT7 guide but I can't get what I need. Can anyone help me?

    Thanks.

    #2
    Hi h2oid,

    Using Low[0] will return the Low 10 bars ago.

    If this is called on CurrentBar 0, this will break your script and you will get an error in the Log tab of the Control Center.

    Are you seeing any error messages in the Log tab of the Control Center?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi!

      I have changed the test script to only see the lowest value of the previous bar. I've written:

      double value = Low[1];

      and I receive the error as you said:

      I see in the log "Error on calling 'OnBarUpdate' method for indicator 'aaaTesting' on bar 0: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart."

      Then, I do not understand why in the Ninja Trader help guide it is written this:

      Examples
      // Current bar low price
      double barLowPrice = Low[0];

      // Low price of 10 bars ago
      double barLowPrice = Low[10];

      // Current bar value of a 20 period exponential moving average of low prices
      double value = EMA(Low, 20)[0];

      I found it at: http://www.ninjatrader.com/support/h...rice_data2.htm

      How should I get lowest and highest values of the previous bar?

      Thanks!

      Comment


        #4
        h2oid,

        You can use the [10] index bars ago for your look back, however we have to remember that the data has be loaded first before checking something is not there. This is known has an Index out of range error

        You would want to use a CurrentBar check in the OnBarUpdate to ensure that enough data has loaded before running calculations.

        See the sample below for more information -
        http://www.ninjatrader.com/support/f...ead.php?t=3170
        Cal H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by WeyldFalcon, 08-07-2020, 06:13 AM
        11 responses
        1,422 views
        0 likes
        Last Post jculp
        by jculp
         
        Started by RubenCazorla, Today, 09:07 AM
        0 responses
        4 views
        0 likes
        Last Post RubenCazorla  
        Started by BarzTrading, Today, 07:25 AM
        2 responses
        29 views
        1 like
        Last Post BarzTrading  
        Started by devatechnologies, 04-14-2024, 02:58 PM
        3 responses
        21 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by tkaboris, Today, 08:01 AM
        0 responses
        6 views
        0 likes
        Last Post tkaboris  
        Working...
        X