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:
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'
Code: -
The line:
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
-
Originally 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.JesseNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by foxtrott21, Today, 08:27 AM
|
0 responses
1 view
0 likes
|
Last Post
by foxtrott21
Today, 08:27 AM
|
||
Started by jaypelle3, Today, 08:26 AM
|
0 responses
1 view
0 likes
|
Last Post
by jaypelle3
Today, 08:26 AM
|
||
Started by linkcou, Today, 07:01 AM
|
2 responses
18 views
0 likes
|
Last Post
by bltdavid
Today, 08:25 AM
|
||
Started by jaypelle3, Today, 08:25 AM
|
0 responses
1 view
0 likes
|
Last Post
by jaypelle3
Today, 08:25 AM
|
||
Started by jaypelle3, Today, 08:22 AM
|
0 responses
2 views
0 likes
|
Last Post
by jaypelle3
Today, 08:22 AM
|
Comment