Exemplo n.º 1
0
        protected override void OnBarUpdate()
        {
            if (CurrentBar < Math.Max(Length, 5))
            {
                return;
            }

            _vOpen.Set(VChart(Length, Open));
            _vHigh.Set(VChart(Length, High));
            _vLow.Set(VChart(Length, Low));
            VClose.Set(VChart(Length, Close));

            //Text Section

            if (_textWarnings)
            {
                if (VClose[0] < -8)
                {
                    DrawTextFixed("Oversold2", " Significantly Oversold!", TextPosition.BottomLeft, Color.Black,
                                  new Font("Arial", 10), Color.Red, Color.Red, 7);
                }
                else
                {
                    RemoveDrawObject("Oversold2");
                }

                if (VClose[0] > 8)
                {
                    DrawTextFixed("Overbought2", " Significantly Overbought!", TextPosition.BottomLeft, Color.Black,
                                  new Font("Arial", 10), Color.Red, Color.Red, 7);
                }
                else
                {
                    RemoveDrawObject("Overbought2");
                }

                if (VClose[0] < -4 && VClose[0] > -8)
                {
                    DrawTextFixed("Oversold1", " Moderately Oversold", TextPosition.BottomLeft, Color.Black,
                                  new Font("Arial", 10), Color.Gold, Color.Gold, 7);
                }
                else
                {
                    RemoveDrawObject("Oversold1");
                }

                if (VClose[0] > 4 && VClose[0] < 8)
                {
                    DrawTextFixed("Overbought1", " Moderately Overbought", TextPosition.BottomLeft, Color.Black,
                                  new Font("Arial", 10), Color.Gold, Color.Gold, 7);
                }
                else
                {
                    RemoveDrawObject("Overbought1");
                }

                if (VClose[0] > -4 && VClose[0] < 4)
                {
                    DrawTextFixed("FairValue", " Fair Value", TextPosition.BottomLeft, Color.Black,
                                  new Font("Arial", 10), Color.Green, Color.Green, 7);
                }
                else
                {
                    RemoveDrawObject("FairValue");
                }
            }

            if (_soundWarnings)
            {
                if (VClose[0] < -8.00)
                {
                    Alert("AlertOS", Priority.High, "Significantly Oversold", "vc.wav", _alertoff, Color.Black, Color.Red);
                }

                if (VClose[0] > 8.00)
                {
                    Alert("AlertOB", Priority.High, "Significantly Overbought", "vc.wav", _alertoff, Color.Black,
                          Color.Red);
                }
            }
            if (!_dotdraw)
            {
                return;
            }

            if (_vLow[0] < -8.00)
            {
                DrawDiamond(CurrentBar + "dot", false, 0, Low[0] - _mltpl * TickSize, _colorDotOversold);
            }

            if (_vHigh[0] > 8.00)
            {
                DrawDiamond(CurrentBar + "dot", false, 0, High[0] + _mltpl * TickSize, _colorDotOverbought);
            }
        }
Exemplo n.º 2
0
        public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
        {
            int        barPaintWidth = ChartControl.ChartStyle.GetBarPaintWidth(ChartControl.BarWidth);
            SolidBrush brushUp       = new SolidBrush(_upColor);
            SolidBrush brushDown     = new SolidBrush(_downColor);
            int        penwidth      = Math.Max(1, ChartControl.BarWidth - 2);
            int        offset        = Math.Max(1, (barPaintWidth / 2 - 2));
            Pen        myPen         = new Pen(_outlineColor);

            if (_mainChartSettings)
            {
                switch (ChartControl.ChartStyle.ChartStyleType.ToString())
                {
                case "OHLC":
                    _vCt = ValueChartStyle.OHLC;
                    break;

                case "HiLoBars":
                    _vCt = ValueChartStyle.HiLoBars;
                    break;

                case "CandleStick":
                    _vCt = ValueChartStyle.CandleStick;
                    break;

                case "LineOnClose":
                    _vCt = ValueChartStyle.LineOnClose;
                    break;

                default:
                    _vCt = ValueChartStyle.OHLC;
                    break;
                }
                _upColor      = ChartControl.ChartStyle.UpColor;
                _downColor    = ChartControl.ChartStyle.DownColor;
                _outlineColor = ChartControl.ChartStyle.Pen.Color;
                _outlineWidth = ChartControl.ChartStyle.Pen.Width;
            }

            int m8 = ChartControl.GetYByValue(this, -8);
            int m4 = ChartControl.GetYByValue(this, -4);
            int p8 = ChartControl.GetYByValue(this, 8);
            int p4 = ChartControl.GetYByValue(this, 4);

            if (_changeBackground)
            {
                graphics.FillRectangle(new SolidBrush(_extremeOver), 0, bounds.Y, ChartControl.Right,
                                       (int)((max - 8.0) / ChartControl.MaxMinusMin(max, min) * bounds.Height));
                graphics.FillRectangle(new SolidBrush(_moderateOver), 0, bounds.Y +
                                       (int)
                                       ((max - 8.0) / ChartControl.MaxMinusMin(max, min) *
                                        bounds.Height), ChartControl.Right,
                                       (int)((4.0) / ChartControl.MaxMinusMin(max, min) * bounds.Height + 1));

                graphics.FillRectangle(new SolidBrush(_moderateOver), 0, bounds.Y +
                                       (int)
                                       ((max + 4.0) / ChartControl.MaxMinusMin(max, min) *
                                        bounds.Height), ChartControl.Right,
                                       (int)((4.0) / ChartControl.MaxMinusMin(max, min) * bounds.Height + 1));
                graphics.FillRectangle(new SolidBrush(_extremeOver), 0, bounds.Y +
                                       (int)
                                       ((max + 8.0) / ChartControl.MaxMinusMin(max, min) *
                                        bounds.Height), ChartControl.Right,
                                       bounds.Height -
                                       (int)((max + 8) / ChartControl.MaxMinusMin(max, min) * bounds.Height));
            }

            graphics.DrawLine(new Pen(Color.Red), 0, m8, ChartControl.Right, m8);
            graphics.DrawLine(new Pen(Color.Green), 0, m4, ChartControl.Right, m4);
            graphics.DrawLine(new Pen(Color.Green), 0, p4, ChartControl.Right, p4);
            graphics.DrawLine(new Pen(Color.Red), 0, p8, ChartControl.Right, p8);

            for (int idx = LastBarIndexPainted; idx >= FirstBarIndexPainted; idx--)
            {
                if (idx - Displacement < 0 || idx - Displacement >= Bars.Count || (!ChartControl.ShowBarsRequired && idx - Displacement < BarsRequired))
                {
                    continue;
                }

                double valH = _vHigh.Get(idx);
                double valL = _vLow.Get(idx);
                double valC = VClose.Get(idx);
                double valO = _vOpen.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);

                switch (_vCt)
                {
                case ValueChartStyle.OHLC:
                    myPen.Color = (y4 > y1) ? _downColor : _upColor;
                    myPen.Width = penwidth;
                    graphics.DrawLine(myPen, x, y2 - penwidth / 2, x, y3 + penwidth / 2);
                    graphics.DrawLine(myPen, x - offset, y1, x, y1);
                    graphics.DrawLine(myPen, x, y4, x + offset, y4);
                    break;

                case ValueChartStyle.CandleStick:
                    if (y4 > y1)
                    {
                        graphics.FillRectangle(brushDown, x - barPaintWidth / 2 + 1, y1, barPaintWidth - 1, y4 - y1);
                        graphics.DrawRectangle(new Pen(_outlineColor, _outlineWidth),
                                               (x - barPaintWidth / 2) + (_outlineWidth / 2), y1,
                                               barPaintWidth - _outlineWidth, y4 - y1);
                    }
                    if (y4 < y1)
                    {
                        graphics.FillRectangle(brushUp, x - barPaintWidth / 2 + 1, y4, barPaintWidth - 1, y1 - y4);
                        graphics.DrawRectangle(new Pen(_outlineColor, _outlineWidth),
                                               (x - barPaintWidth / 2) + (_outlineWidth / 2), y4,
                                               barPaintWidth - _outlineWidth, y1 - y4);
                    }
                    graphics.DrawLine(new Pen(_outlineColor, _outlineWidth), x, y2, x, Math.Min(y1, y4));
                    graphics.DrawLine(new Pen(_outlineColor, _outlineWidth), x, y3, x, Math.Max(y1, y4));
                    if (y1 == y4)
                    {
                        graphics.DrawLine(new Pen(_outlineColor, _outlineWidth), x - barPaintWidth / 2 + 1, y1,
                                          x - barPaintWidth / 2 + barPaintWidth - 2, y4);
                    }
                    break;

                case ValueChartStyle.HiLoBars:
                    myPen.Color = (y4 > y1) ? _downColor : _upColor;
                    myPen.Width = penwidth;
                    graphics.DrawLine(myPen, x, y2, x, y3);
                    if (y2 == y3)
                    {
                        graphics.DrawLine(myPen, x - penwidth / 2, y2, x - penwidth / 2 + penwidth, y3);
                    }
                    break;

                case ValueChartStyle.LineOnClose:
                    myPen.Color = _upColor;
                    myPen.Width = ChartControl.BarWidth;
                    if ((idx - 1) >= 0)
                    {
                        int           prevx            = ChartControl.GetXByBarIdx(BarsArray[0], idx - 1);
                        int           prevy            = ChartControl.GetYByValue(this, VClose.Get(idx - 1));
                        SmoothingMode oldSmoothingMode = graphics.SmoothingMode;
                        graphics.SmoothingMode = SmoothingMode.AntiAlias;
                        graphics.DrawLine(myPen, prevx, prevy, x, y4);
                        graphics.SmoothingMode = oldSmoothingMode;
                    }
                    break;

                default:
                    break;
                }
            }
        }