Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Out of range index value error when DrawLine() called

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

    Out of range index value error when DrawLine() called

    Hello,
    I created an indicator draws two lines on the price chart that follow the movement of the RSI indicator. One line draws when the RSI is up and the other when the RSI is down. For some reason when the "up" side line is called I get "out of range" error, but only on the "up line". If I run the "down line by itself everything is fine. Here is the code. I have "if (CurrentBar < 20) return;" I can change the numerical value, but the error always occurs on the bar after the numerical value. Can someone give me and idea of why this is happening?
    Code:
     
    if (CurrentBar < 20) return;
    //low    
                if(Close[1] < Close[2] && Close[2] < Close[3] && (Close[0] > Close[1] || Close[0] == Close [1]))    
                {
                        if(Finding_Valleys(RSI(14,3)[2],RSI(14,3)[1],RSI(14,3)[0]))//Captures the low point
                    {
                        DrawDiamond("RSI Valley " + CurrentBar, true, 1 , Low[0] - .03, Color.Magenta);
                        rsi_low_value = RSI(14,3)[1];
                        rsi_low = CurrentBar;
                        DrawLine("RSI line Down " + CurrentBar, true, CurrentBar - (rsi_high - 1) , High[CurrentBar - (rsi_high - 1)], 
                            CurrentBar - (rsi_low - 1), Low[CurrentBar - (rsi_low - 1)], Color.Red, DashStyle.Solid, 2);
                        Print(Time[0] + " Low " + rsi_low_value );
                    }
                    
                }
                //high
                if(Close[1] > Close[2] && Close[2] > Close[3] && (Close[0] < Close[1] || Close[0] == Close [1]))
                {
                    if(Finding_Peaks(RSI(14,3)[2],RSI(14,3)[1],RSI(14,3)[0]))//Captures the high point
                    {
                        DrawDiamond("RSI Peak " + CurrentBar, true, 1 , High[0] + .03, Color.MediumTurquoise);
                        rsi_high_value = RSI(14,3)[1];
                        rsi_high = CurrentBar;
                        DrawLine("RSI line Up " + CurrentBar, true, CurrentBar - (rsi_low - 1) , Low[CurrentBar - (rsi_low - 1)], 
                            CurrentBar - (rsi_low - 1), High[CurrentBar - (rsi_low - 1)], Color.Blue, DashStyle.Solid, 2);
                        Print(Time[0] + " High " + rsi_high_value );
                    }    
                    
                }
    Thanks

    #2
    Hello CaptainAmericaXX,

    Thanks for your posts.

    What output are you getting on your print statements? If none because of the error, try commenting out the drawline and run again.

    Comment


      #3
      Hello Paul,
      With the "RSI line Up" DrawLine commented out I get the current value of the RSI and the Diamond prints where it should.

      Comment


        #4
        Hello CaptainAmericaXX,

        Thanks for your reply.

        Taking a closer look at your code, it looks like the RSI Line up code may not be what you want. I note that in the RSI Line down code you draw high to low and in the RSI Line up codes you are drawing low to low.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        636 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        366 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        107 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        569 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        571 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X