Is it possible to obtain the colors set for the up bar color and the down bar color in the chart programmatically? I would like to adjust my drawing colors to the up/down bar colors set but add opacity to them (or use RGBA versions). Suggestions would be appreciated. Thank you.
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
Chart Bar Colors
Collapse
X
-
Chart Bar Colors
Hi,
Is it possible to obtain the colors set for the up bar color and the down bar color in the chart programmatically? I would like to adjust my drawing colors to the up/down bar colors set but add opacity to them (or use RGBA versions). Suggestions would be appreciated. Thank you.Tags: None
-
Hello,
Thanks for your post.
To program the up and down bar colors as well as set the opacity, your code will look something like the following snippet.
// Sets the color of the current bar to blue if trending upward, on bar close. Also sets the opacity to 75%.
if (IsRising(Close[0])){
BarBrush = Brushes.Blue;
BarBrush.Opacity = 0.75;
}
// Sets the color of the current bar to orange if trending downward, on bar close. Also sets the opacity to 25%.
if (IsFalling(Close[0])){
BarBrush = Brushes.Orange;
BarBrush.Opacity = 0.25;
}
The following help guide documentation on working with brushes will go into further detail on how to choose specific colors.
Working With Brushes
http://ninjatrader.com/support/helpG...th_brushes.htm
If you have any further questions please let me know.Josh G.NinjaTrader Customer Service
-
Thank you for the reply Josh, but that is not what I was asking.
I clearly asked how to retrieve the color used for the up bar and for the down bar on the chart, not how to paint bars based on a condition.
When a new chart is being created, one of the properties you get to choose is the 'Color for down bars' and the 'Color for up bars'. I would like to retrieve those colors (brushes) within my indicator code, and apply an opacity (alpha) to those colors.
Comment
-
Hello,
This is not possible to do.
You can use BarBrushes[0] to get the current bar color, but this will only return the color of a bar in which an explicit color overwrite was used. Otherwise it will return null.
Our help guide documentation explains BarBrushes in greater detail.
http://ninjatrader.com/support/helpG...barbrushes.htm
If you have any further questions please let me know.Josh G.NinjaTrader Customer Service
Comment
-
Originally posted by Zeos6 View PostOK. Thank you for the clarification Josh.
Comment
-
Hello chaitunt,
Thank you for your reply.
If BarBrushes[0] returns null, you can assume it's using the default settings for the brushes. You can find out what those are by getting the UpBrush and DownBrush and then assign the appropriate value to BarBrushes[0] by checking the bar direction. Here's an example:
Code:protected override void OnBarUpdate() { if(ChartBars != null) { if (BarBrushes[0] == null) { if (Open[0] > Close[0]) { BarBrushes[0] = ChartBars.Properties.ChartStyle.DownBrush; } if(Open[0] < Close[0]) { BarBrushes[0] = ChartBars.Properties.ChartStyle.UpBrush; } } Print(BarBrushes[0] + " BarBrushes[0]"); Print(ChartBars.Properties.ChartStyle.UpBrush); Print(ChartBars.Properties.ChartStyle.DownBrush); } }
Please let us know if we may be of further assistance to you.
Kate W.NinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_Kate View PostHello chaitunt,
Thank you for your reply.
If BarBrushes[0] returns null, you can assume it's using the default settings for the brushes. You can find out what those are by getting the UpBrush and DownBrush and then assign the appropriate value to BarBrushes[0] by checking the bar direction. Here's an example:
Code:protected override void OnBarUpdate() { ... Print(BarBrushes[0] + " BarBrushes[0]"); Print(ChartBars.Properties.ChartStyle.UpBrush); Print(ChartBars.Properties.ChartStyle.DownBrush); } }
Please let us know if we may be of further assistance to you.
Thank you very much for the reply. I have tried DownBrush and UpBrush and they are printing the values set in the indicator settings but they are not the values actually used to paint the bars. Let me explain the overall context. Please see the attached chart. I use a proprietary indicator, which does a bunch of calculations and colors the bars either red (for down trend bar)/blue (for up trend bar) or lime (for neutral bar). I am trying to find out a bar's color on its close. What I have found out so far is that Count of BarBrushes is 0. (Consequently, BarBrush[0]/BarBrush[1] are returning null.) And, like I said, the values that DownBrush and UpBrush are returning are the defaults.
If BarBrush is not used and defaults are not used how else a bar can get painted? Unless there are other objects that maintain this information besides BarBrush the only thing I can think of is that the indicator is resetting the BarBrushes to null after each bar's close. If you think that's the only option can you advise if there is some sort of callback that we can rely on when the bar is painted?
This information is foundational to the strategy that I'm working on. Appreciate your insights. Thanks again for your help.
-CV1 Photo
Comment
-
Hello Chaitunt,
Thank you for your reply.
Now that I more fully understand what you're trying to do, what you're experiencing is expected. Each indicator has an empty bar brush collection in which it can control the color of each bar. These are separate from each other and one indicator can't access the bar brush collection of another.
The solution is to check the same condition as the other indicator in which paints the bars originally to duplicate the same logic.
Unfortunately unless the other script explicitly exposes a signal or Brush series, there is no way around this as the BarBrushes collection is only visible for the script that sets it. An example would be:
Indicator 1 sets BarBrushes to Brushes.Red for ALL bars.
Indicator 2 Reads BarBrushes, but it reports as null for ALL bars.
If the indicator that paints the bars is a third party indicator, it most likely wouldn't be possible to modify the indicator to expose the necessary information as most of those are provided as a compiled assembly where the code cannot be directly accessed. If that's the case, you may be able to reach out to the vendor you got the indicator from to see if they could make that modification for you.
Please let us know if we may be of further assistance to you.
Kate W.NinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_Kate View PostHello Chaitunt,
If the indicator that paints the bars is a third party indicator, it most likely wouldn't be possible to modify the indicator to expose the necessary information as most of those are provided as a compiled assembly where the code cannot be directly accessed. If that's the case, you may be able to reach out to the vendor you got the indicator from to see if they could make that modification for you.
Please let us know if we may be of further assistance to you.
Thanks very much for the detailed response. The vendor hasn't been very helpful, unfortunately. I'll try again. That said, I wanted to find out if there is any sort of chart/GUI related callback/event handler that I can implement that gets called once a bar is painted. Please advise.
Another option I'm thinking is if there is any sort of mechanism to export meta information about bars (colors etc.) as data. The only option I see is to save as image.
Thanks,
CVLast edited by chaitunt; 04-22-2020, 12:02 PM.
Comment
-
Hello chaitunt,
Thank you for your reply.
No, there would not be any way to find the colors other than what I've already provided - you can get the default chart bar colors but unless an indicator is exposing its bar brush data you wouldn't be able to tell from one indicator what color another indicator has painted a bar.
There is also not a supported method to export meta information such as bar color from a chart.
Please let us know if we may be of further assistance to you.Kate W.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by linkcou, Today, 07:01 AM
|
0 responses
1 view
0 likes
|
Last Post
by linkcou
Today, 07:01 AM
|
||
Started by brunoviveiros, 02-17-2020, 05:31 AM
|
4 responses
63 views
0 likes
|
Last Post Today, 06:25 AM | ||
Started by volIQ, 03-27-2024, 04:28 PM
|
3 responses
21 views
0 likes
|
Last Post
by RJay
Today, 05:41 AM
|
||
Started by Nickgiaco, 02-26-2024, 10:23 AM
|
2 responses
72 views
0 likes
|
Last Post Today, 05:12 AM | ||
Started by Johndc, Today, 04:39 AM
|
0 responses
8 views
0 likes
|
Last Post
by Johndc
Today, 04:39 AM
|
Comment