Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Value after DataLoaded

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

    Value after DataLoaded

    I have a really hard time to understand what "Value" and "Values" exactly is and what it isnt.
    I did some testing after the DataLoaded State and get very strange results.

    Value.Count returns 1007. But when I try to acces the second index (Value[1]), I get an index out of bounds !? Why? It just said that it holds 1007 entries!?
    Why does CurrentBar return 1005 and not 1006? It sounds like it would not calculate the last bar.

    I would really appreciate any help!

    #2
    Hello Bobin,

    The Value property is a default plot property, that is used when you don't define a public property for a plot. It defaults to the first plot, so that means using Value[1] would mean get the plot of 1 BarsAgo. The error would come if you tried that on bar 0, on bar 0 there is no 1 BarsAgo so it causes an error. On bar 1 and beyond you could do that to get the previous value.



    The Values property is the same as above except this contains the collection of plots for the script. If the indicator had two plots you could access the second like the following Values[1][0] meaning the second plot, 0 BarsAgo.



    There are many plural named properties in the platform like Open and Opens, it is the same concept the plural form lets you access a specific series or plot using an index.

    Please let me know if I may be of further assistance.

    Comment


      #3
      Hi Jesse,
      thanks for your answer.

      But CurrentBar returns 1005. So Value[1] should work if I understood you correctly? I dont understand why I am getting an index out of bounds error.

      Comment


        #4
        Hello Bobin,

        I don't have any context on where you are trying to use that so I couldn't say if that would work or not.

        If we assume you made a new empty indicator that contains 1 plot. In OnBarUpdate the plot is being assigned:

        Code:
        Value[0] = Close[0];
        You could after that point check that there is enough data and then use that plot:

        Code:
        if(CurrentBar < 1) return; 
        Print(Value[1]);
        If you are trying to do this from DataLoaded state you need to move your testing to OnBarUpdate when the plot is actually being set and has data.

        Please let me know if I may be of further assistance.

        Comment


          #5
          Originally posted by Bobin View Post
          I have a really hard time to understand what "Value" and "Values" exactly is and what it isnt.
          I did some testing after the DataLoaded State and get very strange results.

          Value.Count returns 1007. But when I try to acces the second index (Value[1]), I get an index out of bounds !? Why? It just said that it holds 1007 entries!?
          Why does CurrentBar return 1005 and not 1006? It sounds like it would not calculate the last bar.

          I would really appreciate any help!
          It may help to try separate out 'slots and 'values'.

          Just because there is a slot to hold a value, doesn't
          necessarily mean the slot has a value.

          In other words, first think of a Series as a bunch of
          slots. If State.DataLoaded says Value.Count is 1007,
          that means slots, not values.

          The values are assigned into each slot, once for each
          call to OnBarUpdate.

          Once you transition to Realtime data, new slots are created
          just before the call to each OnBarUpdate.

          Does that help?

          Perhaps NT support can expand/collapse this analogy,
          but it has been helpful to me in the past.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          593 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          343 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          103 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          556 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          554 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X