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

Coloring Horizontally

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

    Coloring Horizontally

    I know there is an easy way to color vertically through the use of the command BackColor. How can I get the same results but for a horizontal coloring?

    I tried coloring horizontally by drawing a bunch of big width lines but that didn't work out too well because when the y-axis resized my lines didn't readjust widths.

    Basically what I am trying to do is color those zones in my attachment. The zones are determined every day at open and maintain steady for the rest of the day. I am looking to fill it in with some form of semi transparent color to make viewing the zones easy on the eyes.

    Any ideas? Much thanks.
    Attached Files
    Josh P.NinjaTrader Customer Service

    #2
    There is no methods available to do what you want.

    - You could try using DrawLine() or DrawRectangle to fill in the space?
    RayNinjaTrader Customer Service

    Comment


      #3
      I have tried the DrawLine so far, but my code is very inefficient. It is basically drawing a new line for every bar to create the illusion of one continuous coloring. I think its because I am doing it in the OnBarUpdate() section. How do I get it to only draw once per day and just constantly updating the ending point of the line? I also can't seem to get it to use a bars ago parameter of more than 1 :/

      The problem with DrawLine is that I can only determine a width, but the width doesn't correspond with the y-axis (see pics). I can try DrawRectangle so I can specify the y coordinates, but I'm going to need to first figure out how to only draw one object per day because it is exceptionally laggy when I have it draw tens of thousands of rectangles.

      Code:
       protected override void OnBarUpdate()
              {
                  if ( CurrentBar < 1)    return;
                  
                  longtop = CurrentDayOHL().CurrentOpen[0]+spread+buyzone;
                  longbot = CurrentDayOHL().CurrentOpen[0]+spread;
                  shorttop = CurrentDayOHL().CurrentOpen[0]-spread;
                  shortbot = CurrentDayOHL().CurrentOpen[0]-spread-buyzone;
                  
                  LongTop.Set(longtop);
                  LongBottom.Set(longbot);
                  ShortTop.Set(shorttop);
                  ShortBottom.Set(shortbot);
                  
                  linecounter++;
                  DrawLine(Convert.ToString(linecounter), 1, (longtop+longbot)/2, 0, (longtop+longbot)/2, Color.FromArgb(50, longzone.R, longzone.G, longzone.B),DashStyle.Solid, 10);
              }
      Attached Files
      Last edited by NinjaTrader_JoshP; 07-10-2007, 05:07 PM.
      Josh P.NinjaTrader Customer Service

      Comment


        #4
        This is what it looks like when I use DrawRectangle. It fixes my problem with the y-axis width, but it is still drawing a million objects and takes considerable time to load.

        Code:
        protected override void OnBarUpdate()
                {
                    if ( CurrentBar < 1)    return;
                    
                    longtop = CurrentDayOHL().CurrentOpen[0]+spread+buyzone;
                    longbot = CurrentDayOHL().CurrentOpen[0]+spread;
                    shorttop = CurrentDayOHL().CurrentOpen[0]-spread;
                    shortbot = CurrentDayOHL().CurrentOpen[0]-spread-buyzone;
                    
                    LongTop.Set(longtop);
                    LongBottom.Set(longbot);
                    ShortTop.Set(shorttop);
                    ShortBottom.Set(shortbot);
                    
                    rectcounter++;
                    rectcounter2--;
                    DrawRectangle(Convert.ToString(rectcounter), 1, longtop, 0, longbot, Color.Empty, Color.Blue, 3);
                    DrawRectangle(Convert.ToString(rectcounter2), 1, shorttop, 0, shortbot, Color.Empty, Color.Red, 3);
                }
        Attached Files
        Last edited by NinjaTrader_JoshP; 07-10-2007, 05:47 PM.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          How about limiting the number of rectangles drawn or, just draw one for the current day?
          RayNinjaTrader Customer Service

          Comment


            #6
            The thing is I would like to be able to scroll back and see all the historical zones. If its the only way I think I can settle for the draw one for the current day, but how can I achieve this if I can't seem to reference back to the first bar of the day in order to draw the single rectangle?
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Try something like:

              DrawRectangle("myRectange", Bars.BarsSinceSession, yValue1, 0, yValue2, Color.Blue)
              RayNinjaTrader Customer Service

              Comment


                #8
                Hmm in real time my transparency seems to not work because it seems to be filling in the same rectangle several times. Can I limit this to update only once per bar as opposed to on every incoming tick?
                Attached Files
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  - Make sure your draw object tag is NOT unique, you want to make sure the same draw object is used and not a new one
                  - You could add something like if (FirstTickOfBar) to only call the method once per bar

                  We are going to add some DrawRegion() methods to handle what you are trying to work around. This will be available in a few months.
                  RayNinjaTrader Customer Service

                  Comment


                    #10
                    A problem with the Bars.BarsSinceSession is that if my window is currently viewing a section that does not contain either the start of the session or the current last bar of the session it won't paint the rectangle. It wants to have either the start or the end before it will paint. It would appear this behavior only happens after I scroll through the horizontal bar back and forth first.
                    Last edited by NinjaTrader_JoshP; 07-11-2007, 11:45 PM.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Good point. We have changed that behaviour for 6.5 where objects with anchor points outside of the visible range are plotted.

                      You could try stacking plots on top plots and thickening up the line widths as a workaround?
                      RayNinjaTrader Customer Service

                      Comment


                        #12
                        I would do it with plots, but that would make my Data Box a mess. Is there a way to hide the certain plots from the Data Box and not others?

                        Currently the way the DrawRectangle is working as long as the time frame is moving forward it will show the rectangle so I think I can leave it at that for now and just wait for 6.5. Thanks for your help Ray. It is much more efficient now with one rectangle per zone per day.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          You can only hide all plots from the databox, not individual ones.

                          RayNinjaTrader Customer Service

                          Comment


                            #14
                            With help from PrTester I was able to get this to finally paint the way I wanted it to. For anyone interested in the code to achieve a nice horizontal color fill check out my TRO_Buy_Zone v1.01 indicator.
                            Josh P.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Kaledus, Today, 01:29 PM
                            0 responses
                            3 views
                            0 likes
                            Last Post Kaledus
                            by Kaledus
                             
                            Started by PaulMohn, Today, 12:36 PM
                            1 response
                            16 views
                            0 likes
                            Last Post NinjaTrader_Gaby  
                            Started by yertle, Yesterday, 08:38 AM
                            8 responses
                            37 views
                            0 likes
                            Last Post ryjoga
                            by ryjoga
                             
                            Started by rdtdale, Today, 01:02 PM
                            1 response
                            6 views
                            0 likes
                            Last Post NinjaTrader_LuisH  
                            Started by alifarahani, Today, 09:40 AM
                            3 responses
                            19 views
                            0 likes
                            Last Post NinjaTrader_Jesse  
                            Working...
                            X