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

why close[1] doesn't work?

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

    why close[1] doesn't work?

    hi guys.

    i have downloaded historical data of an instrument, i'd like to create an indicator that stores into an array all Close values and then make some calculations. While testing it i realized that only Closes[0] works, other values than zero don't, i.e. plotting zeroth gives me the timeseries, plotting [1] gives me nothing.

    needless to say that i cannot access other values than the current one, as desired.

    moreover how do i find the number of bars, in other words maximum value that i can put in Close[]?

    #2
    Open up the OUTPUT WINDOW.... Do you see an error message?

    Control Center-> Tools->Output Window

    Is it this message?
    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.


    Try here:





    Originally posted by jim_feyn View Post
    hi guys.

    i have downloaded historical data of an instrument, i'd like to create an indicator that stores into an array all Close values and then make some calculations. While testing it i realized that only Closes[0] works, other values than zero don't, i.e. plotting zeroth gives me the timeseries, plotting [1] gives me nothing.

    needless to say that i cannot access other values than the current one, as desired.

    moreover how do i find the number of bars, in other words maximum value that i can put in Close[]?

    Comment


      #3
      You were right. Thank you.

      I need to fill an array with all price data until the current one. By writing in OnBarUpdate:

      data[CurrentBar]=Close[0]; I didn't have much luck.

      OnBarUpdate is like a loop that is constantly executing as new price data comes in? If so, I thought that the above code executes like:
      data[0]=Close[0];
      data[1]=Close[0];
      data[2]=Close[0];
      ........................

      hence it progressively populates my array as current values come. Or it initializes data[] each time a new value comes and past data[] is deleted?

      Comment


        #4
        Originally posted by jim_feyn View Post
        You were right. Thank you.

        I need to fill an array with all price data until the current one. By writing in OnBarUpdate:

        data[CurrentBar]=Close[0]; I didn't have much luck.

        OnBarUpdate is like a loop that is constantly executing as new price data comes in? If so, I thought that the above code executes like:
        data[0]=Close[0];
        data[1]=Close[0];
        data[2]=Close[0];
        ........................

        hence it progressively populates my array as current values come. Or it initializes data[] each time a new value comes and past data[] is deleted?
        Why do you want to fill an array? This is not necessary, as all the closes are already available through a DataSeries object. Using a structure such as data[] would only create a redundancy and increase both CPU and RAM load.

        When you apply the indicator to a chart, it can access all closes within the specified lookback period of the chart. Let us assume that your chart has 52360 bars. To find the number of bars on your chart you can use Bars.Count. With CalculateOnBarClose (COBC) = false, your indicator will access all bars until the last bar on your chart, which is CurrentBar = Bars.Count - 1 = 52359. With COBC = true your indicator will not access the last bar but stop with the second but the last bar on your chart, which is CurrentBar = Bars.Count -2 = 52358

        To access the last close (bar 52358 with COBC = true, or bar 52359 with COBC = false), you have two options

        - either Close [0]
        - or Bars.GetClose(CurrentBar)

        Accordingly

        - Close[CurrentBar]
        - or Bars.GetClose(0)

        allows you to access the close of the first bar on your chart.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by llanqui, Today, 03:53 AM
        0 responses
        6 views
        0 likes
        Last Post llanqui
        by llanqui
         
        Started by burtoninlondon, Today, 12:38 AM
        0 responses
        10 views
        0 likes
        Last Post burtoninlondon  
        Started by AaronKoRn, Yesterday, 09:49 PM
        0 responses
        15 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
        14 views
        0 likes
        Last Post strategist007  
        Working...
        X