Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

array values from indicator are "0"

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

    array values from indicator are "0"

    I am pulling array vars from an indicator, I have checked the values by printing them from the indicator and they are valid, but I am getting "index was outside the bounds of the array" here is the line:

    Code:
     
    [FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][COLOR=black]macd[CanNumber] = Ladders().macd[CanNumber];[/COLOR][/COLOR][/SIZE][/FONT]
    [COLOR=#008000][SIZE=2][FONT=Courier New][COLOR=black]macdAvg[CanNumber] = Ladders().macdAvg[CanNumber];[/COLOR][/FONT][/SIZE]
    [SIZE=2][FONT=Courier New][COLOR=black]Upper[CanNumber] = Ladders().Upper[CanNumber];[/COLOR][/FONT][/SIZE]
    [/COLOR][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]Lower[CanNumber] = Ladders().Lower[CanNumber];[/SIZE][/FONT]
    [/SIZE][/FONT]
    This is where the vars are assigned in the indicator:
    Code:
     
    macd[CanNumber] = fastEma[0] - slowEma[0];
    macdAvg[CanNumber] = (2.0 / (1 + Smooth[CanNumber])) * macd[CanNumber] + (1 - (2.0 / (1 + Smooth[CanNumber]))) * Avg[1];
     
    Upper[CanNumber] = macd[CanNumber] + StdDev(20)[0];
    Lower[CanNumber] = macd[CanNumber] + StdDev(20)[0];
    This is my first go at pulling array vars from another class,
    What am I missing?
    Last edited by Sleeping Troll; 03-28-2010, 08:30 PM.

    #2
    Sleeping Troll, please make sure in your code that when you are accessing an array you are accessing a value that actually exists. For example, if you were to try and grab the value for three bars ago on the first bar of the chart (left-most bar), you would get the "index is out of the bounds of the array" error because the data doesn't exist yet.

    You might want to add a simple return if there aren't enough bars and see if that solves the problem:
    Code:
    if (CurrentBar < 2)
       return;
    AustinNinjaTrader Customer Service

    Comment


      #3
      In my Strategy class and my Indicator classI use both:

      if (Historical)return;
      if (CurrentBar < 20)return;


      Same error, I appreciate the response late on a Sunday evening though!

      Comment


        #4
        Without seeing the full code, is CanNumber also satisfied by your 20 bars check? To debug it would be best to simplify as much as possible and then work try and catch concepts in to 'hunt' it down - http://www.ninjatrader-support2.com/...ead.php?t=9825

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        647 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        369 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        108 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        572 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        573 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X