Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

check Series value at specific index

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

    check Series value at specific index

    i.e. in indicator I have


    Code:
    AddDataSeries("xyz", same, same);

    and I use:

    Code:
    if ( Closes[0][0] > Closes[1][0])  ....

    however, on main chart, if i am on bar (at 2010 year), the secondary data may not yet be available (i.e. if secodnary data starts after 2011 year).

    so, indicator fire error "accessing the index that doesnt exist"...
    so, i wanted to find a way to check if Closes[1] had an available index at 0, however such codes doesnt work:

    Code:
    if(Closes[1].IndexOf(0) ) ......
    because Closes[1] doesnt contain any overload of IndexOf.

    how can i check if specific index is loaded at this moment?
    prbably you understand my problem.

    #2
    Hello TazoTodua,

    Thank you for the post.

    The generally accepted way to check for data is to use the CurrentBars object:

    Code:
    if(CurrentBars[0] < 1 || CurrentBars[1] < 1) return;
    This would ensure that both series have at least 1 bar to be used. By adding this type of check, that should allow logic which uses both series to occur.

    I look forward to being of further assistance.

    Comment


      #3
      i used this code:

      for (int bIdx=0; bIdx < BarsArray.Length; bIdx++) if ( CurrentBar - 1 <= BarsArray[0].Count - BarsArray[bIdx].Count ) return;


      so your code is more easier (achieving the same) right?
      will that handle in both of these cases, and wont throw the error, right?




      thanks ! ! ! ! ! !
      Last edited by ttodua; 07-13-2018, 01:43 PM.

      Comment


        #4
        Hello TazoTodua,

        Without printing out what you are doing, I couldn't say if that is specifically working the same. The CurrentBars object wont throw an error unless you use an index that is not there. Also, the Count property can be variable depending on the scripts settings and is also unknown when using TickReplay.

        I would suggest trying my suggestion in place of the check you are now, and that would let you know if that solves the problem with your specific question. If it does not, we could look at a greater sample together to see why that may be.

        I look forward to being of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        597 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
        555 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X