Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Issue with BackBrush
Collapse
X
-
Issue with BackBrush
So I'm just trying to get BackBrush to paint green when an up ema crossover trend is occurring and red when a downtrend ema crossover is occurring on the MACD. This works, but only for 15-20 minutes after I open up ninjatrader, then it stops painting when the crossover happens, it's almost like the memory is full and it can't do it anymore?? attaching the code and screenshot. Any help would be appreciated, thanks.Tags: None
-
Hello tvaughan4,
Thanks for your post.
Whenever a script is not working as expected, the first check would be the "log" tab of the control center. In the case of this indicator you will see a message in the "Log" tab of the control center advising, "NinjaScript myMACD30minTrend: Brush series exceeds the maximum number (65535) of unique brushes. Please adjust code to use fewer brushes."
The code that you have in the //trend color section are creating a new bush on every tick (your indicator is set to Calculate.OnEachTick). As you are using 3 brushes, 2 of which are actually using Opacity, the brushes can be created as private brushes and their colors (all three) can be set in State.SetDefaults and the two that are using 25% opacity can be set once in State.Configure.
For example:
at the class level, create a private brush: private Brush UpColor;
in State.SetDefaults, assign the color: UpColor = Brushes.Green;
in State.Configure, set the opacity:
Brush temp = UpColor.Clone(); //Copy the brush into a temporary brush
temp.Opacity = 25 / 100.0; // set the opacity
temp.Freeze(); // freeze the temp brush
UpColor = temp; // assign the temp brush value to UpColor.
In OnBarUpdate():
if (Value[0] > Avg [0])
{
BackBrush = UpColor;
- Likes 1
-
Hello tvaughan,
Thanks for your reply.
Yes. I've created a short video that shows how to use the Ninjascript indicator wizard to generate code that you can then copy into your indicator to get the the code needed for, in this case, a public brush. Basically I create an indicator that I call "source" that would have one of every type of input, one plot, one line, one added data series and one custom series and the wizard will generate all of the code needed which you can then either see how it is done or copy paste if you wish. The indicator would not be functional, just as reference source that you can study.
To avoid conflicts note that you would have remove the private Brush UpColor;, from my earlier code example and set the name of the public brush to UpColor.
- Likes 1
Comment
-
Hello @NinjaTrader_PaulH
I cannot figure out whether your sample code applies only to case Value[0] > Avg [0], or not.
Please could you confirm or explain whether one would need as many Brush temp depending on the number of different results generated by the logic applied in OnBarUpdate for determining the background color. In this case when Value[0] > Avg [0] becomes Value[0] < Avg [0] does the code need to be to be integrated with another temporary brush (say from green to red)?
Thank you
Comment
-
Hello guidoisot,
Thanks for your post.
The original posted provided his code which colors the background either of two colors. My example was showing how to create a custom bush once in State.Configure. Yes, you would need two for the original posters code as I only showed one for an example of how to do it.
- Likes 1
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
646 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
367 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
107 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
569 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
573 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment