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 rene69851, 05-02-2024, 03:25 PM
        1 response
        20 views
        0 likes
        Last Post rene69851  
        Started by ETFVoyageur, Yesterday, 07:05 PM
        5 responses
        42 views
        0 likes
        Last Post ETFVoyageur  
        Started by jpeep, 08-16-2020, 08:31 AM
        13 responses
        487 views
        0 likes
        Last Post notenufftime  
        Started by realblubb, 04-28-2024, 09:28 AM
        2 responses
        32 views
        0 likes
        Last Post realblubb  
        Started by bmarovets, Today, 06:33 PM
        0 responses
        12 views
        0 likes
        Last Post bmarovets  
        Working...
        X