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);
}
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
NT8.B6: Programmatically drawing Rectangles throws error
Collapse
X
-
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:
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: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'
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.Code: -
The line:
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.if(CurrentBar <= 60) return;Last edited by karlomacariola; 11-11-2015, 01:08 AM.
Comment
-
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
-
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.jpgOriginally posted by NinjaTrader_Jesse View PostHello,
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.
It's hard to ignore.
Comment
-
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
-
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.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
669 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
378 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
111 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
575 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
580 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment