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

Test colour Bar

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

    Test colour Bar

    hi,

    how can test the colour of the bar and the previus bar of one bar ? For example if I have a bar withe how can test this colour and how can test the colour of the previus bar (1 or 2 or 3) or the next bar ?

    Tanks

    e

    #2
    Unfortunately not possible in 6.5 - in our NT7 you could access the BarColorSeries - http://www.ninjatrader.com/support/h...olorseries.htm
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Could you elaborate on this? In NT7 I tried testing bar colors that had been set by some proprietary indicators without success, so I created a very simple scenario on my own and still had problems.

      My test chart was a 15-min ES chart for a single day's RTH session, which gave me 27 bars. The first screen shot below is the plain chart, with no indicators present.

      Then I wrote a very simple indicator called SetBarsBlue to color the bars blue. That indicator has nothing in the Variables region and nothing in the Properties region, and Initialize() does nothing but set Overlay=true. OnBarUpdate() is as follows:
      Code:
      protected override void OnBarUpdate()
      {
          BarColor = Color.Blue;
          CandleOutlineColor = Color.Blue;
      }
      With just that indicator applied to the chart the bars are painted blue as expected. The result is shown in the second screen shot below.

      Then I wrote an indicator called ReadBackBarColor to read the color information and output it to the Output window. This indicator also had nothing in either the Variables or Properties regions and also had an Initialize() routine that did nothing but set Overlay=true. Here's the code for OnBarUpdate():
      Code:
      protected override void OnBarUpdate()
      {
          if( CurrentBar < 2 )
              return;
          
          int ActiveBar = CurrentBar - 2;
          Print( "BarColor for bar " + ActiveBar.ToString() + ": " + BarColorSeries[2].Name );
          Print( "CandleOutlineColor for bar " + ActiveBar.ToString() + ": " + CandleOutlineColorSeries[2].Name );
          Print( "BarColor RGB for bar " + ActiveBar.ToString() + ": R " +
           BarColorSeries[2].R.ToString() + " G " + BarColorSeries[2].G.ToString() +
           " B " + BarColorSeries[2].B.ToString() );
          Print( "" );
      }
      I chose to skip two bars in ReadBackBarColor() just to have a little space between the current bar and the bar I was testing. Adding this indicator to the chart did not change the chart, which was expected, so there's not another chart screen shot. However, I've provided a screen shot showing a representative sample of the output that appeared in the Output window. And in fact all entries were like that, containing nothing but zeroes.

      The output of RGB was added after outputting .Name produced zeroes. I figured that perhaps there was something about the Name parameter I didn't understand so that it wasn't defined, but that I should certainly be able to get the RGB values. I was surprised to see more zeroes.

      And I also tried a version of SetBarsBlue with OnBarUpdate() changed as follows, with no effect:
      Code:
      protected override void OnBarUpdate()
      {
          BarColor = Color.FromKnownColor(KnownColor.Blue);
          CandleOutlineColor = Color.FromKnownColor(KnownColor.Blue);
      }
      I figure either there's something incredibly simple that I'm doing wrong, or else there's an issue here. Frankly I hope it's the former.
      Attached Files

      Comment


        #4
        MikeInMA, these color series are meant to be set only. This means they will return weird values if you try to get the value.
        AustinNinjaTrader Customer Service

        Comment


          #5
          Post #1 in this thread asks how the color of a bar can be tested. Post #2 indicates that while it's not possible in NT 6.5, in NT 7 you can do it by accessing the BarColorSeries. Post #2 also contains a link to documentation about BarColorSeries. The linked page contains this statement: "A color series type object. Accessing this property via an index value [int barsAgo] returns a color structure representing the referenced bar's color." (Emphasis added.)

          Note in my code snippets that I accessed BarColorSeries via an index value as per the documentation. Is that supposed to return a color structure or not? If not, it appears the documentation is very wrong. If so, it appears not to work as advertised.

          Comment


            #6
            MikeInMA, there is an important note below that text:

            "A color series type object. Accessing this property via an index value [int barsAgo] returns a color structure representing the referenced bar's color.

            Note: This will only return the color of a bar in which an explicit color overwrite was used. Otherwise it will return Color [Empty]."


            I wrote a quick script to test this out:
            Code:
            protected override void OnBarUpdate()
            {
                if (CurrentBar < 5) return;
                BarColorSeries[0] = Color.Blue;
                BarColorSeries[1] = Color.Green;
                BarColorSeries[2] = Color.Purple;
                
                Print("2 bars ago color = " + BarColorSeries[2].ToString());
                Print("4 bars ago color = " + BarColorSeries[4].ToString());
            }

            And it correctly showed at the beginning of the output that since the bars were not assigned a color, they returned Color.Empty. As the script progressed, all of the bars ended up having a color, which was properly retrieved.
            Code:
            2 bars ago color = Color [Purple]
            4 bars ago color = Color [Empty]
            2 bars ago color = Color [Purple]
            4 bars ago color = Color [Empty]
            2 bars ago color = Color [Purple]
            4 bars ago color = Color [Purple]
            2 bars ago color = Color [Purple]
            4 bars ago color = Color [Purple]
            2 bars ago color = Color [Purple]
            4 bars ago color = Color [Purple]
            ...
            AustinNinjaTrader Customer Service

            Comment


              #7
              Using BarColorSeries[n].ToString() as you did returns a color. I don't understand why using BarColorSeries[n].Name as I did fails. Your documentation contains a link to http://msdn.microsoft.com/en-us/libr...8vs.71%29.aspx for the definition of a Color structure, and that documentation indicates that a Color structure contains the public property Name that contains the color name as a string. I remain surprised that my reference to .Name didn't work; it seemed pretty darned reasonable.

              Beyond that, I take it an instance of BarColorSeries is local to each indicator? I'd like to determine how a bar gets colored by another indicator, a proprietary third-party indicator that I can't get inside of. Within an indicator I want to write, I was hoping to be able to figure out how that proprietary indicator colored the bars.

              Comment


                #8
                MikeInMA, I will have someone respond to your question tomorrow.
                AustinNinjaTrader Customer Service

                Comment


                  #9
                  MikeInMa,

                  It works with .ToString() or .Name for displaying the name of the color. Please note that the .Name property returns RGB values if it does not know the name. Meaning, if you have not set a color the color return is Color [Empty] which will result in .Name returning a 0. Otherwise if it were purple it would return "Purple".

                  BarColorSeries[0] = Color.Purple;
                  Print(".ToString: " + BarColorSeries[0].ToString() + " .Name: " + BarColorSeries[0].Name);

                  Output would be:
                  .ToString: Color [Purple] .Name: Purple
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    That all makes sense because I was seeing 0's returned by .Name because that particular indicator had not set the bar color.

                    But how about the other case: Is there any way an indicator can determine if bar color was changed by a different indicator? It sure seems like there should be a global property somewhere associated with each bar that contains each bar's color....

                    Comment


                      #11
                      MikeInMa,

                      The best way to determine this would probably be to expose a series in the indicator doing the change and then checking against that value so you know what happened from that other indicator.
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        Good idea if I had control of both indicators, but in this case color is being set by a proprietary 3rd-party indicator. That's why I was hoping there would be some crumbs left somewhere....

                        Comment


                          #13
                          Unfortunately not. It would not be possible because there is no way to tell indicator A to run before indicator B to have the colorings of A available for access to B like that. The only way to proceed in this situation would be to either program your indicator to mimic the logic used by the 3rd party indicator uses for coloring or ask the 3rd party to expose those color series information so you can program against them.
                          Josh P.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by jaybedreamin, Today, 05:56 PM
                          0 responses
                          3 views
                          0 likes
                          Last Post jaybedreamin  
                          Started by DJ888, 04-16-2024, 06:09 PM
                          6 responses
                          18 views
                          0 likes
                          Last Post DJ888
                          by DJ888
                           
                          Started by Jon17, Today, 04:33 PM
                          0 responses
                          1 view
                          0 likes
                          Last Post Jon17
                          by Jon17
                           
                          Started by Javierw.ok, Today, 04:12 PM
                          0 responses
                          6 views
                          0 likes
                          Last Post Javierw.ok  
                          Started by timmbbo, Today, 08:59 AM
                          2 responses
                          10 views
                          0 likes
                          Last Post bltdavid  
                          Working...
                          X