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
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#post791121Brandon H.NinjaTrader Customer Service
-
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.htmBrandon H.NinjaTrader Customer Service
Comment
-
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.
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#post791121Brandon H.NinjaTrader Customer Service
- Likes 1
Comment
-
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
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by burtoninlondon, Today, 12:38 AM
|
0 responses
5 views
0 likes
|
Last Post Today, 12:38 AM | ||
Started by AaronKoRn, Yesterday, 09:49 PM
|
0 responses
12 views
0 likes
|
Last Post
by AaronKoRn
Yesterday, 09:49 PM
|
||
Started by carnitron, Yesterday, 08:42 PM
|
0 responses
11 views
0 likes
|
Last Post
by carnitron
Yesterday, 08:42 PM
|
||
Started by strategist007, Yesterday, 07:51 PM
|
0 responses
13 views
0 likes
|
Last Post Yesterday, 07:51 PM | ||
Started by StockTrader88, 03-06-2021, 08:58 AM
|
44 responses
3,982 views
3 likes
|
Last Post
by jhudas88
Yesterday, 06:59 PM
|
Comment