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!
See more
See less

Partner 728x90

Collapse

Get the default bar colors for a series

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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).

    #2
    Hello wbennettjr,

    Thank you for your post.

    Are you asking how to pull the default colors for the Data Series, the indicator HeikenAshi, or how to set the colors of the Data Series or HeikenAshi?

    Comment


      #3
      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):
      1. 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;
      2. Now go to a chart containing two data series and the Heiken Ashi indicator.
      3. Change the default bar colors for each and click Apply
      4. Note only one data series changes color
      5. Now create a new indicator that says if you have an up bar that is after a down bar, color it Blue
      6. 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


        #4
        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?
        Can you provide further details? Such as a screenshot of the "bar" being plotted in it's own way?

        Comment


          #5
          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]
                      ...
          I created this simple indicator:

          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;
                  }
              }
          Added HeikenAshi and the indicator to the chart and this is the result: See attachment.
          Attached Files

          Comment


            #6
            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


              #7
              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


                #8
                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


                  #9
                  Patrick,

                  Where are these properties in NT8? Seems they have been moved.

                  Thanks

                  Comment


                    #10
                    You would use OnRender() in NinjaTrader 8: http://ninjatrader.com/support/helpG...s/onrender.htm

                    Comment


                      #11
                      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


                        #12
                        Hello wbennettjr,

                        Thank you for your response.

                        You would use ChartBars.Properties.ChartStyle.DownBrush or ChartBars.Properties.ChartStyle.UpBrush.

                        Comment


                          #13
                          Cool! Thanks! DownBrushDX/UpBrushDX works even better.

                          Comment


                            #14
                            Originally posted by NinjaTrader_PatrickH View Post
                            Hello 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
                            since gives error "The property or indexer 'NinjaTrader.NinjaScript.ChartStyles.ChartStyle.Ch artStyleType' cannot be used in this context because the set accessor is inaccessible. , unless editor tooltip show both { set; get; }

                            I saw this way:
                            PHP Code:
                            DefaultChartStyle         Gui.Chart.ChartStyleType.CandleStick
                            but, it work only at State.Setdefaults, while I need to set colors at State.Configure.
                            fx.practic
                            NinjaTrader Ecosystem Vendor - fx.practic

                            Comment


                              #15
                              As I see, DefaultChartStyle not work too:

                              Last edited by fx.practic; 08-02-2017, 06:08 AM.
                              fx.practic
                              NinjaTrader Ecosystem Vendor - fx.practic

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by kujista, Today, 05:44 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post kujista
                              by kujista
                               
                              Started by ZenCortexCLICK, Today, 04:58 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post ZenCortexCLICK  
                              Started by sidlercom80, 10-28-2023, 08:49 AM
                              172 responses
                              2,281 views
                              0 likes
                              Last Post sidlercom80  
                              Started by Irukandji, Yesterday, 02:53 AM
                              2 responses
                              18 views
                              0 likes
                              Last Post Irukandji  
                              Started by adeelshahzad, Today, 03:54 AM
                              0 responses
                              8 views
                              0 likes
                              Last Post adeelshahzad  
                              Working...
                              X