View Full Version : Coloring Horizontally
NinjaTrader_Josh
07-10-2007, 03:38 PM
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.
NinjaTrader_Ray
07-10-2007, 04:12 PM
There is no methods available to do what you want.
- You could try using DrawLine() or DrawRectangle to fill in the space?
NinjaTrader_Josh
07-10-2007, 05:05 PM
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.
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);
}
NinjaTrader_Josh
07-10-2007, 05:25 PM
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.
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);
}
NinjaTrader_Ray
07-10-2007, 06:09 PM
How about limiting the number of rectangles drawn or, just draw one for the current day?
NinjaTrader_Josh
07-10-2007, 09:38 PM
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?
NinjaTrader_Ray
07-11-2007, 08:14 AM
Try something like:
DrawRectangle("myRectange", Bars.BarsSinceSession, yValue1, 0, yValue2, Color.Blue)
NinjaTrader_Josh
07-11-2007, 10:28 AM
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?
NinjaTrader_Ray
07-11-2007, 10:32 AM
- 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.
NinjaTrader_Josh
07-11-2007, 11:12 PM
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.
NinjaTrader_Ray
07-12-2007, 06:59 AM
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?
NinjaTrader_Josh
07-13-2007, 01:37 AM
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.
NinjaTrader_Ray
07-13-2007, 06:57 AM
You can only hide all plots from the databox, not individual ones.
http://www.ninjatrader-support.com/HelpGuideV6/DisplayInDataBox.html
NinjaTrader_Josh
07-26-2007, 09:27 PM
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 (http://www.ninjatrader-support.com/vb/showpost.php?p=12780&postcount=8).