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

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.
    JesseNinjaTrader Customer Service

    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.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by kempotrader, Today, 08:56 AM
        0 responses
        6 views
        0 likes
        Last Post kempotrader  
        Started by kempotrader, Today, 08:54 AM
        0 responses
        4 views
        0 likes
        Last Post kempotrader  
        Started by mmenigma, Today, 08:54 AM
        0 responses
        2 views
        0 likes
        Last Post mmenigma  
        Started by halgo_boulder, Today, 08:44 AM
        0 responses
        1 view
        0 likes
        Last Post halgo_boulder  
        Started by drewski1980, Today, 08:24 AM
        0 responses
        3 views
        0 likes
        Last Post drewski1980  
        Working...
        X