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

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.
    Paul H.NinjaTrader Customer Service

    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.
        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by junkone, Today, 11:37 AM
        2 responses
        13 views
        0 likes
        Last Post junkone
        by junkone
         
        Started by frankthearm, Yesterday, 09:08 AM
        12 responses
        43 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by quantismo, 04-17-2024, 05:13 PM
        5 responses
        35 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by proptrade13, Today, 11:06 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by love2code2trade, 04-17-2024, 01:45 PM
        4 responses
        35 views
        0 likes
        Last Post love2code2trade  
        Working...
        X