![]() |
|
|||||||
| NinjaScript File Sharing Discussion Discussion for shared NinjaScript files. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Mar 2008
Posts: 105
Thanks: 0
Thanked 0 times in 0 posts
|
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)
twisted.jpg 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 Code:
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(ChartControl.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);
}
Last edited by wayneFH; 03-14-2008 at 10:30 PM.
|
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Mar 2008
Posts: 105
Thanks: 0
Thanked 0 times in 0 posts
|
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. twisted.jpg 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 |
|
|
|
|
|
#4 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Mar 2008
Posts: 105
Thanks: 0
Thanked 0 times in 0 posts
|
I will try to get the GraphicsPath to work.
Thanks for your help. Sincerely, Wayne |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Testing OHLC, pivots and session breaks | Harry | Historical NinjaTrader 6.5 Beta Threads | 54 | 03-27-2008 08:19 AM |
| Buy on second bar as it breaks first pls help | gamblor | Strategy Development | 7 | 02-16-2008 08:38 AM |