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

Change current bar color of a custom bar type

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

    Change current bar color of a custom bar type

    I am using a custom bar type where I do not have access to the code. I would like the current bar painted not green or red as it is painted by the proprietary bar type, but in another color. Is there a way to "overlay" the bar color with another one on the chart?

    #2
    Hello chris07,

    Thanks for your post.

    Yes, with a custom script you can color the bars as you wish.

    Please see the following methods that would allow you to color the bar and/or the outline of the candle

    https://ninjatrader.com/support/help...l?barbrush.htm
    https://ninjatrader.com/support/help...barbrushes.htm
    https://ninjatrader.com/support/help...tlinebrush.htm
    https://ninjatrader.com/support/help...inebrushes.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Paul,

      thank you for the pointers! I have created a new indicator, but this changes the color of all previous candles, but not the current one:


      // Sets the color of the current bar to transparent.
      BarBrushes[0] = Brushes.Transparent;


      the same thing happens when I use the sample code from the tutorial:

      if (CurrentBar < 0)
      return;

      // Sets the color of the current bar to transparent.
      BarBrushes[0] = Brushes.Transparent;

      Attached Files
      Last edited by chris07; 12-07-2021, 01:18 PM.

      Comment


        #4
        If I set

        if (CurrentBar > 0)
        return;


        no color change is made to any of the bars.

        (Sorry for the previous edits, I messed up and then corrected the > to < in the previous post)

        Comment


          #5
          Hello chris07,

          Thanks for your reply.

          If you are running the indicator with calculate.OnBarClose then [0] will be the current bar and the currently forming bar will not be known until it closes at which point your code will color that bar.

          If you want to color the currently forming bar then you will need to change the script calculate setting to Calculate.OnPriceChange or Calculate.OnEachTick.

          this code: if (CurrentBar > 0) return; Will not work because as soon as the 2nd historical bar is loaded to return. Return means don't do anything, so if the bar counter "CurrentBar" is greater than 0 (0 is the first bar of the data series) to then return and no further code is executed.



          Paul H.NinjaTrader Customer Service

          Comment


            #6
            Hi Paul,

            thank you for the explanations. I have set

            Calculate = Calculate.OnEachTick;

            however, now all the bars have their color changed.
            Attached Files

            Comment


              #7
              This also happens on normal candlestick bars.

              Will I need to tell it explicitly that all previous bars should have the original color?
              Last edited by chris07; 12-07-2021, 02:00 PM.

              Comment


                #8
                Hello chris07,

                Thanks for your reply.

                It looks like you are setting the bar brush to transparent.

                Can you clarify what you are intending?
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  The intention is to have the background color as bar color for the current bar. I could use white instead, but my background is set to an off white color. So I thought it would be more conventient to use transparent in case I change the background color.
                  Last edited by chris07; 12-07-2021, 02:10 PM.

                  Comment


                    #10
                    I have changed Transparent to Yellow, and this colors all bars Yellow. So this does not seem to change anything.

                    Comment


                      #11
                      Hello chris07,

                      Thanks for your reply.

                      I am probably misunderstanding what your goal is but here is what I see with your script, all bars transparent and just the outline remains.

                      Click image for larger version

Name:	Chris07-1.PNG
Views:	949
Size:	26.0 KB
ID:	1180841

                      If that is not what you are after, please elaborate on what you are wanting to see and/or post a screenshot that illustrates.

                      Paul H.NinjaTrader Customer Service

                      Comment


                        #12
                        Hi Paul,

                        I would like to have only the current bar color set as transparent. All previous candles should have their original color (green or red, for instance).

                        Comment


                          #13
                          It should look like this:
                          Attached Files

                          Comment


                            #14
                            Hello chris07,

                            Thanks for your reply.

                            Please try:

                            if (State != State.Realtime)
                            return;

                            BarBrushes[0] = Brushes.Transparent;

                            if (Close[1] > Open[1])
                            {
                            BarBrushes[1] = Brushes.Green;
                            }
                            else
                            {
                            BarBrushes[1] = Brushes.Red;
                            }
                            Paul H.NinjaTrader Customer Service

                            Comment


                              #15
                              Hi Paul,

                              this works perfectly. Thank you!

                              I am not sure though where the problem was exactly, except that there was something wrong with the previous bar color not assigned correctly. Could you explain briefly?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by alifarahani, Today, 09:40 AM
                              6 responses
                              31 views
                              0 likes
                              Last Post alifarahani  
                              Started by Waxavi, Today, 02:10 AM
                              1 response
                              17 views
                              0 likes
                              Last Post NinjaTrader_LuisH  
                              Started by Kaledus, Today, 01:29 PM
                              5 responses
                              13 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by Waxavi, Today, 02:00 AM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_LuisH  
                              Started by gentlebenthebear, Today, 01:30 AM
                              3 responses
                              17 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Working...
                              X