public override void GetMinMaxValues(ChartControl chartControl, ref double min, ref double max)
{
if (Bars==null) return;
if (useplot)
{
// #if NT7
// int lastBar = Math.Min(this.LastBarIndexPainted, Bars.Count - 1);
// int firstBar = this.FirstBarIndexPainted;
// #else
int lastBar = Math.Min(ChartControl.LastBarPainted, Bars.Count - 1);
int firstBar = Math.Max((lastBar - ChartControl.BarsPainted) + 1,0);
// #endif
min=Double.MaxValue;
max=Double.MinValue;
for(int index=firstBar;index<=lastBar;index++)
{
if ((index<=lastcalcbar) && (index >=Math.Max(1,startbar)))
{
min=Math.Min(min,Lowbanddata.Get(index));
max=Math.Max(max,Highbanddata.Get(index));
}
}
}
else
base.GetMinMaxValues(chartControl, ref min, ref max);
}
public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
{
if (Bars==null) return;
if (useplot)
{
// #if NT7
// int lastBar = Math.Min(this.LastBarIndexPainted, Bars.Count - 1);
// int firstBar = this.FirstBarIndexPainted;
// #else
int lastBar = Math.Min(ChartControl.LastBarPainted, Bars.Count - 1);
int firstBar = Math.Max((lastBar - ChartControl.BarsPainted) + 1,0);
// #endif
int barPaintWidth = ChartControl.ChartStyle.GetBarPaintWidth(ChartControl.BarWidth);
int barwidth=ChartControl.BarWidth;
#if !NT7
double scalingfactor= (double)bounds.Height/ChartControl.MaxMinusMin(max, min);
#endif
//Color ColorNeutral=Color.FromArgb(255,255-ChartControl.BackColor.R,255-ChartControl.BackColor.G,255-ChartControl.BackColor.B);
// #if NT7
// Pen outlinePen=ChartControl.ChartStyle.Pen;
// #else
Pen outlinePen=ChartControl.BarOutlinePen;
// #endif
Color ColorNeutral=outlinePen.Color;
Pen HiLoPen= (Pen)outlinePen.Clone();
if (EnhanceHL)
HiLoPen.Width *=2;
SolidBrush drawBrush=new SolidBrush(Color.Transparent);
SolidBrush neutralBrush=new SolidBrush(ColorNeutral);
int penSize;
if (ChartControl.ChartStyle.ChartStyleType==ChartStyleType.OHLC)
penSize=Math.Max(0,barwidth-2);
else if (ChartControl.ChartStyle.ChartStyleType==ChartStyleType.HiLoBars)
penSize=barwidth;
else
penSize=1;
Pen drawPen=new Pen(Color.Transparent,penSize);
int x, yHigh, yClose, yOpen, yLow;
int direction;
//zero line
// #if NT7
// int y0=ChartControl.GetYByValue(this,0.0);
// #else
int y0=(bounds.Y + bounds.Height) + Convert.ToInt32(min * scalingfactor);
// #endif
for(int index=firstBar;index<=lastBar;index++)
{
direction=0;
if ((index<=lastcalcbar) && (index >=Math.Max(1,startbar)))
{
// #if NT7
// x=ChartControl.GetXByBarIdx(BarsArray[0],index);
// yHigh = ChartControl.GetYByValue(this,Highbanddata.Get(index));
// yClose = ChartControl.GetYByValue(this,Closebanddata.Get(index));
// yOpen = ChartControl.GetYByValue(this,Openbanddata.Get(index)) ;
// yLow = ChartControl.GetYByValue(this,Lowbanddata.Get(index)) ;
// #else
x=ChartControl.GetXByBarIdx(index);
yHigh = (bounds.Y + bounds.Height) - Convert.ToInt32((Highbanddata.Get(index) - min) * scalingfactor);
yClose = (bounds.Y + bounds.Height) - Convert.ToInt32((Closebanddata.Get(index) - min) * scalingfactor);
yOpen = (bounds.Y + bounds.Height) - Convert.ToInt32((Openbanddata.Get(index) - min) * scalingfactor) ;
yLow = (bounds.Y + bounds.Height) - Convert.ToInt32((Lowbanddata.Get(index) - min) * scalingfactor) ;
// #endif
if (PtType==PaintType.StrongUpDown)
{
if ( Closebanddata.Get(index)<Lowbanddata.Get(index-1) )
direction=-1;
else if ( Closebanddata.Get(index)>Highbanddata.Get(index-1) )
direction=1;
}
else if (PtType==PaintType.UpDown)
{
if ( Closebanddata.Get(index)<Openbanddata.Get(index) )
direction=-1;
else if ( Closebanddata.Get(index)>Openbanddata.Get(index) )
direction=1;
}
if (direction==1)
{
drawPen.Color=ChartControl.UpColor;
}
else if (direction==-1)
{
drawPen.Color=ChartControl.DownColor;
}
else
{
drawPen.Color=ColorNeutral;
}
drawBrush.Color=drawPen.Color;
if ((ChartControl.ChartStyle.ChartStyleType==ChartStyleType.HiLoBars))
{
graphics.DrawLine(drawPen,x,yHigh,x,yLow);
}
else if (ChartControl.ChartStyle.ChartStyleType==ChartStyleType.CandleStick)
{
graphics.DrawLine(HiLoPen,x,yLow,x,yHigh);
if (yClose==yOpen)
graphics.DrawLine(outlinePen,x-barwidth-outlinePen.Width,yClose,x+barwidth+outlinePen.Width,yClose);
else
{
graphics.FillRectangle(drawBrush,x-barwidth-outlinePen.Width,Math.Min(yClose,yOpen)+1,2*(barwidth+outlinePen.Width)+1,Math.Abs(yClose-yOpen)-1);
if (ShowOutline)
{
// graphics.FillRectangle(neutralBrush,x-barwidth-outlinepenwidth,Math.Min(yClose,yOpen)+1,2*(barwidth+outlinepenwidth)+1,Math.Abs(yClose-yOpen)-1);
// graphics.FillRectangle(drawBrush,x-barwidth,Math.Min(yClose,yOpen)+1,2*barwidth+1,Math.Abs(yClose-yOpen)-1);
graphics.DrawRectangle(outlinePen,x-barwidth-outlinePen.Width/2,Math.Min(yClose,yOpen),2*(barwidth)+outlinePen.Width+1,Math.Abs(yClose-yOpen));
}
}
}
else
{
graphics.DrawLine(drawPen,x,yLow+penSize/2,x,yHigh-penSize/2);
graphics.DrawLine(drawPen,x,yClose,x+barwidth,yClose);
graphics.DrawLine(drawPen,x-barwidth,yOpen,x,yOpen);
}
}
}
}
else
base.Plot(graphics,bounds,min, max);
}
|