The problem is: The BarBrushes array is empty anywhere I try to use it (OnStateChange when State == State.DataLoaded, and OnBarUpdate with Calculate.OnBarClose). Am I doing something wrong or is it a bug?
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!
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
NinjaTrader
BarBrushes has 0 items at all times
Collapse
X
-
BarBrushes has 0 items at all times
Hi, I am trying to create an indicator that paints candles differently when some conditions are met. Previous candle's colors can change on each bar close, so I can't really use BarBrush, so I'm trying to use BarBrushes instead.
The problem is: The BarBrushes array is empty anywhere I try to use it (OnStateChange when State == State.DataLoaded, and OnBarUpdate with Calculate.OnBarClose). Am I doing something wrong or is it a bug?Tags: None
-
I'm getting out of bounds exceptions when trying to set the colors, not null returns :/
I'm using the array directly to set the colors, I expected for it to have an item count equal to the amount of loaded bars, with null values where the candle's color wasn't overriden.
How should I go about setting these colors, if this is not how it works?
Comment
-
Originally posted by NinjaTrader_JoshG View PostCan you provide a short sample that produces this error? I think it may help to see how you are setting BarBrushes.
1. Create an empty indicator.
2.Inside of the OnStateChange() method:
Code:if(State == State.DataLoaded) { BarBrushes[0] = Brushes.Blue }
Printing BarBrushes.Count shows that it's item count is 0.
Comment
-
I would not expect for you to be able to access that index from State.DataLoaded
How are you setting BarBrushes inside OnBarUpdate() to produce the bounds error? The following snippet would set the current bar to the color orange when my condition is met.
Code:protected override void OnBarUpdate() { if (Close[0] > Open[0]) BarBrushes[0] = Brushes.Orange; }
Josh G.NinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_JoshG View PostI would not expect for you to be able to access that index from State.DataLoaded
How are you setting BarBrushes inside OnBarUpdate() to produce the bounds error? The following snippet would set the current bar to the color orange when my condition is met.
Code:protected override void OnBarUpdate() { if (Close[0] > Open[0]) BarBrushes[0] = Brushes.Orange; }
Code:BarBrushes[99] = Brushes.Orange
If the explanation is too messy I'll try to post a proper code sample when I get home.
Comment
-
Your sample is not too messy. The reason an out of bounds error is occurring is because a value is not being assigned to BarBrushes on each bar. I am just not certain why that is, so I will need to look into it.
If you describe what it is you are trying to accomplish I may be able to assist you more on how to achieve your goal.Josh G.NinjaTrader Customer Service
Comment
-
I managed to fix the out of bounds error in the OnBarUpdate() method by creating another indicator from scratch and moving it to the new one, I have absolutely no idea why that worked, as I made sure I was copying every piece of code I wrote to the other file.
The BarBrushes array really wasn't ready in the State.DataLoaded, and I had to populate the BarBrushes array with null values inside of OnBarUpdate() by doing:
Code:BarBrushes[0] = null;
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by warreng86, 11-10-2020, 02:04 PM
|
6 responses
1,360 views
0 likes
|
Last Post
by mathewlo
Today, 09:34 PM
|
||
Started by Perr0Grande, Today, 08:16 PM
|
0 responses
5 views
0 likes
|
Last Post
by Perr0Grande
Today, 08:16 PM
|
||
Started by elderan, Today, 08:03 PM
|
0 responses
9 views
0 likes
|
Last Post
by elderan
Today, 08:03 PM
|
||
Started by algospoke, Today, 06:40 PM
|
0 responses
10 views
0 likes
|
Last Post
by algospoke
Today, 06:40 PM
|
||
Started by maybeimnotrader, Today, 05:46 PM
|
0 responses
14 views
0 likes
|
Last Post Today, 05:46 PM |
Comment