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

Chart Bar Colors

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

    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.

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

    Comment


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


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


          #5
          OK. Thank you for the clarification Josh.

          Comment


            #6
            Originally posted by Zeos6 View Post
            OK. Thank you for the clarification Josh.
            Have you been able to figure out how to do this? I have a similar requirement but BarBrushes[0] is returning null. I'm trying to find out if there is any other way to get the color of a price bar.. maybe using Chart methods. Thoughts?

            Comment


              #7
              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);
                              }
                      }
              The prints just show what each value is and which got assigned to BarBrushes[0].

              Please let us know if we may be of further assistance to you.
              Kate W.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_Kate View Post
                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()
                {
                ...
                Print(BarBrushes[0] + " BarBrushes[0]");
                Print(ChartBars.Properties.ChartStyle.UpBrush);
                Print(ChartBars.Properties.ChartStyle.DownBrush);
                }
                }
                The prints just show what each value is and which got assigned to BarBrushes[0].

                Please let us know if we may be of further assistance to you.
                Kate:
                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.

                -CV

                Comment


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


                    #10
                    Originally posted by NinjaTrader_Kate View Post
                    Hello 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.
                    Hi Kate:
                    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,
                    CV
                    Last edited by chaitunt; 04-22-2020, 12:02 PM.

                    Comment


                      #11
                      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 jclose, Today, 09:37 PM
                      0 responses
                      4 views
                      0 likes
                      Last Post jclose
                      by jclose
                       
                      Started by WeyldFalcon, 08-07-2020, 06:13 AM
                      10 responses
                      1,413 views
                      0 likes
                      Last Post Traderontheroad  
                      Started by firefoxforum12, Today, 08:53 PM
                      0 responses
                      10 views
                      0 likes
                      Last Post firefoxforum12  
                      Started by stafe, Today, 08:34 PM
                      0 responses
                      10 views
                      0 likes
                      Last Post stafe
                      by stafe
                       
                      Started by sastrades, 01-31-2024, 10:19 PM
                      11 responses
                      169 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Working...
                      X