• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NT8.B6: Programmatically drawing Rectangles throws error

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

    NT8.B6: Programmatically drawing Rectangles throws error

    I am working on an indicator using Rectangles and I keep on seeing the following error in the Log:

    Failed to call OnRender for 'Rectangle': 'Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index'
    I made a test indicator to see if this error can be reproduced by just drawing a Rectangle. Attached to this post is a copy of my test indicator. Please feel free to test it on your end to see if you can observe the same error. Below is the code:

    Code:
    public class RectangleObjectTest : Indicator
    	{
    		protected override void OnStateChange()
    		{
    			if (State == State.SetDefaults)
    			{
    				Description							= @"Testing the Rectangle drawing object";
    				Name								= "RectangleObjectTest";
    				Calculate							= Calculate.OnEachTick;
    				IsOverlay							= true;
    				DisplayInDataBox					= true;
    				DrawOnPricePanel					= true;
    				DrawHorizontalGridLines				= true;
    				DrawVerticalGridLines				= true;
    				PaintPriceMarkers					= true;
    				ScaleJustification					= NinjaTrader.Gui.Chart.ScaleJustification.Right;
    				//Disable this property if your indicator requires custom values that cumulate with each new market data event. 
    				//See Help Guide for additional information.
    				IsSuspendedWhileInactive			= true;
    			}
    			else if (State == State.Configure)
    			{
    			}
    		}
    
    		protected override void OnBarUpdate()
    		{
    			//Add your custom indicator logic here.
    			
    			if(CurrentBar < 60) return;
    			
    			Draw.Rectangle(this, "myRectangle", false, Time[0], Close[0], Time[60], Open[0], Brushes.DodgerBlue, Brushes.LightBlue, 5);
    		}
    	}
    On a live chart with this indicator attached, the error would usually occur when you switch from a fast timeframe to a slower timeframe. For example, I would almost always see the error when I switch the chart from 1 minute to Daily or 1 second to Daily. It doesn't always appear but it does when you do it a couple of times. In the main indicator I am working on I am drawing tens of Rectangles and when this appears, the log is flooded with the error above. In just one chart it doesn't cause the platform to crash but on several charts (and if the indicator is drawing multiple rectangles at a time) it would eventually.
    Attached Files

    #2
    And does :

    Code:
    if(CurrentBar <= 60) return;
    help any?

    Comment


      #3
      The line:

      if(CurrentBar <= 60) return;
      Simply checks whether there are enough bars to draw the rectangle since its length extend from Time[0] to Time[60]. It is required to draw such a Rectangle.
      Last edited by karlomacariola; 11-11-2015, 12:08 AM.

      Comment


        #4
        Ah sorry. I thought you were asking what that line is for then I saw the "=" sign. I did try to change the condition to "<=" but no joy it doesn't help.

        Comment


          #5
          Hello,

          Thank you for the report on this.

          I do see this on my end as well, I will forward this to development for further review to see if this is expected or should be eliminated.

          I look forward to being of further assistance.
          JesseNinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Jesse View Post
            Hello,

            Thank you for the report on this.

            I do see this on my end as well, I will forward this to development for further review to see if this is expected or should be eliminated.

            I look forward to being of further assistance.
            Thanks for looking into this. For the record I get this screen when I run my indicator that renders many Rectangles when I change timeframes: http://i.imgur.com/uiEVaFD.jpg

            It's hard to ignore.

            Comment


              #7
              any news about that problem?
              I still can't draw rectangles, it worked in one of the old beta versions, but on 8.0.0.10 I get the exact same exception ("Failed to call onRender for Rectangle - Index was out of range"..)
              I debugged it and the exception is thrown from @Shapes.cs - line 454 (from IsVisibleOnChart method)

              I use the following method to draw rectangle:

              Draw.Rectangle(NinjaScriptBaseowner,stringtag,boolisAutoScale,DateTimestartTime,doublestartY,DateTimeendTime,doubleendY,Brushbrush,BrushareaBrush,intareaOpacity,booldrawOnPricePanel)

              Comment


                #8
                Hello,

                Thank you for the reply.

                I am unable to reproduce the before mentioned error any longer and see the original code posted is working.

                I did note with the original code, the opacity was set to 5 which would be 5% visible 95% transparent. Also AutoScale is false and if this was applied to a secondary panel it would not be visible.

                Please try the following line of code, and ensure the indicator is set to IsOverlay = true;

                Code:
                if(CurrentBar < 60) return;
                			Draw.Rectangle(this, "myRectangle", true, Time[0], Close[0], Time[60], Open[0], Brushes.Red, Brushes.Red, 100);

                After ensuring I had at least 60 bars on the chart, I was able to see a rectangle being plotted.

                If you are any other overload set as you described in the post, please include the actual syntax you are using so I could test the actual code being used.


                Please let me know if I may be of further assistance.
                JesseNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by aslane, Today, 01:29 PM
                1 response
                9 views
                0 likes
                Last Post aslane
                by aslane
                 
                Started by itrader46, Today, 01:09 PM
                0 responses
                5 views
                0 likes
                Last Post itrader46  
                Started by elnoppo, Today, 12:38 PM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_Kate  
                Started by TradingRocks, Today, 11:44 AM
                1 response
                10 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by Brillo, Today, 11:39 AM
                2 responses
                11 views
                0 likes
                Last Post Brillo
                by Brillo
                 
                Working...
                X