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
Get the default bar colors for a series
Collapse
X
-
Get the default bar colors for a series
How do I get the default colors for up and down bars that are set in the series dialog? I want to create an indicator to color bars but I want to use these colors so using properties like BarColor will work (e.g. HeikenAshi - but it uses it's own colors). -
Thanks for your reply Patrick.
I used Heiken Ashi as an example of an indicator that colors the bars. The issue is it creates its own properties for the up and down colors, it does not use the defaults set in the Series Dialog.
If I'm creating my own indicator to do something similar to what Heiken Ashi does (draw and paint my own bars), how do I access the colors that are set in the Series Dialog so that I can use those colors to paint my bars?
I've used ChartControl.UpColor/DownColor but they seem to only be set for the last series in the chart.
Also, if from another indicator, I use BarColor to set the color of a specific bar, it doesn't call the Plot method, it plots the bar its own way. Is there a way to fix that?
To reproduce (using Heiken Ashi since it's the closest match to intended behavior):
- Modify HeikenAshi to have the following two lines in the Plot method after the initial null checks:
Code:brushUp.Color = ChartControl.UpColor; brushDown.Color = ChartControl.DownColor;
- Now go to a chart containing two data series and the Heiken Ashi indicator.
- Change the default bar colors for each and click Apply
- Note only one data series changes color
- Now create a new indicator that says if you have an up bar that is after a down bar, color it Blue
- Note that the blue bars are not drawn using the Plot method from Heiken Ashi (Heiken Ashi re-draws all visible bars in the range it seems so I think we really shouldn't have seen a change. The point though is the Plot method does not seem to be getting called here).
Comment
- Modify HeikenAshi to have the following two lines in the Plot method after the initial null checks:
-
Hello wbennettjr,
You can use ChartControl.BarsArray[0].BarsData.ChartStyle.UpColor to specify the bar series.
Also, if from another indicator, I use BarColor to set the color of a specific bar, it doesn't call the Plot method, it plots the bar its own way. Is there a way to fix that?
Comment
-
Thanks Patrick! I'll give that a try.
To answer your question:
I added the code to HeikenAshi:
Code:public override void Plot(Graphics graphics, Rectangle bounds, double min, double max) { if (Bars == null || ChartControl == null) return; [B]brushUp.Color = BarColorUp; brushDown.Color = BarColorDown;[/B] ...
Code:/// <summary>Test bar colors.</summary> [Description("Test bar colors.")] public class _TestBarColors : Indicator { protected override void OnBarUpdate() { if (Open[0] < Close[0] && Open[1] > Close[1]) BarColor = Color.Blue; } }
Comment
-
I'm guessing because we're in the context of the other indicator, it doesn't know that HeikenAshi is responsible for the bar drawing. So the question really is: Is there a way to call another indicator to let it know to redraw a bar with different attributes? Or, maybe set which indicator is responsible for drawing the bars?
Comment
-
Hello wbennettjr,
That is correct, the Heiken Ashi is not aware of the other indicator and vice versa. There is no method or function to set which indicator alters the bar. The Heiken Ashi indicator overrides the plot method and uses it's own custom drawing. If you are curious on how this works please go to Tools > Edit NinjaScript > Indicator > CustomPlotSample.
If you need to interact with the Heiken Ashi to change bars based on your conditions, you may wish to right click in the Heiken Ashi while viewing it in the NinjaScript Editor and select Save As and provide a new name. This way you have another Heiken Ashi that you can alter.
Comment
-
Thanks Patrick!
I figured it'd be a longshot but was hoping there was some way without putting the coloring logic in the indicator. Like I said, I'm not using the Heiken Ashi in my trading, I have my own indicator - just using Heiken Ashi in the post as a reference since it is the closest stock indicator in functionality to what I'm doing.
I'm thinking I'll try separating the bar drawing into a separate class and then use that from both indicators. It's not ideal but much better than than putting the coloring logic in the bar drawing indicator.
Comment
-
-
You would use OnRender() in NinjaTrader 8: http://ninjatrader.com/support/helpG...s/onrender.htm
Comment
-
I am using OnRender(). There is no BarsData.ChartStyle.UpColor (or UpBrush) property on ChartControl.BarsArray[0] anymore. I'm asking where the property has been moved to.
Comment
-
-
Originally posted by NinjaTrader_PatrickH View PostHello wbennettjr,
Thank you for your response.
You would use ChartBars.Properties.ChartStyle.DownBrush or ChartBars.Properties.ChartStyle.UpBrush.
And how can I set this brushes?
This way not work
PHP Code:ChartBars.Properties.ChartStyle.ChartStyleType = Gui.Chart.ChartStyleType.CandleStick;
I saw this way:
PHP Code:DefaultChartStyle = Gui.Chart.ChartStyleType.CandleStick;
Comment
-
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by kujista, Today, 05:44 AM
|
0 responses
5 views
0 likes
|
Last Post
by kujista
Today, 05:44 AM
|
||
Started by ZenCortexCLICK, Today, 04:58 AM
|
0 responses
6 views
0 likes
|
Last Post Today, 04:58 AM | ||
Started by sidlercom80, 10-28-2023, 08:49 AM
|
172 responses
2,281 views
0 likes
|
Last Post
by sidlercom80
Today, 04:40 AM
|
||
Started by Irukandji, Yesterday, 02:53 AM
|
2 responses
18 views
0 likes
|
Last Post
by Irukandji
Today, 03:55 AM
|
||
Started by adeelshahzad, Today, 03:54 AM
|
0 responses
8 views
0 likes
|
Last Post
by adeelshahzad
Today, 03:54 AM
|
Comment