Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Draw.Region not rendering
Collapse
X
-
Draw.Region not rendering
I am developing this indicator and am not able to shade regions between 2 lines as in image below.I have attached the code.Last edited by NinjaTrader_BrandonH; 07-23-2023, 01:19 PM.Tags: None
-
Hello Graci117,
Thanks for your post.
I see you are using Draw.Region() syntax that uses a Series series argument and a double price argument, but you are using two series in your method.
You should make sure to use the Draw.Region() syntax that lets you specify two series as the arguments. The syntax could be seen below.
Draw.Region(NinjaScriptBase owner, string tag, int startBarsAgo, int endBarsAgo, ISeries<double> series1, ISeries<double> series2, Brush outlineBrush, Brush areaBrush, int areaOpacity, [int displacement])
Draw.Region(): https://ninjatrader.com/support/help...ion.htm
When running the script note for any errors that might appear.
Do you see any error messages appearing in the Log tab of the Control Center when running the script? If so, what exactly does the error report?
Have you added debugging prints to the script to understand how your logic in the script is behaving?
It is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.
Below is a link to a forum post that demonstrates how to use prints to understand behavior.
https://ninjatrader.com/support/foru...121#post791121<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
-
Thank you Brandon for your response.I looked at the log and there are no errors.I also tried and copy the exact same syntax from some of the other indicators for Draw.Region and I do have correct number of parameters. Print statement in this case does not help as the indicator displays correclty, however it is not filling the areas.Could you possibly look at the code attached and let me know what I am missing?
Thanks!!
Comment
-
I changed the code to the following based on one of the other examples I saw and it still does not render the shading. I also don't know how to shade between the overbought and the oversold areas as in the first image.
if(Main[0]>Signal[0]) {PlotBrushes[0][0] = Brushes.Green;}
else {PlotBrushes[0][0] = Brushes.Red;}
//signal
if(Main[0]>Signal[0]) {PlotBrushes[1][0] = Brushes.Green;}
else {PlotBrushes[1][0] = Brushes.Red;}
if (Cross[0] == 1 || (savedUBar > savedDBar))
{
Draw.Region(this, "Up" + CurrentBar, CurrentBar - savedUBar + 1, 0, Main,Signal, Brushes.Green, Brushes.Green, 50);
}
if (Cross[0] == -1 || (savedDBar > savedUBar))
{
Draw.Region(this, "Dwn" + CurrentBar, CurrentBar - savedDBar + 1, 0, Main,Signal, Brushes.Red, Brushes.Red, 50);
}
Comment
-
Hello Graci117,
Thanks for your notes.
In the code you shared I see that you have the DrawOnPricePanel property set to true in State.SetDefaults but you are wanting to draw a region on the indicator panel, not the price panel.
You should change the DrawOnPricePanel property to false in State.SetDefaults for the Draw.Region() method to draw on the indicator panel.
As for drawing a region between the overbought/oversold lines and the upper/lower lines, you would need to create custom Series<double> variables for the overbought line, oversold line, upper line, and lower line. Then assign the value of those lines to the custom Series variables and use those custom Series variables when calling the Draw.Region() method.
Note to use MaximumBarsLookBack.Infinite when instantiating those custom Series variables, such as obline = new Series<double>(this, MaximumBarsLookBack.Infinite);
See this help guide page for more information about custom Series: https://ninjatrader.com/support/help...t8/seriest.htm<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
Comment
-
Thanks so much Brandon for the tips.I changed the DrawOnPricePanel property to false and the region still didn't render. I also added 4 new Series variables for the OB and OS and those don't also render. I am attaching my updated code.Could you please help? Thanks so much!!Originally posted by NinjaTrader_BrandonH View PostHello Graci117,
Thanks for your notes.
In the code you shared I see that you have the DrawOnPricePanel property set to true in State.SetDefaults but you are wanting to draw a region on the indicator panel, not the price panel.
You should change the DrawOnPricePanel property to false in State.SetDefaults for the Draw.Region() method to draw on the indicator panel.
As for drawing a region between the overbought/oversold lines and the upper/lower lines, you would need to create custom Series<double> variables for the overbought line, oversold line, upper line, and lower line. Then assign the value of those lines to the custom Series variables and use those custom Series variables when calling the Draw.Region() method.
Note to use MaximumBarsLookBack.Infinite when instantiating those custom Series variables, such as obline = new Series<double>(this, MaximumBarsLookBack.Infinite);
See this help guide page for more information about custom Series: https://ninjatrader.com/support/help...t8/seriest.htm
DrawRegionHelp.txt
Comment
-
Hello Graci117,
Thanks for your notes.
I have made an example script using the code you shared that you could view demonstrating drawing a region between the plots on the indicator panel, drawing a region between the upper line and overbought line, and drawing a region between the lower line and oversold line.
See the attached image showing the script working and drawing regions.
You could compare the attached example script to your script to see where differences might be.
TMODrawRegionExample.zip
Note that if your script is not behaving as expected, you should add debugging prints to the script that print out the values being used in your Draw.Region() method and prints out the values used in the conditions to call Draw.Region() if applicable.
Below is a link to a forum post that demonstrates how to use prints to understand behavior.
https://ninjatrader.com/support/foru...121#post791121<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
- Likes 1
Comment
-
Thanks so much! It totally worked!!Originally posted by NinjaTrader_BrandonH View PostHello Graci117,
Thanks for your notes.
I have made an example script using the code you shared that you could view demonstrating drawing a region between the plots on the indicator panel, drawing a region between the upper line and overbought line, and drawing a region between the lower line and oversold line.
See the attached image showing the script working and drawing regions.
You could compare the attached example script to your script to see where differences might be.
Note that if your script is not behaving as expected, you should add debugging prints to the script that print out the values being used in your Draw.Region() method and prints out the values used in the conditions to call Draw.Region() if applicable.
Below is a link to a forum post that demonstrates how to use prints to understand behavior.
https://ninjatrader.com/support/foru...121#post791121
Comment
-
I am also struggling to get the Draw.Region() to show in Panel 2. Where is the example script from Post #7? I have created the custom series, set DrawOnPricePanel = false and set the MaximumBarsLookBack for the Series' to Infinite. All values are looking good when printing debug statements and when I double click other drawings my "regionFill" objects are showing in the 'Drawing Objects' window but not displaying. I have tried the many different options of Draw.Region() trying to get it to display.
Comment
-
Hello PhillT,
To download the file in post # 7 you must have completed the forum registration link sent to the email used to register your forum user.
Are you printing bar time and the bars ago values used for the start and end bar of the draw object and the values of each series on these bars?
Please attach the output from the prints to your reply, and a screenshot of the chart scrolled to where the object should be appearing.
Please have the data box open with the mouse placed over the ending bar for the object so we can match up the output with the screenshot.Chelsea B.NinjaTrader Customer Service
Comment
-
Thank You NinjaTrader_ChelseaB! No idea why the link to the example .zip wasn't showing before, I see it now but still struggling. I actually went the RenderTarget.FillRectangle route to get my desired results but would love to figure this out for future use.
I am using startTime and endTime rather than barsAgo, though I tried many versions of the method. I will upload a few screenshots for more context.
Comment
-
Hello PhillT,
Please print the startTime and endTime if these are being used instead.
Also, just to ensure if there have been changes to State.SetDefaults, remove the instance of the script and add a new instance to the chart (so the new defaults are pulled).Chelsea B.NinjaTrader Customer Service
Comment
-
I was using Time[0] as the endTime and my startTime is days back but the method was only being called when a new High was made in the series. I would've thought this would draw from startTime up until Time[0] (now) but it displayed nothing even though it created the object.
I moved the Draw.Region() out of this condition and placed where I ONLY check that Time[0] > startTime and it's working just as expected! I'm thinking endTime being "now" but not continuing to call the method unless a new high formed was a problem. At least the placement location of the Draw.Region has made a difference and I've got the region shaded now.
Usually when I make changes to an Indicator file that is already loaded up I just press F5 on the chart to reload the data and my changes. Is this ineffective? Should I be in the habit of completely removing and re-adding the instance after making changes?
Thanks!
Comment
-
Hello PhillT,
"Usually when I make changes to an Indicator file that is already loaded up I just press F5 on the chart to reload the data and my changes. Is this ineffective? "
Defaults are only pulled for new instances. If you have made changes to State.SetDefaults in OnStateChange() it is necessary to remove the instance and add a new instance to pull the new default values. If the defaults have not be changed, you can reload the script (F5) to run any other changes.Chelsea B.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
576 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
334 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 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
553 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
551 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment