public static int getSlope(NinjaTrader.Indicator.Indicator ind, DataSeries series, int index)
        {
            if (!series.ContainsValue(3))
            {
                return(0);
            }

            return((int)(((180 / Math.PI) * (Math.Atan((series.Get(index) - ((series.Get(index + 1) + series.Get(index + 2)) / 2)) / 1.5 / ind.TickSize))) * -1));
        }
        public static int getSlope(Strategy strat, DataSeries series, int index)
        {
            if (!series.ContainsValue(3))
            {
                return(0);
            }

            return((int)(((180 / Math.PI) * (Math.Atan((series.Get(index) - ((series.Get(index + 1) + series.Get(index + 2)) / 2)) / 1.5 / strat.TickSize))) * -1));
        }
示例#3
0
        public static void DrawValueString(Indicator ind, Graphics graphics, Rectangle bounds, string plotName, int plotNum, DataSeries series, int boxNum)
        {
            int num2 = ind.CalculateOnBarClose ? (ind.ChartControl.BarsPainted - 2) : (ind.ChartControl.BarsPainted - 1);

            if (ind.Bars != null)
            {
                int index = ((ind.ChartControl.LastBarPainted - ind.ChartControl.BarsPainted) - 1) + num2;
                if (ind.ChartControl.ShowBarsRequired || ((index - ind.Displacement) >= ind.BarsRequired))
                {
                    double        num3    = series.Get(index);
                    string        s       = plotName + ": ";
                    StringBuilder builder = new StringBuilder();
                    builder.Append(Math.Round(num3, 3).ToString(CultureInfo.InvariantCulture));
                    Color color = (num3 > 0.0) ? upColor : downColor;
                    textBrush.Color = color;
                    Brush brush = textBrush;
                    if (plotNum != -1)
                    {
                        if (ind.Plots[plotNum] == null)
                        {
                            s = "Err: Plot Does not exsit!";
                        }
                        else
                        {
                            brush = (ind.Plots[plotNum].Pen.Color == Color.Transparent) ? textBrush : ind.Plots[plotNum].Pen.Brush;
                        }
                    }
                    graphics.DrawString(s, textFont, brush, (bounds.X + bounds.Width) - 37, (bounds.Y + bounds.Height) - (boxNum * 20), stringFormat);
                    graphics.DrawString(builder.ToString(), textFont, textBrush, (bounds.X + bounds.Width) - 3, (bounds.Y + bounds.Height) - (boxNum * 20), stringFormat);
                }
            }
        }
示例#4
0
        public void drawColorLine(Graphics graphics, Rectangle bounds, double min, double max, DataSeries series,
                                  Pen upPen, Pen downPen)
        {
            if (base.Bars != null)
            {
                int           barPaintWidth = ChartControl.ChartStyle.GetBarPaintWidth(ChartControl.BarWidth);
                SmoothingMode smoothingMode = graphics.SmoothingMode;
                int           x1            = -1;
                int           y1            = -1;
                double        val;
                double        old   = 0.0;
                double        older = 0.0;
                Pen           pen   = null;
                GraphicsPath  path  = null;
                for (int i = 0;
                     i <= (Math.Min(ChartControl.BarsPainted, series.Count - ChartControl.FirstBarPainted) - 1);
                     i++)
                {
                    int index = ((ChartControl.LastBarPainted - ChartControl.BarsPainted) + 1) + i;
                    if (ChartControl.ShowBarsRequired || ((index - Displacement) >= BarsRequired))
                    {
                        val = series.Get(index);
                        if (!double.IsNaN(val))
                        {
                            int x2 = (((ChartControl.CanvasRight - ChartControl.BarMarginRight) - (barPaintWidth / 2)) -
                                      ((ChartControl.BarsPainted - 1) * ChartControl.BarSpace)) + (i * ChartControl.BarSpace);
                            int y2 = (bounds.Y + bounds.Height) -
                                     ((int)(((val - min) / ChartControl.MaxMinusMin(max, min)) * bounds.Height));
                            if (x1 >= 0)
                            {
                                Pen pen2;
                                pen2 = (val > 0) ? upPen : downPen;

                                if (pen2 != pen)
                                {
                                    if (path != null)
                                    {
                                        graphics.DrawPath(pen, path);
                                    }
                                    path = new GraphicsPath();
                                    pen  = pen2;
                                }
                                path.AddLine(x1, y1, x2, y2);
                            }
                            x1    = x2;
                            y1    = y2;
                            older = old;
                            old   = val;
                        }
                        if (pen != null)
                        {
                            graphics.SmoothingMode = SmoothingMode.AntiAlias;
                            graphics.DrawPath(pen, path);
                            graphics.SmoothingMode = smoothingMode;
                        }
                    }
                }
            }
        }
示例#5
0
        public void DrawColorLine(Graphics graphics, Rectangle bounds, double min, double max, DataSeries series, Pen upPen, Pen downPen)
        {
            if (Bars == null)
            {
                return;
            }
            int           barPaintWidth = ChartControl.ChartStyle.GetBarPaintWidth(ChartControl.BarWidth);
            SmoothingMode smoothingMode = graphics.SmoothingMode;
            int           num2          = -1;
            int           num3          = -1;
            Pen           pen           = null;
            GraphicsPath  path          = null;

            for (int i = 0;
                 i <= (Math.Min(ChartControl.BarsPainted, series.Count - ChartControl.FirstBarPainted) - 1);
                 i++)
            {
                int index = ((ChartControl.LastBarPainted - ChartControl.BarsPainted) + 1) + i;
                if (ChartControl.ShowBarsRequired || ((index - Displacement) >= BarsRequired))
                {
                    double d = series.Get(index);
                    if (!double.IsNaN(d))
                    {
                        int num7 = (((ChartControl.CanvasRight - ChartControl.BarMarginRight) - (barPaintWidth / 2)) -
                                    ((ChartControl.BarsPainted - 1) * ChartControl.BarSpace)) + (i * ChartControl.BarSpace);
                        int num8 = (bounds.Y + bounds.Height) - ((int)(((d - min) / ChartControl.MaxMinusMin(max, min)) * bounds.Height));
                        if (num2 >= 0)
                        {
                            Pen pen2 = (d > 0.0) ? upPen : downPen;
                            if (pen2 != pen)
                            {
                                if (path != null)
                                {
                                    if (pen != null)
                                    {
                                        graphics.DrawPath(pen, path);
                                    }
                                }
                                path = new GraphicsPath();
                                pen  = pen2;
                            }
                            if (path != null)
                            {
                                path.AddLine(num2, num3, num7, num8);
                            }
                        }
                        num2 = num7;
                        num3 = num8;
                    }
                    if (pen != null)
                    {
                        graphics.SmoothingMode = SmoothingMode.AntiAlias;
                        graphics.DrawPath(pen, path);
                        graphics.SmoothingMode = smoothingMode;
                    }
                }
            }
        }
        public override void GetMinMaxValues(ChartControl chartControl, ref double min, ref double max)
        {
            if ((chartControl == null) || (Bars == null))
            {
                return;
            }

            int    lastBar, firstBar;
            double tmp;

            min = Double.MaxValue;
            max = Double.MinValue;

            firstBar = Math.Max(this.FirstBarIndexPainted, 1);
            if (firstBar < startbar)
            {
                firstBar = startbar;
            }

            lastBar = Math.Min(this.LastBarIndexPainted, Bars.Count - 1);
            if (lastBar > lastcalcbar)
            {
                lastBar = lastcalcbar;
            }

            for (int idx = firstBar; idx <= lastBar; idx++)
            {
                tmp = dsSShigh.Get(idx); if (max < tmp)
                {
                    max = tmp;
                }
                tmp = dsSSlow.Get(idx); if (min > tmp)
                {
                    min = tmp;
                }
            }

            if ((max - min) < .000001)
            {
                min -= .000001;
                max += .000001;
            }
        }
/// <summary>
///
/// </summary>
/// <param name="graphics"></param>
/// <param name="bounds"></param>
/// <param name="min"></param>
/// <param name="max"></param>
        public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
        {
            if (Bars == null)
            {
                return;
            }
            int lastBar  = Math.Min(LastBarIndexPainted, Bars.Count - 1);
            int firstBar = FirstBarIndexPainted;

            int barWidth = ((widthOverride > 0)?widthOverride:ChartControl.BarWidth);

            Pen outlinePen = ChartControl.ChartStyle.Pen;

            int bars = ChartControl.BarsPainted;


            int        x, yHigh, yClose, yOpen, yLow;
            SolidBrush direction;
            SolidBrush up = new SolidBrush(ChartControl.ChartStyle.UpColor);
            SolidBrush dn = new SolidBrush(ChartControl.ChartStyle.DownColor);

            for (int indx = firstBar; indx <= lastBar; ++indx)
            {
                if ((indx <= CurrentBar) && (indx >= 1))
                {
                    x      = ChartControl.GetXByBarIdx(BarsArray[0], indx);
                    yHigh  = ChartControl.GetYByValue(this, dsHigh.Get(indx));
                    yClose = ChartControl.GetYByValue(this, dsClose.Get(indx));
                    yOpen  = ChartControl.GetYByValue(this, dsOpen.Get(indx));
                    yLow   = ChartControl.GetYByValue(this, dsLow.Get(indx));

                    if (yClose < yOpen)
                    {
                        paintBrush.Color = ChartControl.ChartStyle.UpColor;
                    }
                    else
                    {
                        paintBrush.Color = ChartControl.ChartStyle.DownColor;
                    }

                    graphics.DrawLine(ChartControl.ChartStyle.Pen2, x, yHigh, x, yLow);
                    if (yClose == yOpen)
                    {
                        graphics.DrawLine(outlinePen, x - barWidth - outlinePen.Width, yClose, x + barWidth + outlinePen.Width, yClose);
                    }
                    else
                    {
                        graphics.FillRectangle(paintBrush, x - barWidth - outlinePen.Width, Math.Min(yClose, yOpen), 2 * (barWidth + outlinePen.Width), Math.Abs(yClose - yOpen));
                        graphics.DrawRectangle(outlinePen, x - barWidth - outlinePen.Width, Math.Min(yClose, yOpen), 2 * (barWidth + outlinePen.Width), Math.Abs(yClose - yOpen));
                    }
                }
            }
        }
        /// <summary>
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="bounds"></param>
        /// <param name="min"></param>
        /// <param name="max"></param>
        public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
        {
            if (Bars == null || ChartControl == null)
            {
                return;
            }

            int    lastBarIndex = this.LastBarIndexPainted;
            int    idx          = lastBarIndex - ((CalculateOnBarClose && lastBarIndex == Input.Count - 1) ? 1 : 0);
            double intercept    = interceptSeries.Get(idx);
            double slope        = slopeSeries.Get(idx);
            double stdDev       = stdDeviationSeries.Get(idx);

            int stdDevPixels = (int)Math.Round(((stdDev * width) / ChartControl.MaxMinusMin(max, min)) * bounds.Height, 0);

            int xPos = GetXPos(Period - 1);
            int yPos = GetYPos(intercept, bounds, min, max);

            int xPos2 = GetXPos(0);
            int yPos2 = GetYPos(intercept + slope * (Period - 1), bounds, min, max);

            SmoothingMode oldSmoothingMode = graphics.SmoothingMode;

            graphics.SmoothingMode = SmoothingMode.AntiAlias;

            // Middle
            graphics.DrawLine(Plots[0].Pen,
                              xPos,
                              yPos,
                              xPos2,
                              yPos2);

            // Upper
            graphics.DrawLine(Plots[1].Pen,
                              xPos,
                              yPos - stdDevPixels,
                              xPos2,
                              yPos2 - stdDevPixels);

            // Lower
            graphics.DrawLine(Plots[2].Pen,
                              xPos,
                              yPos + stdDevPixels,
                              xPos2,
                              yPos2 + stdDevPixels);

            graphics.SmoothingMode = oldSmoothingMode;
        }
示例#9
0
        public int FractalHighBar(int barsAgo, int instance, int lookBackPeriod)
        {
            if (instance < 1)
            {
                throw new Exception(GetType().Name + ".FractalHighBar: instance must be greater/equal 1 but was " + instance);
            }
            else if (barsAgo < 0)
            {
                throw new Exception(GetType().Name + ".FractalHighBar: barsAgo must be greater/equal 0 but was " + barsAgo);
            }
            else if (barsAgo >= Count)
            {
                throw new Exception(GetType().Name + ".FractalHighBar: barsAgo out of valid range 0 through " + (Count - 1) + ", was " + barsAgo + ".");
            }

            Update();

            for (int idx = CurrentBar - barsAgo; idx >= CurrentBar - barsAgo - lookBackPeriod; idx--)
            {
                if (idx < 0)
                {
                    return(-1);
                }
                if (idx >= _fractalHigh.Count)
                {
                    continue;
                }

                if (_fractalHigh.Get(idx).Equals(0.0))
                {
                    continue;
                }

                if (instance <= 1) // 1-based, < to be save
                {
                    return(CurrentBar - idx);
                }

                instance--;
            }


            return(-1);
        }
        public static void drawValueString(NinjaTrader.Indicator.Indicator ind, Graphics graphics, Rectangle bounds, string plotName, int plotNum, DataSeries series, int boxNum)
        {
            int index = -1;
            int bars  = ind.CalculateOnBarClose ? (ind.ChartControl.BarsPainted - 2) : (ind.ChartControl.BarsPainted - 1);

            if (ind.Bars != null)
            {
                index = ((ind.ChartControl.LastBarPainted - ind.ChartControl.BarsPainted) - 1) + bars;
                if (ind.ChartControl.ShowBarsRequired || ((index - ind.Displacement) >= ind.BarsRequired))
                {
                    double        val = series.Get(index);
                    string        s   = plotName + ": ";
                    StringBuilder str = new StringBuilder();
                    str.Append((Math.Round(val, 3)).ToString());
                    Color valColor = (val > 0) ? Color.YellowGreen : Color.OrangeRed;
                    textBrush.Color = valColor;
                    Brush b = textBrush;
                    if (plotNum == -1)
                    {
                        //do nothing
                    }
                    else if (ind.Plots[plotNum] == null)
                    {
                        s = "Err: Plot Does not exsit!";
                    }
                    else
                    {
                        b = (ind.Plots[plotNum].Pen.Color == Color.Transparent)
                                ? textBrush
                                : ind.Plots[plotNum].Pen.Brush;
                    }
                    graphics.DrawString(s, textFont, b, bounds.X + bounds.Width - 37, bounds.Y + bounds.Height - boxNum * 20,
                                        stringFormat);
                    graphics.DrawString(str.ToString(), textFont, textBrush, bounds.X + bounds.Width - 3,
                                        bounds.Y + bounds.Height - boxNum * 20, stringFormat);
                }
            }
        }
示例#11
0
        /// <summary>
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="bounds"></param>
        /// <param name="min"></param>
        /// <param name="max"></param>
        public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
        {
            if (Bars == null || ChartControl == null)
            {
                return;
            }

            // plot error if data not complete
            if (textBrush.Color != ChartControl.AxisColor || textFont != ChartControl.Font)
            {
                textBrush.Color = ChartControl.AxisColor;
                textFont        = ChartControl.Font;

                SizeF errorSize = graphics.MeasureString(errorData, textFont);
                errorTextWidth  = errorSize.Width + 5;
                errorTextHeight = errorSize.Height + 5;
            }

            if (priorDayHLC == HLCCalculationMode.CalcFromIntradayData)
            {
                DateTime lastBarDate = (Bars.Count == 0) ? Cbi.Globals.MaxDate : ChartControl.EquidistantBars ?
                                       Bars.GetTime(Math.Min(Bars.Count - 1, ChartControl.LastBarPainted)).Date
                                                                                : Bars.GetTime(Math.Min(Bars.Count - 1, Bars.GetBar(ChartControl.LastBarTimePainted))).Date;
                if ((lastBarDate == Cbi.Globals.MaxDate) ||
                    (Bars.BarsType.BuiltFrom == PeriodType.Minute &&
                     ((pivotRangeType == PivotRange.Monthly && Bars.Count > 0 && Bars.GetTime(0).AddSeconds(-1).Date >= new DateTime(lastBarDate.Year, lastBarDate.Month, 1).AddMonths(-1)) ||
                      (pivotRangeType == PivotRange.Weekly && Bars.Count > 0 && Bars.GetTime(0).AddSeconds(-1).Date >= lastBarDate.AddDays(-(((int)lastBarDate.DayOfWeek) + 1) % 7).AddDays(-7)) ||
                      (pivotRangeType == PivotRange.Daily && Bars.Count > 0 && Bars.GetTime(0).AddSeconds(-1).Date >= lastBarDate.AddDays(-1)))) ||
                    (Bars.BarsType.BuiltFrom != PeriodType.Minute &&
                     ((pivotRangeType == PivotRange.Monthly && Bars.Count > 0 && Bars.GetTime(0).Date >= new DateTime(lastBarDate.Year, lastBarDate.Month, 1).AddMonths(-1)) ||
                      (pivotRangeType == PivotRange.Weekly && Bars.Count > 0 && Bars.GetTime(0).Date >= lastBarDate.AddDays(-(((int)lastBarDate.DayOfWeek) + 1) % 7).AddDays(-7)) ||
                      (pivotRangeType == PivotRange.Daily && Bars.Count > 0 && Bars.GetTime(0).Date >= lastBarDate.AddDays(-1)))))
                {
                    graphics.DrawString(errorData, ChartControl.Font, textBrush, bounds.X + bounds.Width - errorTextWidth, bounds.Y + bounds.Height - errorTextHeight, stringFormatNear);
                }
            }
            else if (priorDayHLC == HLCCalculationMode.DailyBars && existsHistDailyData)
            {
                DateTime lastBarDate = (dailyBars.Count == 0) ? Cbi.Globals.MaxDate : ChartControl.EquidistantBars ?
                                       dailyBars.GetTime(Math.Min(dailyBars.Count - 1, ChartControl.LastBarPainted)).Date
                                        : dailyBars.GetTime(Math.Min(dailyBars.Count - 1, dailyBars.GetBar(ChartControl.LastBarTimePainted))).Date;
                if ((lastBarDate == Cbi.Globals.MaxDate) ||
                    (pivotRangeType == PivotRange.Monthly && dailyBars.GetTime(0).Date >= new DateTime(lastBarDate.Year, lastBarDate.Month, 1).AddMonths(-1)) ||
                    (pivotRangeType == PivotRange.Weekly && dailyBars.GetTime(0).Date >= lastBarDate.AddDays(-(((int)lastBarDate.DayOfWeek) + 1) % 7).AddDays(-7)) ||
                    (pivotRangeType == PivotRange.Daily && dailyBars.GetTime(0).Date >= lastBarDate.AddDays(-1)))
                {
                    graphics.DrawString(errorData, ChartControl.Font, textBrush, bounds.X + bounds.Width - errorTextWidth, bounds.Y + bounds.Height - errorTextHeight, stringFormatNear);
                }
            }

            float textHeight = ChartControl.Font.GetHeight();

            for (int seriesCount = 0; seriesCount < Values.Length; seriesCount++)
            {
                SolidBrush     brush = brushes[seriesCount];
                int            firstBarIdxToPaint = -1;
                int            lastX            = -1;
                int            lastY            = -1;
                SmoothingMode  oldSmoothingMode = graphics.SmoothingMode;
                Gui.Chart.Plot plot             = Plots[seriesCount];
                DataSeries     series           = (DataSeries)Values[seriesCount];

                for (int i = newSessionBarIdxArr.Count - 1; i >= 0; i--)
                {
                    int prevSessionBreakIdx = (int)newSessionBarIdxArr[i];
                    if (prevSessionBreakIdx <= this.LastBarIndexPainted)
                    {
                        firstBarIdxToPaint = prevSessionBreakIdx;
                        break;
                    }
                }

                using (GraphicsPath path = new GraphicsPath())
                {
                    if (brush.Color != plot.Pen.Color)
                    {
                        brush = new SolidBrush(plot.Pen.Color);
                    }

                    for (int idx = this.LastBarIndexPainted; idx >= Math.Max(this.FirstBarIndexPainted, this.LastBarIndexPainted - Width); idx--)
                    {
                        if (idx - Displacement < 0 || idx - Displacement >= Bars.Count || (!ChartControl.ShowBarsRequired && idx - Displacement < BarsRequired))
                        {
                            continue;
                        }
                        else if (!series.IsValidPlot(idx))
                        {
                            continue;
                        }

                        if (idx < firstBarIdxToPaint)
                        {
                            break;
                        }

                        double val = series.Get(idx);
                        int    x   = ChartControl.GetXByBarIdx(BarsArray[0], idx);
                        int    y   = ChartControl.GetYByValue(this, val);

                        if (lastX >= 0)
                        {
                            if (y != lastY)                             // Problem here is, that last bar of old day has date of new day
                            {
                                y = lastY;
                            }
                            path.AddLine(lastX - plot.Pen.Width / 2, lastY, x - plot.Pen.Width / 2, y);
                        }
                        lastX = x;
                        lastY = y;
                    }

                    graphics.SmoothingMode = SmoothingMode.AntiAlias;
                    graphics.DrawPath(plot.Pen, path);
                    graphics.SmoothingMode = oldSmoothingMode;
                    graphics.DrawString(plot.Name, ChartControl.Font, brush, lastX, lastY - textHeight / 2, stringFormatFar);
                }
            }
        }
示例#12
0
 public void DrawColorLine(Graphics graphics, Rectangle bounds, double min, double max, DataSeries series, Pen upPen, Pen downPen)
 {
     if (Bars == null) return;
     int barPaintWidth = ChartControl.ChartStyle.GetBarPaintWidth(ChartControl.BarWidth);
     SmoothingMode smoothingMode = graphics.SmoothingMode;
     int num2 = -1;
     int num3 = -1;
     Pen pen = null;
     GraphicsPath path = null;
     for (int i = 0;
          i <= (Math.Min(ChartControl.BarsPainted, series.Count - ChartControl.FirstBarPainted) - 1);
          i++)
     {
         int index = ((ChartControl.LastBarPainted - ChartControl.BarsPainted) + 1) + i;
         if (ChartControl.ShowBarsRequired || ((index - Displacement) >= BarsRequired))
         {
             double d = series.Get(index);
             if (!double.IsNaN(d))
             {
                 int num7 = (((ChartControl.CanvasRight - ChartControl.BarMarginRight) - (barPaintWidth / 2)) -
                             ((ChartControl.BarsPainted - 1) * ChartControl.BarSpace)) + (i * ChartControl.BarSpace);
                 int num8 = (bounds.Y + bounds.Height) - ((int)(((d - min) / ChartControl.MaxMinusMin(max, min)) * bounds.Height));
                 if (num2 >= 0)
                 {
                     Pen pen2 = (d > 0.0) ? upPen : downPen;
                     if (pen2 != pen)
                     {
                         if (path != null)
                             if (pen != null) graphics.DrawPath(pen, path);
                         path = new GraphicsPath();
                         pen = pen2;
                     }
                     if (path != null) path.AddLine(num2, num3, num7, num8);
                 }
                 num2 = num7;
                 num3 = num8;
             }
             if (pen != null)
             {
                 graphics.SmoothingMode = SmoothingMode.AntiAlias;
                 graphics.DrawPath(pen, path);
                 graphics.SmoothingMode = smoothingMode;
             }
         }
     }
 }
示例#13
0
 public static int GetSlope(NinjaTrader.Strategy.Strategy strat, DataSeries series, int index)
 {
     return !series.ContainsValue(3) ? 0 : (int)((57.295779513082323 * Math.Atan(((series.Get(index) - ((series.Get(index + 1) + series.Get(index + 2)) / 2.0)) / 1.5) / strat.TickSize)) * -1.0);
 }
示例#14
0
 public static int GetSlope(Indicator ind, DataSeries series, int index)
 {
     return !series.ContainsValue(3) ? 0 : (int)((57.295779513082323 * Math.Atan(((series.Get(index) - ((series.Get(index + 1) + series.Get(index + 2)) / 2.0)) / 1.5) / ind.TickSize)) * -1.0);
 }
示例#15
0
        public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
        {
            if (Bars == null)
            {
                return;
            }

            byte bRed   = (byte)~(ChartControl.BackColor.R);
            byte bGreen = (byte)~(ChartControl.BackColor.G);
            byte bBlue  = (byte)~(ChartControl.BackColor.B);

            Color borderColor = Color.FromArgb(bRed, bGreen, bBlue);

            if (lineWidth > 0)
            {
                // draw back lines
                Pen    linePen   = new Pen(lineBrush, lineWidth);
                double lineSpace = 100;

                {
                    double y = (bounds.Y + bounds.Height) - ((0 - min) / ChartControl.MaxMinusMin(max, min)) * bounds.Height;
                    graphics.DrawLine(linePen, ChartControl.CanvasLeft, (int)y, ChartControl.CanvasRight, (int)y);
                }
                while (max > lineSpace || min < lineSpace * -1)
                {
                    double y = (bounds.Y + bounds.Height) - ((lineSpace - min) / ChartControl.MaxMinusMin(max, min)) * bounds.Height;
                    graphics.DrawLine(linePen, ChartControl.CanvasLeft, (int)y, ChartControl.CanvasRight, (int)y);
                    y = (bounds.Y + bounds.Height) - (((lineSpace * -1) - min) / ChartControl.MaxMinusMin(max, min)) * bounds.Height;
                    graphics.DrawLine(linePen, ChartControl.CanvasLeft, (int)y, ChartControl.CanvasRight, (int)y);

                    lineSpace += 100;
                }
            }

            int bars          = ChartControl.BarsPainted;
            int barPaintWidth = ChartControl.ChartStyle.GetBarPaintWidth(ChartControl.BarWidth);

            if (ChartControl.LastBarPainted - ChartControl.BarsPainted + 1 + bars - Bars.Count != 0)
            {
                bars--;
            }

            while (bars >= 0)
            {
                int index = ((ChartControl.LastBarPainted - ChartControl.BarsPainted) + 1) + bars;

                if (ChartControl.ShowBarsRequired || index - Displacement >= BarsRequired)
                {
                    try
                    {
                        double cciVal = CciPlot.Get(index);
                        int    x      = (((ChartControl.CanvasRight - ChartControl.BarMarginRight) - (barPaintWidth / 2)) -
                                         ((ChartControl.BarsPainted - 1) * ChartControl.BarSpace)) + (bars * ChartControl.BarSpace);
                        int y1 = (bounds.Y + bounds.Height) - ((int)(((cciVal - min) / ChartControl.MaxMinusMin(max, min)) * bounds.Height));

                        double alertVal = dotSeries.Get(index);

                        if (!double.IsNaN(alertVal) && !double.IsNaN(cciVal))
                        {
                            int y = (bounds.Y + bounds.Height) - ((int)(((0 - min) / ChartControl.MaxMinusMin(max, min)) * bounds.Height));

                            Color dotColor = Color.Transparent;

                            if (Math.Abs(1 - alertVal) < double.Epsilon)
                            {
                                dotColor = ChartControl.ChartStyle.UpColor;
                            }
                            else if (Math.Abs(-1 - alertVal) < double.Epsilon)
                            {
                                dotColor = ChartControl.ChartStyle.DownColor;
                            }
                            else if (Math.Abs(2 - alertVal) < double.Epsilon)
                            {
                                dotColor = Color.Gray;
                            }

                            if (dotColor != Color.Transparent)
                            {
                                int barOffset = (int)((double)(barWidth - 1) / 2);

                                // draw bars
                                if (y1 - y > 0)
                                {
                                    graphics.FillRectangle(new SolidBrush(dotColor), x - barOffset, y, barWidth, y1 - y);
                                }
                                else
                                {
                                    graphics.FillRectangle(new SolidBrush(dotColor), x - barOffset, y1, barWidth, y - y1);
                                }

                                if (showDots)
                                {
                                    // draw dots
                                    SmoothingMode smoothingMode = graphics.SmoothingMode;
                                    graphics.SmoothingMode = SmoothingMode.AntiAlias;

                                    Pen pen = new Pen(borderColor, 7)
                                    {
                                        DashStyle = DashStyle.Dot, DashCap = DashCap.Round
                                    };
                                    graphics.DrawPie(pen, x - 1, y, 2, 2, 0, 360);
                                    pen = new Pen(dotColor, 5)
                                    {
                                        DashStyle = DashStyle.Dot, DashCap = DashCap.Round
                                    };
                                    graphics.DrawRectangle(pen, x - 2, y - 1, 2, 2);
                                    graphics.SmoothingMode = smoothingMode;
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
                bars--;
            }

            // Default plotting in base class.
            base.Plot(graphics, bounds, min, max);
        }
示例#16
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 = hah.Get(idx);
                double valL = hal.Get(idx);
                double valC = hac.Get(idx);
                double valO = hao.Get(idx);

                bool val4  = c4.Get(idx);
                bool val5  = c5.Get(idx);
                bool val2  = c2.Get(idx);
                bool val67 = c67.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
                {
                    SolidBrush bup, bdn;

                    if (val4 && st4 == SignalType.BARCOLOR)
                    {
                        bup = bdn = b4;
                    }
                    else if (val5 && st5 == SignalType.BARCOLOR)
                    {
                        bup = bdn = b5;
                    }
                    else if (val2 && st2 == SignalType.BARCOLOR)
                    {
                        bup = bdn = b2;
                    }
                    else if (val67 && st67 == SignalType.BARCOLOR)
                    {
                        bup = bdn = b67;
                    }
                    else
                    {
                        bup = brushUp; bdn = brushDown;
                    }

                    if (y4 > y1)
                    {
                        graphics.FillRectangle(bup, x - barPaintWidth / 2, y1, barPaintWidth, y4 - y1);
                    }
                    else
                    {
                        graphics.FillRectangle(bdn, 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));
                }
            }

            base.Plot(graphics, bounds, min, max);
        }
示例#17
0
 public static int GetSlope(Indicator ind, DataSeries series, int index)
 {
     return(!series.ContainsValue(3) ? 0 : (int)((57.295779513082323 * Math.Atan(((series.Get(index) - ((series.Get(index + 1) + series.Get(index + 2)) / 2.0)) / 1.5) / ind.TickSize)) * -1.0));
 }
        public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)

        {
            int barPaintWidth = ChartControl.ChartStyle.GetBarPaintWidth(ChartControl.BarWidth);
            int spacing       = (ChartControl.BarSpace - barPaintWidth) / 2 - 1;

            if (spacing < 0)
            {
                spacing = 0;
            }

            int bars = ChartControl.BarsPainted;

            int index;

            float x1, y1, y2, y3, y4;

            float lastX = 0;

            float lastY = 0;


            Exception caughtException;

            while (bars >= 0)

            {
                index = ChartControl.LastBarPainted - ChartControl.BarsPainted + bars;
                if (ChartControl.ShowBarsRequired || ((index - base.Displacement) >= base.BarsRequired))

                {
                    // only draw the candle ends...
                    if ((index > 0) &&
                        ((index == CurrentBar) || (pe.BarIndex.Get(index + 1) <= pe.BarIndex.Get(index))))
                    {
                        try

                        {
                            int multibarWidth = (ChartControl.BarSpace * (pe.BarIndex.Get(index))) + barPaintWidth;

                            x1 = (((ChartControl.CanvasRight - ChartControl.BarMarginRight) - (multibarWidth / 2)) - ((ChartControl.BarsPainted - 1) * ChartControl.BarSpace)) + ((bars - 1) * (base.ChartControl.BarSpace)) - penWidth / 2;

                            y1 = (bounds.Y + bounds.Height) - ((int)((((double)mxSeen.Get(index) - min) / Gui.Chart.ChartControl.MaxMinusMin(max, min)) * bounds.Height));

                            y2 = (bounds.Y + bounds.Height) - ((int)((((double)clSeen.Get(index) - min) / Gui.Chart.ChartControl.MaxMinusMin(max, min)) * bounds.Height));

                            y3 = (bounds.Y + bounds.Height) - ((int)((((double)opSeen.Get(index) - min) / Gui.Chart.ChartControl.MaxMinusMin(max, min)) * bounds.Height));

                            y4 = (bounds.Y + bounds.Height) - ((int)((((double)mnSeen.Get(index) - min) / Gui.Chart.ChartControl.MaxMinusMin(max, min)) * bounds.Height));


                            if (y2 > y3)

                            {
                                if (!boxStyle)
                                {
                                    graphics.DrawRectangle(bearPen, (int)x1 - multibarWidth / 2 - spacing, (int)y3, multibarWidth + 2 * spacing - penWidth / 2, y2 - y3);
                                    graphics.DrawLine(bearPen, x1, y4, x1, y2);
                                    graphics.DrawLine(bearPen, x1, y1, x1, y3);
                                }
                                else
                                {
                                    graphics.DrawRectangle(bearPen, (int)x1 - multibarWidth / 2 - spacing, (int)y1, multibarWidth + 2 * spacing - penWidth / 2, y4 - y1);
                                    graphics.FillRectangle(bearBrush, (int)x1 - multibarWidth / 2 - spacing, (int)y3, multibarWidth + 2 * spacing - penWidth / 2, y2 - y3);
                                }
                            }

                            else if (y2 < y3)
                            {
                                if (!boxStyle)
                                {
                                    graphics.DrawRectangle(bullPen, (int)x1 - multibarWidth / 2 - spacing, (int)y2, multibarWidth + 2 * spacing - penWidth / 2, y3 - y2);
                                    graphics.DrawLine(bullPen, x1, y4, x1, y3);
                                    graphics.DrawLine(bullPen, x1, y1, x1, y2);
                                }
                                else
                                {
                                    graphics.DrawRectangle(bullPen, (int)x1 - multibarWidth / 2 - spacing, (int)y1, multibarWidth + 2 * spacing - penWidth / 2, y4 - y1);
                                    graphics.FillRectangle(bullBrush, (int)x1 - multibarWidth / 2 - spacing, (int)y2, multibarWidth + 2 * spacing - penWidth / 2, y3 - y2);
                                }
                            }

                            else if (y2 == y3)
                            {
                                if (!boxStyle)
                                {
                                    graphics.DrawRectangle(bullPen, (int)x1 - multibarWidth / 2 - spacing, (int)y3, multibarWidth + 2 * spacing - penWidth / 2, 1);
                                    graphics.DrawLine(bullPen, x1, y4, x1, y3);
                                    graphics.DrawLine(bullPen, x1, y1, x1, y2);
                                }
                                else
                                {
                                    graphics.DrawRectangle(bullPen, (int)x1 - multibarWidth / 2 - spacing, (int)y1, multibarWidth + 2 * spacing - penWidth / 2, y4 - y1);
                                    graphics.DrawRectangle(bullPen, (int)x1 - multibarWidth / 2 - spacing, (int)y3, multibarWidth + 2 * spacing - penWidth / 2, 1);
                                }
                            }
                        }

                        catch (Exception exception) {
                            caughtException = exception;
                        }
                    } // only draw the candle ends...
                }     // if on canvas

                bars--;
            } // candle drawing loop...
        }
示例#19
0
        public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
        {
            if (Bars == null || ChartControl == null)
            {
                return;
            }

            if (Color.Transparent == cloudAreaColorUp && Color.Transparent == cloudAreaColorDown || 0 == cloudColorOpacity)
            {
                base.Plot(graphics, bounds, min, max);                          // Call base Plot() method to paint defined Plots.
                return;                                                         // If cloudAreaColor colors are transparent or cloudColorOpacity is 0
                // there is nothing to paint so return to avoid unnecessary calculations.
            }

            SolidBrush brush     = null;                                                                // Set current brush color here.
            SolidBrush brushUP   = new SolidBrush(Color.FromArgb(cloudColorOpacity, cloudAreaColorUp));
            SolidBrush brushDOWN = new SolidBrush(Color.FromArgb(cloudColorOpacity, cloudAreaColorDown));

            int           barWidth         = ChartControl.ChartStyle.GetBarPaintWidth(ChartControl.BarWidth);
            SmoothingMode oldSmoothingMode = graphics.SmoothingMode;
            GraphicsPath  path             = new GraphicsPath();                        // Create a new path.

            brush = brushUP;                                                            // Start with the upwards color.
            int  barcount = 0;                                                          // Start with leftmost bar.
            bool firstbar = true;                                                       // Plotting the first bar.

            while (barcount < ChartControl.BarsPainted)                                 // Continue until all bars have been painted.
            {
                int count = 0;                                                          // Counter for innner loop.
                for (int seriesCount = 0; seriesCount < 2; seriesCount++)
                {
                    int        lastX  = -1;
                    int        lastY  = -1;
                    DataSeries series = (0 == seriesCount) ? SenkouSpanA : SenkouSpanB;

                    for (count = barcount; count < ChartControl.BarsPainted; count++)
                    {
                        int idx = ChartControl.LastBarPainted - ChartControl.BarsPainted + 1 + count - periodMedium;
                        if (idx < 0 || idx >= Input.Count || (!ChartControl.ShowBarsRequired && idx < BarsRequired))
                        {
                            continue;
                        }

                        bool senkouSpanAHasValue = SenkouSpanA.IsValidPlot(idx) && SenkouSpanA.Get(idx) > 0;
                        bool senkouSpanBHasValue = SenkouSpanB.IsValidPlot(idx) && SenkouSpanB.Get(idx) > 0;
                        if (!senkouSpanAHasValue || !senkouSpanAHasValue)                       // If we don't have valid value for the series then skip the loop step
                        // as there is nothing to plot. So ignore the entry.
                        {
                            continue;
                        }

                        double val = series.Get(idx);                                                                                   // Get next y-value to be plotted.

                        int x = (int)(ChartControl.CanvasRight - ChartControl.BarMarginRight - barWidth / 2
                                      + (count - ChartControl.BarsPainted + 1) * ChartControl.BarSpace) + 1;

                        int y = (int)((bounds.Y + bounds.Height) - ((val - min) / Gui.Chart.ChartControl.MaxMinusMin(max, min)) * bounds.Height);

                        double val0 = SenkouSpanA.Get(idx);
                        double val1 = SenkouSpanB.Get(idx);

                        if (((val0 > val1) && (brush != brushUP)) ||                                    // Now going in wrong direction?
                            ((val0 < val1) && (brush != brushDOWN)))
                        {                                                                               // Yes.  Done with this loop.
                            if (lastX >= 0)                                                             // Was there a last point?
                            {                                                                           // Yes.  Connect it to the position half-way to this one.
                                path.AddLine(lastX, lastY, (x + lastX) / 2, (lastY + y) / 2);
                                // Plot vertex of cross-over of the lines (1/2 way point).
                            }
                            break;                                                                                                      // Done, exit inner loop to change color.
                        }

                        if (firstbar == false)                                                              // Is this the first plotted bar of the chart?
                        {                                                                                   // No.  Plot all bars after the first one.
                            if (count == barcount)                                                          // First bar after direction change (and color swap)?
                            {                                                                               // Yes.  Add line segment for cross-over, 1/2 bar back.
                                double valm1 = series.Get(idx - 1);                                         // Get prior y-value to be plotted.
                                lastX = x - ChartControl.BarSpace / 2;                                      // Back up 1/2 a bar for x-value.
                                lastY = (y + (int)((bounds.Y + bounds.Height) - ((valm1 - min) / Gui.Chart.ChartControl.MaxMinusMin(max, min)) * bounds.Height)) / 2;
                            }

                            path.AddLine(lastX, lastY, x, y);                                                   // Connect last point to this one.
                        }
                        firstbar = false;                                                                       // No longer the first bar.
                        lastX    = x;                                                                           // Save current position for next time, so we can connect the dots.
                        lastY    = y;
                    }

                    path.Reverse();                                                                                             // Go back the other direction.
                }

                graphics.SmoothingMode = SmoothingMode.AntiAlias;
                graphics.FillPath(brush, path);
                path.Reset();                                                                   // Eliminate points already colored.

                barcount = count;                                                               // Get ready to process next segment.
                brush    = (brush == brushUP) ? brushDOWN : brushUP;                            // Switch colors for next segment.
            }

            graphics.SmoothingMode = oldSmoothingMode;                                                  // Restore smoothing mode before exiting.
            brushUP.Dispose();                                                                          // Dispose of brushes.
            brushDOWN.Dispose();
            path.Dispose();                                                                             // Dispose of path.
            base.Plot(graphics, bounds, min, max);                                                      // Call the base Plot() method to paint defined Plots.
        }
示例#20
0
        public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
        {
            if (Bars == null)
            {
                return;
            }

            if (useplot)
            {
                base.Plot(graphics, bounds, min, max);


                int lastBar  = Math.Min(this.LastBarIndexPainted, Bars.Count - 1);
                int firstBar = this.FirstBarIndexPainted;

                Pen outlinePen = ChartControl.ChartStyle.Pen;

                int barPaintWidth = (int)(1 + 2 * (ChartControl.ChartStyle.BarWidthUI - 1) + 2 * outlinePen.Width);                  //ChartControl.ChartStyle.GetBarPaintWidth(ChartControl.BarWidth);
                int barwidth      = ChartControl.BarWidth;



                Color ColorNeutral = outlinePen.Color;

                Pen HiLoPen = (Pen)outlinePen.Clone();

                if (EnhanceHL)
                {
                    HiLoPen.Width *= 2;
                }



                int penSize;

                if (ChartControl.ChartStyle.ChartStyleType == ChartStyleType.OHLC)
                {
                    penSize = Math.Max(0, barwidth - 2);
                }
                else if (ChartControl.ChartStyle.ChartStyleType == ChartStyleType.HiLoBars)
                {
                    penSize = barwidth;
                }
                else if (chart == GomCDChartType.NonCumulativeChart && ForceHiLo)
                {
                    penSize = ForcedHiLoBS;
                }
                else
                {
                    penSize = 1;
                }

                drawPen.Width = penSize;

                int x, yHigh, yClose, yOpen, yLow;
                int direction;

                //zero line
                int y0 = ChartControl.GetYByValue(this, 0.0);



                if ((chart == GomCDChartType.NonCumulativeChart) || ReinitSession)
                {
                    graphics.DrawLine(new Pen(Color.Blue), bounds.X, y0, bounds.X + bounds.Width, y0);
                }

                for (int index = firstBar; index <= lastBar; index++)
                {
                    direction = 0;

                    if ((index <= lastcalcbar) && (index >= Math.Max(1, startbar)))
                    {
                        x      = ChartControl.GetXByBarIdx(BarsArray[0], index);
                        yHigh  = ChartControl.GetYByValue(this, dsHigh.Get(index));
                        yClose = ChartControl.GetYByValue(this, dsClose.Get(index));
                        yOpen  = ChartControl.GetYByValue(this, dsOpen.Get(index));
                        yLow   = ChartControl.GetYByValue(this, dsLow.Get(index));


                        if (PtType == GomPaintType.StrongUpDown)
                        {
                            if (dsClose.Get(index) < dsLow.Get(index - 1))
                            {
                                direction = -1;
                            }
                            else if (dsClose.Get(index) > dsHigh.Get(index - 1))
                            {
                                direction = 1;
                            }
                        }
                        else if (PtType == GomPaintType.UpDown)
                        {
                            if (dsClose.Get(index) < dsOpen.Get(index))
                            {
                                direction = -1;
                            }
                            else if (dsClose.Get(index) > dsOpen.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) || (chart == GomCDChartType.NonCumulativeChart && ForceHiLo))
                        {
                            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 - barPaintWidth / 2, Math.Min(yClose, yOpen) + 1, barPaintWidth, Math.Abs(yClose - yOpen));

                                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));

                                    graphics.DrawRectangle(outlinePen, x - (barPaintWidth / 2) + (outlinePen.Width / 2), Math.Min(yClose, yOpen), barPaintWidth - outlinePen.Width, 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);
            }
        }
示例#21
0
        //
        //  This Plot() method has been tweaked so it will color in two different colors
        //  in-between the two plots of Values[3] and Values[4].
        //
        public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
        {
            base.Plot(graphics, bounds, min, max);

            if (Bars == null || ChartControl == null)
            {
                return;
            }

            SolidBrush brush;                                                                           // Set current brush color here.

            SolidBrush brushUP   = new SolidBrush(Color.FromArgb(bandAreaColorOpacity * 20, bandAreaColorUp));
            SolidBrush brushDOWN = new SolidBrush(Color.FromArgb(bandAreaColorOpacity * 20, bandAreaColorDown));

            int           barWidth         = ChartControl.ChartStyle.GetBarPaintWidth(ChartControl.BarWidth);
            SmoothingMode oldSmoothingMode = graphics.SmoothingMode;
            GraphicsPath  path             = new GraphicsPath();

            DataSeries series0 = (DataSeries)Values[0];                 // Color in between these two plots.
            DataSeries series1 = (DataSeries)Values[1];

            brush = brushUP;                                                    // Start with the upwards color.
            int  barcount = 0;                                                  // Start with leftmost bar.
            bool firstbar = true;                                               // Plotting the first bar.

            while (barcount < ChartControl.BarsPainted)                         // Continue until all bars have been painted.
            {
                int count = 0;                                                  // Counter for innner loop.
                for (int seriesCount = 0; seriesCount < 2; seriesCount++)
                {
                    int            lastX  = -1;
                    int            lastY  = -1;
                    DataSeries     series = (DataSeries)Values[seriesCount];
                    Gui.Chart.Plot plot   = Plots[seriesCount];

                    for (count = barcount; count < ChartControl.BarsPainted; count++)
                    {
                        int idx = ChartControl.LastBarPainted - ChartControl.BarsPainted + 1 + count;
                        if (idx < 0 || idx >= Input.Count || (!ChartControl.ShowBarsRequired && idx < BarsRequired))
                        {
                            continue;
                        }

                        double val = series.Get(idx);                                                           // Get next y-value to be plotted.
                        if (val == 0)                                                                           // If nothing to plot...
                        {
                            continue;                                                                           // ...ignore the enrtry.
                        }
                        int x = (int)(ChartControl.CanvasRight - ChartControl.BarMarginRight - barWidth / 2
                                      + (count - ChartControl.BarsPainted + 1) * ChartControl.BarSpace) + 1;

                        int y = (int)((bounds.Y + bounds.Height) - ((val - min) / Gui.Chart.ChartControl.MaxMinusMin(max, min)) * bounds.Height);

                        double val0 = series0.Get(idx);
                        double val1 = series1.Get(idx);
                        if (((val0 > val1) && (brush != brushUP)) ||                            // Now going in wrong direction?
                            ((val0 < val1) && (brush != brushDOWN)))
                        {                                                                       // Yes.  Done with this loop.
                            if (lastX >= 0)                                                     // Was there a last point?
                            {                                                                   // Yes.  Connect it to the position half-way to this one.
                                path.AddLine(lastX - plot.Pen.Width / 2, lastY, (x + lastX - plot.Pen.Width) / 2, (lastY + y) / 2);
                                // Plot vertex of cross-over of the lines (1/2 way point).
                            }
                            break;                                                                                              // Done, exit inner loop to change color.
                        }

                        if (firstbar == false)                                                      // Is this the first plotted bar of the chart?
                        {                                                                           // No.  Plot all bars after the first one.
                            if (count == barcount)                                                  // First bar after direction change (and color swap)?
                            {                                                                       // Yes.  Add line segment for cross-over, 1/2 bar back.
                                double valm1 = series.Get(idx - 1);                                 // Get prior y-value to be plotted.
                                lastX = x - ChartControl.BarSpace / 2;                              // Back up 1/2 a bar for x-value.
                                lastY = (y + (int)((bounds.Y + bounds.Height) - ((valm1 - min) / Gui.Chart.ChartControl.MaxMinusMin(max, min)) * bounds.Height)) / 2;
                            }

                            path.AddLine(lastX - plot.Pen.Width / 2, lastY, x - plot.Pen.Width / 2, y);                 // Connect last point to this one.
                        }
                        firstbar = false;                                                                               // No longer the first bar.
                        lastX    = x;                                                                                   // Save current position for next time, so we can connect the dots.
                        lastY    = y;
                    }
                    path.Reverse();                                                                                     // Go back the other direction.
                }
                graphics.SmoothingMode = SmoothingMode.AntiAlias;
                graphics.FillPath(brush, path);
                path.Reset();                                                           // Eliminate points already colored.

                barcount = count;                                                       // Get ready to process next segment.
                brush    = (brush == brushUP) ? brushDOWN : brushUP;                    // Switch colors for next segment.
            }
            graphics.SmoothingMode = oldSmoothingMode;                                  // Restore smoothing mode before exiting.
        }
        public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
        {
            double valH = 0;
            double valL = 0;
            double valC = 0;
            double valO = 0;
            int    x    = 0;
            int    y1   = 0;
            int    y2   = 0;
            int    y3   = 0;
            int    y4   = 0;

            try {
                if (Bars == null || ChartControl == null)
                {
                    return;
                }

                if (colorZeroLine != Color.Transparent)
                {
                    int yz = ChartControl.GetYByValue(this, 0);
                    graphics.DrawLine(zeroLinePen, bounds.Left, yz, bounds.Right, yz);
                }

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

                int firstBar = Math.Max(this.FirstBarIndexPainted, 1);
                if (firstBar < startbar)
                {
                    firstBar = startbar;
                }

                int lastBar = Math.Min(this.LastBarIndexPainted, Bars.Count - 1);
                if (lastBar > lastcalcbar)
                {
                    lastBar = lastcalcbar;
                }

                for (int idx = firstBar; idx <= lastBar; idx++)
                {
                    valH = dsSShigh.Get(idx);
                    valL = dsSSlow.Get(idx);
                    valC = dsSSclose.Get(idx);
                    valO = dsSSopen.Get(idx);

                    x  = ChartControl.GetXByBarIdx(BarsArray[0], idx);
                    y1 = ChartControl.GetYByValue(this, valO);
                    y2 = ChartControl.GetYByValue(this, valH);
                    y3 = ChartControl.GetYByValue(this, valL);
                    y4 = ChartControl.GetYByValue(this, valC);

                    if (colorBaseLine != Color.Transparent)
                    {
                        double valB = dsSSbase.Get(idx);
                        int    yb   = ChartControl.GetYByValue(this, valB);

                        graphics.DrawLine(baseLinePen, x - barPaintWidth, yb, x + barPaintWidth, yb);
                    }

                    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));
                    }
                }
            } catch (Exception ex) { Print("Exception in t4tSpreadSym on line 420: " + ex.Message); }
        }
示例#23
0
 public static int GetSlope(NinjaTrader.Strategy.Strategy strat, DataSeries series, int index)
 {
     return(!series.ContainsValue(3) ? 0 : (int)((57.295779513082323 * Math.Atan(((series.Get(index) - ((series.Get(index + 1) + series.Get(index + 2)) / 2.0)) / 1.5) / strat.TickSize)) * -1.0));
 }
示例#24
0
 public static void DrawValueString(Indicator ind, Graphics graphics, Rectangle bounds, string plotName, int plotNum, DataSeries series, int boxNum)
 {
     int num2 = ind.CalculateOnBarClose ? (ind.ChartControl.BarsPainted - 2) : (ind.ChartControl.BarsPainted - 1);
     if (ind.Bars != null)
     {
         int index = ((ind.ChartControl.LastBarPainted - ind.ChartControl.BarsPainted) - 1) + num2;
         if (ind.ChartControl.ShowBarsRequired || ((index - ind.Displacement) >= ind.BarsRequired))
         {
             double num3 = series.Get(index);
             string s = plotName + ": ";
             StringBuilder builder = new StringBuilder();
             builder.Append(Math.Round(num3, 3).ToString(CultureInfo.InvariantCulture));
             Color color = (num3 > 0.0) ? upColor : downColor;
             textBrush.Color = color;
             Brush brush = textBrush;
             if (plotNum != -1)
             {
                 if (ind.Plots[plotNum] == null)
                     s = "Err: Plot Does not exsit!";
                 else
                     brush = (ind.Plots[plotNum].Pen.Color == Color.Transparent) ? textBrush : ind.Plots[plotNum].Pen.Brush;
             }
             graphics.DrawString(s, textFont, brush, (bounds.X + bounds.Width) - 37, (bounds.Y + bounds.Height) - (boxNum * 20), stringFormat);
             graphics.DrawString(builder.ToString(), textFont, textBrush, (bounds.X + bounds.Width) - 3, (bounds.Y + bounds.Height) - (boxNum * 20), stringFormat);
         }
     }
 }
示例#25
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;
                }
            }
        }
示例#26
0
        protected override void OnBarUpdate()
        {
            if (CurrentBar < 200)
            {
                return;
            }

            if (0 == iNoAlts)
            {
                switch (noPlots)
                {
                case AdaptiveCciPlots.One: iNoAlts = 1; break;

                case AdaptiveCciPlots.Two: iNoAlts = 2; break;

                case AdaptiveCciPlots.Three: iNoAlts = 3; break;

                case AdaptiveCciPlots.Four: iNoAlts = 4; break;
                }
            }

            smooth.Set((4 * Input[0] + 3 * Input[1] + 2 * Input[2] + Input[3]) * 0.1);
            detrender.Set((0.0962 * smooth[0] + 0.5769 * smooth[2] - 0.5769 * smooth[4] - 0.0962 * smooth[6]) * (0.075 * period[1] + 0.54));

            // Compute InPhase and Quadrature components
            q1.Set((0.0962 * detrender[0] + 0.5769 * detrender[2] - 0.5769 * detrender[4] - 0.0962 * detrender[6]) * (0.075 * period[1] + 0.54));

            i1.Set(detrender[3]);

            // Advance the phase of i1 and q1 by 90}
            double jI = (0.0962 * i1[0] + 0.5769 * i1[2] - 0.5769 * i1[4] - 0.0962 * i1[6]) * (0.075 * period[1] + 0.54);
            double jQ = (0.0962 * q1[0] + 0.5769 * q1[2] - 0.5769 * q1[4] - 0.0962 * q1[6]) * (0.075 * period[1] + 0.54);

            // Phasor addition for 3 bar averaging}
            i2.Set(i1[0] - jQ);
            q2.Set(q1[0] + jI);

            // Smooth the I and Q components before applying the discriminator
            i2.Set(0.2 * i2[0] + 0.8 * i2[1]);
            q2.Set(0.2 * q2[0] + 0.8 * q2[1]);

            // Homodyne Discriminator
            re.Set(i2[0] * i2[1] + q2[0] * q2[1]);
            im.Set(i2[0] * q2[1] - q2[0] * i2[1]);

            re.Set(0.2 * re[0] + 0.8 * re[1]);
            im.Set(0.2 * im[0] + 0.8 * im[1]);

            if (Math.Abs(im[0]) > double.Epsilon && Math.Abs(re[0]) > double.Epsilon)
            {
                period.Set(360 / ((180 / Math.PI) * Math.Atan(im[0] / re[0])));
            }
            if (period[0] > 1.5 * period[1])
            {
                period.Set(1.5 * period[1]);
            }
            if (period[0] < 0.67 * period[1])
            {
                period.Set(0.67 * period[1]);
            }
            if (period[0] < 6)
            {
                period.Set(6);
            }
            if (period[0] > 200)
            {
                period.Set(200);
            }

            period.Set(0.2 * period[0] + 0.8 * period[1]);

            int length = periodMultiplier * (int)(cycPart * period[0]);

            lengthVars.Set(length);
            //			Print(Length);
            vMedianPrice.Set((High[0] + Low[0] + Close[0]) / 3);
            double avg = 0;

            for (int count = 0; count < length; count++)
            {
                avg = avg + vMedianPrice[count];
            }

            avg = avg / length;
            double md = 0;

            for (int count = 0; count < length; count++)
            {
                md = md + Math.Abs(vMedianPrice[count] - avg);
            }

            md = md / length;

            if (Math.Abs(md) < double.Epsilon)
            {
                return;
            }

            adaptCci.Set((vMedianPrice[0] - avg) / (0.015 * md));
            CciPlot.Set(SMA(adaptCci, smaSmooth)[0]);

            DataSeries dsAlt1 = AdaptiveAlternativeCci(cycPart, numBars1, periodMultiplier, smaSmooth).CciPlot;
            DataSeries dsAlt2 = AdaptiveAlternativeCci(cycPart, numBars2, periodMultiplier, smaSmooth).CciPlot;
            DataSeries dsAlt3 = AdaptiveAlternativeCci(cycPart, numBars3, periodMultiplier, smaSmooth).CciPlot;
            DataSeries dsAlt4 = AdaptiveAlternativeCci(cycPart, numBars4, periodMultiplier, smaSmooth).CciPlot;

            if (iNoAlts > 0)
            {
                AltCciPlot1.Set(dsAlt1.Get(CurrentBar));
            }
            if (iNoAlts > 1)
            {
                AltCciPlot2.Set(dsAlt2.Get(CurrentBar));
            }
            if (iNoAlts > 2)
            {
                AltCciPlot3.Set(dsAlt3.Get(CurrentBar));
            }
            if (iNoAlts > 3)
            {
                AltCciPlot4.Set(dsAlt4.Get(CurrentBar));
            }

            if (iNoAlts > 3)
            {
                if (Rising(dsAlt1) && Rising(dsAlt2) && Rising(dsAlt3) && Rising(dsAlt4))
                {
                    dotSeries.Set(1);
                }
                else if (Falling(dsAlt1) && Falling(dsAlt2) && Falling(dsAlt3) && Falling(dsAlt4))
                {
                    dotSeries.Set(-1);
                }
                else
                {
                    dotSeries.Set(2);
                }
            }
            else if (iNoAlts > 2)
            {
                if (Rising(dsAlt1) && Rising(dsAlt2) && Rising(dsAlt3))
                {
                    dotSeries.Set(1);
                }
                else if (Falling(dsAlt1) && Falling(dsAlt2) && Falling(dsAlt3))
                {
                    dotSeries.Set(-1);
                }
                else
                {
                    dotSeries.Set(2);
                }
            }
            else if (iNoAlts > 1)
            {
                if (Rising(dsAlt1) && Rising(dsAlt2))
                {
                    dotSeries.Set(1);
                }
                else if (Falling(dsAlt1) && Falling(dsAlt2))
                {
                    dotSeries.Set(-1);
                }
                else
                {
                    dotSeries.Set(2);
                }
            }
            else if (iNoAlts > 0)
            {
                if (Rising(dsAlt1))
                {
                    dotSeries.Set(1);
                }
                else if (Falling(dsAlt1))
                {
                    dotSeries.Set(-1);
                }
                else
                {
                    dotSeries.Set(2);
                }
            }
            else if (Rising(CciPlot))
            {
                dotSeries.Set(1);
            }
            else if (Falling(CciPlot))
            {
                dotSeries.Set(-1);
            }
            else
            {
                dotSeries.Set(2);
            }
        }