if (CCIPlot[0] > obLevelE)
{
Draw.Region(this, "CCIup", CurrentBar, 0, CCIPlot, obLevelE, Brushes.Red, opacity4, Displacement);
}
if (CCIPlot[0] < osLevelE)
{
Draw.Region(this, "CCIdn", CurrentBar, 0, CCIPlot, osLevelE, Brushes.Lime, opacity4, Displacement);
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
If something wrong with Draw.Region?
Collapse
X
-
If something wrong with Draw.Region?
I am trying to get the region to only fill when the CCI value exceeds my defined value, yet it colors the area below as well regardless how I try to stop it from doing so. I've included a snippet for what I believe should trigger it to shade red if its over my overbought level, and lime if its under my oversold level. Can you please help me sort out why this would not work as intended?
Code:Last edited by Conceptzx; 01-24-2024, 05:34 AM.Tags: None
-
Hello Conceptzx,
Thank you for your post.
In both Draw.Region() methods, you have the startBarsAgo set to "CurrentBar" barsAgo and the endBarsAgo set to 0 barsAgo. This means the region will be drawn for every bar on the chart up to that bar where the condition was triggered. Each time the condition is triggered again, the existing Region object is updated to draw across all bars on the chart again. You mentioned you want it to, "only fill when the CCI value exceeds my defined value" - do you mean you only want it to fill for the bars on which the CCI is above/below the value? Please clarify what you are looking to achieve so I may better understand and assist you.
I look forward to your reply.
Comment
-
In that case, you would need to save the bar number on which the CCI crosses above the value and then draw the region up until it crosses below the value. You will then need a new tag for each new region that is drawn, as it will be more than just one region above and one region below. You need to create a new region object for each time the CCI crosses above/below the value.Originally posted by Conceptzx View PostIn the attached image where CCI exceeds my defined value, I only want it to fill red between the plot and the line while above the line, not from below the line to the plot.
A similar scenario has been discussed in the following thread:
Hello, I'm trying to draw a region whose color will depend on whether an indicator line is higher or lower than another indicator line. It just keeps giving me the same color, though. Could you please tell me what is incorrect with this syntax? I've simplified the issue with the following sample. I would be most grateful
As mentioned in that thread, there is an example indicator that uses different colored regions for different conditions. This indicator is publicly available on our NinjaTrader Ecosystem website:
Here is a basic guideline of how to import NinjaScript add-ons in NinjaTrader 8:
Note — To import NinjaScripts you will need the original .zip file.
To Import:- Download the NinjaScripts to your desktop, keep them in the compressed .zip file.
- From the Control Center window select the menu Tools > Import > NinjaScript Add-on...
- Select the downloaded .zip file
- NinjaTrader will then confirm if the import has been successful.
Critical - Specifically for some NinjaScripts, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press 'No'
Once installed, you may add the indicator to a chart by:- Right-click your chart > Indicators... > Select the Indicator from the 'Available' list on the left > Add > OK
Here is a short video demonstration of the import process:
Please let me know if I can be of further assistance.
The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
Comment
-
The CCI logic is built into this indicator, its not calling on the original CCI to calculate the plot.
I'm still confused here, are you suggesting something like this?
Code:if (CCIPlot[0] < obLevelE && CCIPlot[0] > osLevelE) { Draw.Region(this, "CCIneu", CurrentBar, 0, CCIPlot, obLevelE, Brushes.Transparent, 100, Displacement); Draw.Region(this, "CCIned", CurrentBar, 0, CCIPlot, osLevelE, Brushes.Transparent, 100, Displacement); } else if (CCIPlot[0] > obLevelE) { Draw.Region(this, "CCIup", CurrentBar, 0, CCIPlot, obLevelE, Brushes.Red, opacity4, Displacement); } else if (CCIPlot[0] < osLevelE) { Draw.Region(this, "CCIdn", CurrentBar, 0, CCIPlot, osLevelE, Brushes.Lime, opacity4, Displacement); }
Comment
-
This is not what I am suggesting; you are drawing one Region with the tag "CCIup" and another region with the tag "CCIdn" and both regions start on the first bar of the chart and go all the way up to the bar where the condition was triggered. That means the two objects will both be drawn and shade the region between the two provided values for the entirety of the chart. You will need to draw multiple separate regions that have different tags and start/end only when the CCI crosses above/below and then crosses back over to the other side in order to generate the desired result. The indicator I referenced adds info to the tag to generate new Region objects when conditions are met. For example:Originally posted by Conceptzx View PostThe CCI logic is built into this indicator, its not calling on the original CCI to calculate the plot.
I'm still confused here, are you suggesting something like this?
Code:if (CCIPlot[0] < obLevelE && CCIPlot[0] > osLevelE) { Draw.Region(this, "CCIneu", CurrentBar, 0, CCIPlot, obLevelE, Brushes.Transparent, 100, Displacement); Draw.Region(this, "CCIned", CurrentBar, 0, CCIPlot, osLevelE, Brushes.Transparent, 100, Displacement); } else if (CCIPlot[0] > obLevelE) { Draw.Region(this, "CCIup", CurrentBar, 0, CCIPlot, obLevelE, Brushes.Red, opacity4, Displacement); } else if (CCIPlot[0] < osLevelE) { Draw.Region(this, "CCIdn", CurrentBar, 0, CCIPlot, osLevelE, Brushes.Lime, opacity4, Displacement); }
Draw.Region(this, "reg1" + sb1, CurrentBar - sb1 + 1, 0, Upper, Lower, Brushes.Transparent, wideColor, opacity, Displacement);
Additionally, the regions do not start at the beginning of the chart and end on the current bar. You will need to indicate which bar you would like the regions to start on, which is when the crossover occurs.
Please let us know if we may be of further assistance.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
595 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
343 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
103 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
556 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
554 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|
Comment