示例#1
0
		/// <summary>
		/// </summary>
		/// <param name="chartControl"></param>
		/// <param name="graphics"></param>
		/// <param name="bars"></param>
		/// <param name="panelIdx"></param>
		/// <param name="fromIdx"></param>
		/// <param name="toIdx"></param>
		/// <param name="bounds"></param>
		/// <param name="max"></param>
		/// <param name="min"></param>
		public override void PaintBars(ChartControl chartControl, Graphics graphics, Data.Bars bars, int panelIdx, int fromIdx, int toIdx, Rectangle bounds, double max, double min) 
		{
			int		boxSize	 = bars.Period.Value;
			double	tickSize = bars.Instrument.MasterInstrument.TickSize;
			double	offset	 = boxSize * tickSize;

			int		barWidthValue = bars.BarsData.ChartStyle.BarWidthUI;
			int		barWidth	  = GetBarPaintWidth(barWidthValue);
			int     lastBarIdx    = bars.Count - 1;

			for (int idx = fromIdx; idx <= toIdx; idx++) 
			{
				double open      = bars.GetOpen(idx);
				double close     = bars.GetClose(idx);
			    bool   upBar     = open < close;

				int x      = chartControl.GetXByBarIdx(bars, idx);
				int openY  = chartControl.GetYByValue(bars, open);
				int closeY = chartControl.GetYByValue(bars, close);
				
				Pen pen = upBar ? Pen : Pen2;
				Color orgPenColor = pen.Color;
				Color barColor = chartControl.GetBarOverrideColor(bars, idx);
				Color olColor  = chartControl.GetCandleOutlineOverrideColor(bars, idx);
				if (olColor != Color.Empty) 
					pen.Color = olColor;
				else if (barColor != Color.Empty) 
					pen.Color = barColor;
				
				if (openY == closeY)
					graphics.DrawLine(pen, x - barWidth / 2, closeY, x + barWidth / 2, closeY);
				else 
				{
					brush.Color = barColor != Color.Empty ? barColor : upBar ? UpColor : DownColor;

					int minY = Math.Min(openY, closeY);
					int maxY = Math.Max(openY, closeY);
					
					graphics.FillRectangle(brush, x - (barWidth / 2) + 1, minY + 1, barWidth - 1, maxY - minY - 1);
					graphics.DrawRectangle(pen,   x - (barWidth / 2) + (pen.Width / 2), minY, barWidth - pen.Width, maxY - minY);
				}
				pen.Color = orgPenColor;
			}
		}
示例#2
0
		/// <summary>
		/// </summary>
		/// <param name="chartControl"></param>
		/// <param name="graphics"></param>
		/// <param name="bars"></param>
		/// <param name="panelIdx"></param>
		/// <param name="fromIdx"></param>
		/// <param name="toIdx"></param>
		/// <param name="bounds"></param>
		/// <param name="max"></param>
		/// <param name="min"></param>
		public override void PaintBars(ChartControl chartControl, Graphics graphics, Data.Bars bars, int panelIdx, int fromIdx, int toIdx, Rectangle bounds, double max, double min)
		{
			if (downBrush.Color != DownColor)
				downBrush.Color = DownColor;

			if (upBrush.Color != UpColor)
				upBrush.Color = UpColor;

			Color		barColor;
			int			barWidthValue = bars.BarsData.ChartStyle.BarWidthUI;
			int			barWidth;
			SolidBrush	brush		= upBrush;
			int			close;
			double		closeValue;
			int			high;
			int			low;
			Color		oldPenColor	= Pen.Color;
			Color		pen2Color	= Pen2.Color;
			int			open;
			double		openValue;
			int			x;

			for (int idx = fromIdx; idx <= toIdx; idx++)
			{
				barColor	= chartControl.GetBarOverrideColor(bars, idx);
				barWidth	= GetBarPaintWidth(barWidthValue);
				closeValue	= bars.GetClose(idx);
				close		= chartControl.GetYByValue(bars, closeValue);
				high		= chartControl.GetYByValue(bars, bars.GetHigh(idx));
				low			= chartControl.GetYByValue(bars, bars.GetLow(idx));
				openValue	= bars.GetOpen(idx);
				open		= chartControl.GetYByValue(bars, openValue);
				x			= chartControl.GetXByBarIdx(bars, idx);

				Color	candleOutlineColorScript		= chartControl.GetCandleOutlineOverrideColor(bars, idx);
				bool	isCandleOutlineColorScriptSet	= (chartControl.GetCandleOutlineOverrideColor(bars, idx) != Color.Empty);

				Pen.Color = oldPenColor;
				if (barColor != Color.Empty)
					Pen.Color = (candleOutlineColorScript != Color.Empty ? candleOutlineColorScript : barColor);
				else if (candleOutlineColorScript != Color.Empty)
					Pen.Color = candleOutlineColorScript;

				if (open == close)
					graphics.DrawLine(Pen, x - barWidth / 2, close, x + barWidth / 2, close);
				else
				{
					brush = closeValue >= openValue ? upBrush : downBrush;
					Color oldColor = brush.Color;
					if (barColor != Color.Empty)
						brush.Color = barColor;

					graphics.FillRectangle(brush, x - barWidth / 2 + 1, Math.Min(close, open) + 1,
						barWidth - 1, Math.Max(open, close) - Math.Min(close, open) - 1);

					if (barColor != Color.Empty)
						brush.Color = oldColor;

					graphics.DrawRectangle(Pen, x - (barWidth / 2) + (Pen.Width / 2), Math.Min(close, open), barWidth - Pen.Width, Math.Max(open, close) - Math.Min(close, open));
				}

				Pen2.Color = isCandleOutlineColorScriptSet ? candleOutlineColorScript : pen2Color;

				if (high < Math.Min(open, close))
					graphics.DrawLine(Pen2, x, high, x, Math.Min(open, close));

				if (low > Math.Max(open, close))
					graphics.DrawLine(Pen2, x, low, x, Math.Max(open, close));
			}
			Pen.Color = oldPenColor;
			Pen2.Color = pen2Color;
		}
示例#3
0
		/// <summary>
		/// </summary>
		/// <param name="chartControl"></param>
		/// <param name="graphics"></param>
		/// <param name="bars"></param>
		/// <param name="panelIdx"></param>
		/// <param name="fromIdx"></param>
		/// <param name="toIdx"></param>
		/// <param name="bounds"></param>
		/// <param name="max"></param>
		/// <param name="min"></param>
		public override void PaintBars(ChartControl chartControl, Graphics graphics, Data.Bars bars, int panelIdx, int fromIdx, int toIdx, Rectangle bounds, double max, double min)
		{
			if (downBrush.Color != DownColor)
				downBrush.Color = DownColor;

			if (upBrush.Color != UpColor)
				upBrush.Color = UpColor;

			int			x;
			Color		barColor;
		    int			high;
		    double		highVal;
		    int			low;
		    double		lowVal;
			int			boxStartPosition	= -1;
			bool		drawLastBar			= false;
			int			chartMinX			= chartControl.CanvasRight - chartControl.BarMarginRight - GetBarPaintWidth(BarWidthUI) / 2  - ((chartControl.BarsPainted - 1) * chartControl.BarSpace);
			Color		candleOutlineColorScript;

			if (toIdx >= 0 && toIdx < bars.Count - 1)
				toIdx++;

			for (int idx = fromIdx; idx <= toIdx; idx++)
			{
				if (idx == 0)
					continue;

				barColor	= chartControl.GetBarOverrideColor(bars, idx);
				highVal		= bars.GetHigh(idx);
				high		= chartControl.GetYByValue(bars, highVal);
				lowVal		= bars.GetLow(idx);
				low			= chartControl.GetYByValue(bars, lowVal);
				x			= chartControl.GetXByBarIdx(bars, idx);
				candleOutlineColorScript = chartControl.GetCandleOutlineOverrideColor(bars, idx);

				if (idx == fromIdx)
					boxStartPosition = chartMinX;
				else
					boxStartPosition = chartControl.GetXByBarIdx(bars, idx - 1);
				
				boxStartPosition = (boxStartPosition < chartMinX ? chartMinX : boxStartPosition);
				if (x == boxStartPosition)
					continue;

				int width = Math.Max(2, Math.Abs(x - boxStartPosition));
				if (boxStartPosition + width > bounds.Width + bounds.X)
				    width = (bounds.X + bounds.Width) - boxStartPosition;

		        if (bars.GetClose(idx) >= bars.GetOpen(idx))
		        {
					Color oldBrushColor	= upBrush.Color;
					Color oldPenColor	= Pen.Color;

					if (barColor != Color.Empty)
						upBrush.Color = barColor;
					if (candleOutlineColorScript != Color.Empty)
						Pen.Color = candleOutlineColorScript;
					else if (barColor != Color.Empty)
						Pen.Color = barColor;

					width -= (int) Pen.Width;
		            graphics.FillRectangle(upBrush, boxStartPosition,	high,	width, low - high);
		            graphics.DrawRectangle(Pen,		boxStartPosition,	high,	width, low - high);

					if (barColor != Color.Empty)
						upBrush.Color = oldBrushColor;
					if (candleOutlineColorScript != Color.Empty || barColor != Color.Empty)
						Pen.Color = oldPenColor;
				}
		        else
				{
					Color oldBrushColor	= downBrush.Color;
					Color oldPenColor	= Pen2.Color;

					if (barColor != Color.Empty)
						downBrush.Color = barColor;
					if (candleOutlineColorScript != Color.Empty)
						Pen2.Color = candleOutlineColorScript;
					else if (barColor != Color.Empty)
						Pen2.Color = barColor;

					width -= (int) Pen2.Width;
					graphics.FillRectangle(downBrush,	boxStartPosition, high,	width, low - high);
		            graphics.DrawRectangle(Pen2,		boxStartPosition, high,	width, low - high);

					if (barColor != Color.Empty)
						downBrush.Color = oldBrushColor;
					if (candleOutlineColorScript != Color.Empty || barColor != Color.Empty)
						Pen2.Color = oldPenColor;
				}
				
				if (!drawLastBar)
					drawLastBar = true;
			}
		}