예제 #1
0
        /// <summary>
        /// Value Charts by David Stendhal; Converted to NinjaTrader by TradingStudies.com
        /// </summary>
        /// <returns></returns>
        public Indicator.RValueCharts RValueCharts(Data.IDataSeries input, bool changeBackground, bool dotDraw, int dotOffset, Color dotOverBought, Color dotOverSold, Color downColor, Color extremeOver, int length, bool mainChartSettings, Color moderateOver, Color outlineColor, float outlineWidth, int soundAlertInterval, bool soundWarnings, bool textWarnings, Color upColor, ValueChartStyle vct)
        {
            if (InInitialize && input == null)
            {
                throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
            }

            return(_indicator.RValueCharts(input, changeBackground, dotDraw, dotOffset, dotOverBought, dotOverSold, downColor, extremeOver, length, mainChartSettings, moderateOver, outlineColor, outlineWidth, soundAlertInterval, soundWarnings, textWarnings, upColor, vct));
        }
예제 #2
0
        /// <summary>
        /// Value Charts by David Stendhal; Converted to NinjaTrader by TradingStudies.com
        /// </summary>
        /// <returns></returns>
        public RValueCharts RValueCharts(Data.IDataSeries input, bool changeBackground, bool dotDraw, int dotOffset, Color dotOverBought, Color dotOverSold, Color downColor, Color extremeOver, int length, bool mainChartSettings, Color moderateOver, Color outlineColor, float outlineWidth, int soundAlertInterval, bool soundWarnings, bool textWarnings, Color upColor, ValueChartStyle vct)
        {
            if (cacheRValueCharts != null)
            {
                for (int idx = 0; idx < cacheRValueCharts.Length; idx++)
                {
                    if (cacheRValueCharts[idx].ChangeBackground == changeBackground && cacheRValueCharts[idx].DotDraw == dotDraw && cacheRValueCharts[idx].DotOffset == dotOffset && cacheRValueCharts[idx].DotOverBought == dotOverBought && cacheRValueCharts[idx].DotOverSold == dotOverSold && cacheRValueCharts[idx].DownColor == downColor && cacheRValueCharts[idx].ExtremeOver == extremeOver && cacheRValueCharts[idx].Length == length && cacheRValueCharts[idx].MainChartSettings == mainChartSettings && cacheRValueCharts[idx].ModerateOver == moderateOver && cacheRValueCharts[idx].OutlineColor == outlineColor && cacheRValueCharts[idx].OutlineWidth == outlineWidth && cacheRValueCharts[idx].SoundAlertInterval == soundAlertInterval && cacheRValueCharts[idx].SoundWarnings == soundWarnings && cacheRValueCharts[idx].TextWarnings == textWarnings && cacheRValueCharts[idx].UpColor == upColor && cacheRValueCharts[idx].Vct == vct && cacheRValueCharts[idx].EqualsInput(input))
                    {
                        return(cacheRValueCharts[idx]);
                    }
                }
            }

            lock (checkRValueCharts)
            {
                checkRValueCharts.ChangeBackground = changeBackground;
                changeBackground          = checkRValueCharts.ChangeBackground;
                checkRValueCharts.DotDraw = dotDraw;
                dotDraw = checkRValueCharts.DotDraw;
                checkRValueCharts.DotOffset = dotOffset;
                dotOffset = checkRValueCharts.DotOffset;
                checkRValueCharts.DotOverBought = dotOverBought;
                dotOverBought = checkRValueCharts.DotOverBought;
                checkRValueCharts.DotOverSold = dotOverSold;
                dotOverSold = checkRValueCharts.DotOverSold;
                checkRValueCharts.DownColor = downColor;
                downColor = checkRValueCharts.DownColor;
                checkRValueCharts.ExtremeOver = extremeOver;
                extremeOver = checkRValueCharts.ExtremeOver;
                checkRValueCharts.Length = length;
                length = checkRValueCharts.Length;
                checkRValueCharts.MainChartSettings = mainChartSettings;
                mainChartSettings = checkRValueCharts.MainChartSettings;
                checkRValueCharts.ModerateOver = moderateOver;
                moderateOver = checkRValueCharts.ModerateOver;
                checkRValueCharts.OutlineColor = outlineColor;
                outlineColor = checkRValueCharts.OutlineColor;
                checkRValueCharts.OutlineWidth = outlineWidth;
                outlineWidth = checkRValueCharts.OutlineWidth;
                checkRValueCharts.SoundAlertInterval = soundAlertInterval;
                soundAlertInterval = checkRValueCharts.SoundAlertInterval;
                checkRValueCharts.SoundWarnings = soundWarnings;
                soundWarnings = checkRValueCharts.SoundWarnings;
                checkRValueCharts.TextWarnings = textWarnings;
                textWarnings = checkRValueCharts.TextWarnings;
                checkRValueCharts.UpColor = upColor;
                upColor = checkRValueCharts.UpColor;
                checkRValueCharts.Vct = vct;
                vct = checkRValueCharts.Vct;

                if (cacheRValueCharts != null)
                {
                    for (int idx = 0; idx < cacheRValueCharts.Length; idx++)
                    {
                        if (cacheRValueCharts[idx].ChangeBackground == changeBackground && cacheRValueCharts[idx].DotDraw == dotDraw && cacheRValueCharts[idx].DotOffset == dotOffset && cacheRValueCharts[idx].DotOverBought == dotOverBought && cacheRValueCharts[idx].DotOverSold == dotOverSold && cacheRValueCharts[idx].DownColor == downColor && cacheRValueCharts[idx].ExtremeOver == extremeOver && cacheRValueCharts[idx].Length == length && cacheRValueCharts[idx].MainChartSettings == mainChartSettings && cacheRValueCharts[idx].ModerateOver == moderateOver && cacheRValueCharts[idx].OutlineColor == outlineColor && cacheRValueCharts[idx].OutlineWidth == outlineWidth && cacheRValueCharts[idx].SoundAlertInterval == soundAlertInterval && cacheRValueCharts[idx].SoundWarnings == soundWarnings && cacheRValueCharts[idx].TextWarnings == textWarnings && cacheRValueCharts[idx].UpColor == upColor && cacheRValueCharts[idx].Vct == vct && cacheRValueCharts[idx].EqualsInput(input))
                        {
                            return(cacheRValueCharts[idx]);
                        }
                    }
                }

                RValueCharts indicator = new RValueCharts();
                indicator.BarsRequired        = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack         = MaximumBarsLookBack;
#endif
                indicator.Input              = input;
                indicator.ChangeBackground   = changeBackground;
                indicator.DotDraw            = dotDraw;
                indicator.DotOffset          = dotOffset;
                indicator.DotOverBought      = dotOverBought;
                indicator.DotOverSold        = dotOverSold;
                indicator.DownColor          = downColor;
                indicator.ExtremeOver        = extremeOver;
                indicator.Length             = length;
                indicator.MainChartSettings  = mainChartSettings;
                indicator.ModerateOver       = moderateOver;
                indicator.OutlineColor       = outlineColor;
                indicator.OutlineWidth       = outlineWidth;
                indicator.SoundAlertInterval = soundAlertInterval;
                indicator.SoundWarnings      = soundWarnings;
                indicator.TextWarnings       = textWarnings;
                indicator.UpColor            = upColor;
                indicator.Vct = vct;
                Indicators.Add(indicator);
                indicator.SetUp();

                RValueCharts[] tmp = new RValueCharts[cacheRValueCharts == null ? 1 : cacheRValueCharts.Length + 1];
                if (cacheRValueCharts != null)
                {
                    cacheRValueCharts.CopyTo(tmp, 0);
                }
                tmp[tmp.Length - 1] = indicator;
                cacheRValueCharts   = tmp;
                return(indicator);
            }
        }
예제 #3
0
 public Indicator.RValueCharts RValueCharts(bool changeBackground, bool dotDraw, int dotOffset, Color dotOverBought, Color dotOverSold, Color downColor, Color extremeOver, int length, bool mainChartSettings, Color moderateOver, Color outlineColor, float outlineWidth, int soundAlertInterval, bool soundWarnings, bool textWarnings, Color upColor, ValueChartStyle vct)
 {
     return(_indicator.RValueCharts(Input, changeBackground, dotDraw, dotOffset, dotOverBought, dotOverSold, downColor, extremeOver, length, mainChartSettings, moderateOver, outlineColor, outlineWidth, soundAlertInterval, soundWarnings, textWarnings, upColor, vct));
 }
예제 #4
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;
                }
            }
        }