PDA

View Full Version : How to Paint with Bar Breaks.


wayneFH
03-14-2008, 10:27 PM
Currently I have an indicator which draws horizontal zones on the hour and it paints the zones light red and light blue. But I don't like the diagonal connection of the painted area. How can I make it break and only draw horizontally? (see attached image)

2019

I'm using PlotStyle.Hash for the lines and they break on the hour bar nicely rather than ugly diagonal connections.

But overriding the plot function to paint the space between the bars leaves those with diagonal connections

Is there any way to paint horizontally up to the boundary between the break bars and then paint the next bar horizontally?

Here's the overriding plot method.

Thanks!
Wayne

public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
{
base.Plot(graphics, bounds, min, max);
if (Bars == null || ChartControl == null)
return;

SolidBrush brushblue = new SolidBrush(Color.FromArgb(60,Color.Blue));
SolidBrush brushred = new SolidBrush(Color.FromArgb(60,Color.Red));
int barWidth = ChartControl.ChartStyle.GetBarPaintWidth(ChartCont rol.BarWidth);
SmoothingMode oldSmoothingMode = graphics.SmoothingMode;
GraphicsPath path = new GraphicsPath();
GraphicsPath path2 = new GraphicsPath();

if(fill)
{
//Color Long Buy Zone
for (int seriesCount = 0; seriesCount < 2; seriesCount++)
{
int lastX = -1;
int lastY = -1;
DataSeries series = (DataSeries) Values[seriesCount];
double val = 0;
Gui.Chart.Plot plot = Plots[seriesCount];

for (int count = 0; count < ChartControl.BarsPainted; count++)
{
int idx = ChartControl.LastBarPainted - ChartControl.BarsPainted + 1 + count;
if (idx < 0 || idx >= Input.Count || (!ChartControl.ShowBarsRequired && idx < BarsRequired))
continue;

val = series.Get(idx);
if (val == 0)
continue;

int x = (int) (ChartControl.CanvasRight - ChartControl.BarMarginRight - barWidth / 2
- (ChartControl.BarsPainted - 1) * ChartControl.BarSpace + count * ChartControl.BarSpace) + 1;
int y = (int) ((bounds.Y + bounds.Height) - ((val - min ) / Gui.Chart.ChartControl.MaxMinusMin(max, min)) * bounds.Height);

if (lastX >= 0)
{
path.AddLine(lastX - plot.Pen.Width / 2, lastY, x - plot.Pen.Width / 2, y);
}

lastX = x;
lastY = y;
}
path.Reverse();
}

//Color Short Buy Zone
for (int seriesCount = 3; seriesCount < 5; seriesCount++)
{
int lastX = -1;
int lastY = -1;
DataSeries series = (DataSeries) Values[seriesCount];
double val = 0;
Gui.Chart.Plot plot = Plots[seriesCount];

for (int count = 0; count < ChartControl.BarsPainted; count++)
{
int idx = ChartControl.LastBarPainted - ChartControl.BarsPainted + 1 + count;
if (idx < 0 || idx >= Input.Count || (!ChartControl.ShowBarsRequired && idx < BarsRequired))
continue;

val = series.Get(idx);
if (val == 0)
continue;

int x = (int) (ChartControl.CanvasRight - ChartControl.BarMarginRight - barWidth / 2
- (ChartControl.BarsPainted - 1) * ChartControl.BarSpace + count * ChartControl.BarSpace) + 1;
int y = (int) ((bounds.Y + bounds.Height) - ((val - min ) / Gui.Chart.ChartControl.MaxMinusMin(max, min)) * bounds.Height);

if (lastX >= 0)
{
path2.AddLine(lastX - plot.Pen.Width / 2, lastY, x - plot.Pen.Width / 2, y);
}

lastX = x;
lastY = y;
}
path2.Reverse();

}
}
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.SmoothingMode = oldSmoothingMode;
graphics.FillPath(brushblue, path);
graphics.FillPath(brushred, path2);
}

NinjaTrader_Josh
03-14-2008, 10:50 PM
Instead of using the Plot override script you have there try using DrawRegion(). Make distinct regions and only paint where you want. See if that works out

wayneFH
03-16-2008, 01:36 PM
Thanks, Josh. But how can I get the shading to fill to the ends of the horizontal lines? Here's an image of the results of using DrawRegion().
NOTE: You will see I also tried DrawRectangle() with exactly the same results.

2029

So the DrawRegion() and DrawRectangle() function draw from the center to center of bars. But the horizontal lines draw from the boundary between bars.

How can I make the paint fit exactly with the line? Any ideas?

Sincerely,
Wayne

NinjaTrader_Josh
03-16-2008, 02:35 PM
Unfortunately this is beyond the level we can support. To do what you want you will have to do the Plot() override method. A hint would be that you need to go through the code you took from the TRO Buy Zone indicator and work out the GraphicsPath part.

wayneFH
03-17-2008, 10:26 AM
I will try to get the GraphicsPath to work.

Thanks for your help.

Sincerely,
Wayne