コード例 #1
0
ファイル: SlingShot.cs プロジェクト: fandres70/custom
        public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
        {
            base.Plot(graphics, bounds, min, max); // We call base Plot() method to paint defined Plots

            if (_bandAreaColorUp == Color.Transparent && _bandAreaColorDown == Color.Transparent || _opacity == 0)
            {
                return; // if bandArea colors are transparent or opacity is 0 returning to avoid unnecessary calculations
            }
            SolidBrush upBrush   = new SolidBrush(Color.FromArgb(_opacity, _bandAreaColorUp));
            SolidBrush downBrush = new SolidBrush(Color.FromArgb(_opacity, _bandAreaColorDown));

            List <Point> points = new List <Point>();

            int        lastX         = -1;
            double     lastValueFast = -1;
            double     lastValueSlow = -1;
            SolidBrush brush         = null;

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

                bool fastHasValue = FastMA.IsValidPlot(idx) && FastMA.Get(idx) > 0;
                bool slowHasValue = SlowMA.IsValidPlot(idx) && SlowMA.Get(idx) > 0;
                if (!slowHasValue || !fastHasValue) //if we don't have valid values for BOTH moving averages then skip the loop step
                {
                    continue;
                }

                double valueFast = FastMA.Get(idx);
                double valueSlow = SlowMA.Get(idx);

                int x = ChartControl.GetXByBarIdx(BarsArray[0], idx);

                if (lastX >= 0)
                {
                    int yf0 = ChartControl.GetYByValue(this, lastValueFast);
                    int yf1 = ChartControl.GetYByValue(this, valueFast);
                    int ys0 = ChartControl.GetYByValue(this, lastValueSlow);
                    int ys1 = ChartControl.GetYByValue(this, valueSlow);

                    if (ys0 != yf0)
                    {
                        brush = ys0 < yf0 ? downBrush : upBrush;
                    }

                    if (Math.Sign(yf1 - ys1) != 0 && Math.Sign(yf0 - ys0) != Math.Sign(yf1 - ys1) || points.Count == 0) // We have a cross or only start painting
                    {
                        if (points.Count > 0 && brush != null)                                                          //
                        {
                            SmoothingMode oldSmoothingMode = graphics.SmoothingMode;

                            graphics.SmoothingMode = SmoothingMode.AntiAlias;
                            graphics.FillPolygon(brush, points.ToArray());
                            graphics.SmoothingMode = oldSmoothingMode;
                        }
                        points.Clear();
                        points.Add(new Point(lastX, yf0));
                        points.Add(new Point(x, yf1));
                        points.Add(new Point(x, ys1));
                        points.Add(new Point(lastX, ys0));
                        points.Add(new Point(lastX, yf0));
                    }
                    else
                    {
                        int pos = points.Count / 2;
                        points.Insert(pos, new Point(x, ys1));
                        points.Insert(pos, new Point(x, yf1));
                    }
                }
                // save as previous point
                lastX         = x;
                lastValueFast = valueFast;
                lastValueSlow = valueSlow;
            }
            if (points.Count > 0 && brush != null)
            {
                SmoothingMode oldSmoothingMode = graphics.SmoothingMode;

                graphics.SmoothingMode = SmoothingMode.AntiAlias;
                graphics.FillPolygon(brush, points.ToArray());
                graphics.SmoothingMode = oldSmoothingMode;
                points.Clear();
            }
        }
コード例 #2
0
ファイル: SlingShot.cs プロジェクト: fandres70/custom
        protected override void OnBarUpdate()
        {
            double f;
            double s;

            if (CurrentBar <= Math.Max(FastAverage, SlowAverage))
            {
                return;
            }
            switch (FastAverageType)
            {
            case MovingAverageType.EMA:
                f = EMA(_fastInput, FastAverage)[0];
                break;

            case MovingAverageType.SMA:
                f = SMA(_fastInput, FastAverage)[0];
                break;

            case MovingAverageType.TMA:
                f = TMA(_fastInput, FastAverage)[0];
                break;

            case MovingAverageType.WMA:
                f = WMA(_fastInput, FastAverage)[0];
                break;

            case MovingAverageType.VWMA:
                f = VWMA(_fastInput, FastAverage)[0];
                break;

            default:
                f = HMA(_fastInput, FastAverage)[0];
                break;
            }

            FastMA.Set(f);

            switch (SlowAverageType)
            {
            case MovingAverageType.EMA:
                s = EMA(_slowInput, SlowAverage)[0];
                break;

            case MovingAverageType.SMA:
                s = SMA(_slowInput, SlowAverage)[0];
                break;

            case MovingAverageType.TMA:
                s = TMA(_slowInput, SlowAverage)[0];
                break;

            case MovingAverageType.WMA:
                s = WMA(_slowInput, SlowAverage)[0];
                break;

            case MovingAverageType.VWMA:
                s = VWMA(_slowInput, SlowAverage)[0];
                break;

            default:
                s = HMA(_slowInput, SlowAverage)[0];
                break;
            }
            SlowMA.Set(s);

            if (High[0] < SlowMA[0] &&
                High[0] < FastMA[0])
            {
                if (Math.Min(SlowMA[0], FastMA[0]) - High[0] > pipsOffset)
                {
                    trendDataSeries[0] = -1.1;
                }
                else
                if (trendDataSeries.ContainsValue(1))
                {
                    trendDataSeries[0] = trendDataSeries[1];
                }
            }
            else if (Low[0] > SlowMA[0] &&
                     Low[0] > FastMA[0])
            {
                if (Low[0] - Math.Max(SlowMA[0], FastMA[0]) > pipsOffset)
                {
                    trendDataSeries[0] = 1.1;
                }
                else
                if (trendDataSeries.ContainsValue(1))
                {
                    trendDataSeries[0] = trendDataSeries[1];
                }
            }
            else
            {
                if (trendDataSeries.ContainsValue(1))
                {
                    trendDataSeries[0] = trendDataSeries[1];
                }
            }

            if (trendDataSeries.ContainsValue(0))
            {
                //plot
                if (trendDataSeries[0] > 1)
                {
                    DrawDiamond(CurrentBar + "dot", false, 0, High[0] + 25 * TickSize, Color.Green);
                }
                else if (trendDataSeries[0] < -1)
                {
                    DrawDiamond(CurrentBar + "dot", false, 0, Low[0] - 25 * TickSize, Color.Red);
                }
            }
        }