Exemplo n.º 1
0
        public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
        {
            if (Bars == null || ChartControl == null)
            {
                return;
            }

            int barPaintWidth = Math.Max(3, 1 + 2 * ((int)Bars.BarsData.ChartStyle.BarWidth - 1) + 2 * shadowWidth);

            for (int idx = FirstBarIndexPainted; idx <= LastBarIndexPainted; idx++)
            {
                if (idx - Displacement < 0 || idx - Displacement >= BarsArray[0].Count || (!ChartControl.ShowBarsRequired && idx - Displacement < BarsRequired))
                {
                    continue;
                }
                double valH = HAHigh.Get(idx);
                double valL = HALow.Get(idx);
                double valC = HAClose.Get(idx);
                double valO = HAOpen.Get(idx);
                int    x    = ChartControl.GetXByBarIdx(BarsArray[0], idx);
                int    y1   = ChartControl.GetYByValue(this, valO);
                int    y2   = ChartControl.GetYByValue(this, valH);
                int    y3   = ChartControl.GetYByValue(this, valL);
                int    y4   = ChartControl.GetYByValue(this, valC);

                graphics.DrawLine(shadowPen, x, y2, x, y3);

                if (y4 == y1)
                {
                    graphics.DrawLine(shadowPen, x - barPaintWidth / 2, y1, x + barPaintWidth / 2, y1);
                }
                else
                {
                    if (y4 > y1)
                    {
                        graphics.FillRectangle(brushDown, x - barPaintWidth / 2, y1, barPaintWidth, y4 - y1);
                    }
                    else
                    {
                        graphics.FillRectangle(brushUp, x - barPaintWidth / 2, y4, barPaintWidth, y1 - y4);
                    }
                    graphics.DrawRectangle(shadowPen, (x - barPaintWidth / 2) + (shadowPen.Width / 2), Math.Min(y4, y1), barPaintWidth - shadowPen.Width, Math.Abs(y4 - y1));
                }
            }
        }
Exemplo n.º 2
0
        protected override void OnTermination()
        {
            if (HAClose != null)
            {
                HAClose.Dispose();
            }

            if (HAOpen != null)
            {
                HAOpen.Dispose();
            }

            if (HAHigh != null)
            {
                HAHigh.Dispose();
            }

            if (HALow != null)
            {
                HALow.Dispose();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (Displacement + (CalculateOnBarClose ? 1 : 0) > 0 && CurrentBar > 0 && BarColorSeries[1] != Color.Transparent)
            {
                InitColorSeries();
            }

            BarColorSeries.Set(Math.Max(0, CurrentBar + Math.Max(0, Displacement) + (CalculateOnBarClose ? 1 : 0)), Color.Transparent);
            CandleOutlineColorSeries.Set(Math.Max(0, CurrentBar + Math.Max(0, Displacement) + (CalculateOnBarClose ? 1 : 0)), Color.Transparent);

            if (CurrentBar == 0)
            {
                HAOpen.Set(Open[0]);
                HAHigh.Set(High[0]);
                HALow.Set(Low[0]);
                HAClose.Set(Close[0]);
                return;
            }

            HAClose.Set((Open[0] + High[0] + Low[0] + Close[0]) * 0.25); // Calculate the close
            HAOpen.Set((HAOpen[1] + HAClose[1]) * 0.5);                  // Calculate the open
            HAHigh.Set(Math.Max(High[0], HAOpen[0]));                    // Calculate the high
            HALow.Set(Math.Min(Low[0], HAOpen[0]));                      // Calculate the low
        }
Exemplo n.º 4
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (!initialized)
            {
                if (ChartControl != null && saveDownColor == Color.Empty && ChartControl.ChartStyle.DownColor != Color.Transparent)
                {
                    saveDownColor = ChartControl.ChartStyle.DownColor;
                    saveUpColor   = ChartControl.ChartStyle.UpColor;
//					savePen			= ChartControl.ChartStyle.Pen;

                    // Use the defined chart colors
                    barColorDown = ChartControl.ChartStyle.DownColor;
                    barColorUp   = ChartControl.ChartStyle.UpColor;

                    // make normal bars invisible
                    ChartControl.ChartStyle.DownColor = Color.Transparent;
                    ChartControl.ChartStyle.UpColor   = Color.Transparent;
                    ChartControl.ChartStyle.Pen.Color = Color.Transparent;
                    //ChartControl.ChartStyle.Pen			= new Pen(Color.Transparent);
                }
                initialized = true;
            }

            if (CurrentBar == 0)
            {
                HAOpen.Set(0);
                HAHigh.Set(0);
                HALow.Set(0);
                HAClose.Set(0);
                return;
            }

            // Draw HeikenAshi bars as specified by user

            int lastBar  = Math.Min(ChartControl.LastBarPainted, Bars.Count - 1);
            int firstBar = (lastBar - ChartControl.BarsPainted) + 1;

            switch (PaintStyle)
            {
            case PaintingStyle.PaintVisibleOnly:
                if (CurrentBar <= firstBar + 2)
                {
                    return;
                }
                if (CurrentBar >= lastBar + 1)
                {
                    return;
                }
                break;

            case PaintingStyle.PaintToLast:
                if (CurrentBar <= firstBar + 2)
                {
                    return;
                }
                break;

            case PaintingStyle.PaintAll:
//
//					break;
//
            default:

                break;
            }

            HAClose.Set((HMA(Open, smoothingPeriod)[0] + HMA(High, smoothingPeriod)[0] + HMA(Low, smoothingPeriod)[0] + HMA(Close, smoothingPeriod)[0]) / 4); // Calculate the close
            HAOpen.Set((HMA(HAOpen, smoothingPeriod)[1] + HMA(HAClose, smoothingPeriod)[1]) / 2);                                                             // Calculate the open
            HAHigh.Set(Math.Max(HMA(High, smoothingPeriod)[0], HMA(HAOpen, smoothingPeriod)[0]));                                                             // Calculate the high
            HALow.Set(Math.Min(HMA(Low, smoothingPeriod)[0], HMA(HAOpen, smoothingPeriod)[0]));                                                               // Calculate the low

            Color barColor    = (HAClose[0] > HAOpen[0] ? BarColorUp : BarColorDown);
            Color ShadowColor = (Close[0] > Open[0] ? BarColorUp : BarColorDown);

            int BodyWidth = Math.Max(ChartControl.BarWidth + 2, ChartControl.BarSpace - 3);

            DrawLine(CurrentBar.ToString(), false, 0, HAHigh[0], 0, HALow[0], ShadowColor, DashStyle.Solid, ShadowWidth);
            DrawLine(CurrentBar.ToString() + "OC", false, 0, HAOpen[0], 0, HAClose[0], barColor, DashStyle.Solid, BodyWidth);
        }
Exemplo n.º 5
0
        protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
        {
            base.OnRender(chartControl, chartScale);

            BodyWidth = (int)ChartControl.BarWidth + Math.Min(ShadowWidth * 2, 4);
            if (ChartBars != null)
            {
                // loop through all of the viewable range of the chart
                for (int barIndex = ChartBars.FromIndex; barIndex <= ChartBars.ToIndex; barIndex++)
                {
                    if (ShadowColor == Brushes.Transparent)
                    {
                        if (Close.GetValueAt(barIndex) > Open.GetValueAt(barIndex))
                        {
                            DrawLineNT("BarBrushUp",
                                       barIndex,
                                       HAHigh.GetValueAt(barIndex),
                                       barIndex,
                                       Math.Max(HAClose.GetValueAt(barIndex), HAOpen.GetValueAt(barIndex)),
                                       ShadowWidth,
                                       chartScale);

                            DrawLineNT("BarBrushUp",
                                       barIndex,
                                       HALow.GetValueAt(barIndex),
                                       barIndex,
                                       Math.Min(HAClose.GetValueAt(barIndex), HAOpen.GetValueAt(barIndex)),
                                       ShadowWidth,
                                       chartScale);
                        }
                        else
                        {
                            DrawLineNT("BarBrushDown",
                                       barIndex,
                                       HAHigh.GetValueAt(barIndex),
                                       barIndex,
                                       Math.Max(HAClose.GetValueAt(barIndex), HAOpen.GetValueAt(barIndex)),
                                       ShadowWidth,
                                       chartScale);

                            DrawLineNT("BarBrushDown",
                                       barIndex,
                                       HALow.GetValueAt(barIndex),
                                       barIndex,
                                       Math.Min(HAClose.GetValueAt(barIndex), HAOpen.GetValueAt(barIndex)),
                                       ShadowWidth,
                                       chartScale);
                        }
                    }
                    else
                    {
                        DrawLineNT("ShadowBrush",
                                   barIndex,
                                   HAHigh.GetValueAt(barIndex),
                                   barIndex,
                                   Math.Max(HAClose.GetValueAt(barIndex), HAOpen.GetValueAt(ShadowWidth)),
                                   ShadowWidth,
                                   chartScale);

                        DrawLineNT("ShadowBrush",
                                   barIndex,
                                   HALow.GetValueAt(barIndex),
                                   barIndex,
                                   Math.Min(HAClose.GetValueAt(barIndex), HAOpen.GetValueAt(ShadowWidth)),
                                   ShadowWidth,
                                   chartScale);
                    }

                    if (HAClose.GetValueAt(barIndex) > HAOpen.GetValueAt(barIndex))
                    {
                        DrawLineNT("BarBrushUp",
                                   barIndex,
                                   HAOpen.GetValueAt(barIndex),
                                   barIndex,
                                   HAClose.GetValueAt(barIndex),
                                   BodyWidth,
                                   chartScale);
                    }
                    else
                    {
                        DrawLineNT("BarBrushDown",
                                   barIndex,
                                   HAOpen.GetValueAt(barIndex),
                                   barIndex,
                                   HAClose.GetValueAt(barIndex),
                                   BodyWidth,
                                   chartScale);
                    }
                }
                // Draw price line if wanted

                if (ShowPriceLine)
                {
                    DrawLineNT("PriceLineBrush",
                               Math.Max(PriceLineLength, CurrentBar - 15),
                               Close.GetValueAt(CurrentBar),
                               CurrentBar,
                               Close.GetValueAt(CurrentBar),
                               PriceLineWidth,
                               PriceLineStyle,
                               chartScale);

                    DrawStringNT("  -- " + Close.GetValueAt(CurrentBar).ToString() + " = Last Price",
                                 Font,
                                 "PriceTextBrush",
                                 CurrentBar,
                                 Close.GetValueAt(CurrentBar),
                                 "PriceAreaBrush",
                                 chartScale);
                }
            }
        }