Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Out of Range Exception

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

    Out of Range Exception

    I am Calculating Slope peaks and valleys but in my loop I am getting an OutOfRangeExeptionError and have been unable to figure out why this is happening. The indicator seems to be rendering correctly, but something is not right.

    here is the block of code that is catching the exception:

    bool directionUp = Slope[0] <= Slope[1];

    try
    {
    Print("================================== Slope Parameters ===================================");
    for (int i = 0; i <= Slope.Count+1; i++)
    {
    Print(string.Format("Loop index : {0}", i));
    Print(string.Format("Slope count -1 : {0}", Slope.Count -1));

    if (directionUp && Slope[i + 1] < Slope[i])
    {
    peakIndexes[0] = i;
    directionUp = false;

    }
    else if (!directionUp && Slope[i + 1] > Slope[i])
    {
    valleyIndexes[0] = i;
    directionUp = true;

    }
    }
    }
    catch(Exception e)
    {
    Print(e.ToString());
    }
    }​
    Attached Files

    #2
    Hello Itachi,

    Thanks for your post.

    According to the error message, a parameter in your script named 'index' is evaluating as a negative number and must be a non-negative number. This error might be coming from outside the code you shared.

    To determine exactly what line of code is causing the error, you could reduce your script by commenting out code. Then, uncomment the code section by section and test the script for the error.

    If at any point after removing some code, the error stops, add the last removed item back to test that it is the cause of the error. That line of code could then be modified accordingly.

    Please let me know if I may assist further.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    650 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    370 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    109 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    574 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    577 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X