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); }
protected override void OnBarUpdate() { if (CurrentBar < Math.Max(200, numBars)) { Value.Set(0); } else { 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]); smoothPeriod.Set(0.33 * period[0] + 0.67 * smoothPeriod[1]); int length = periodMultiplier * (int)(cycPart * period[0]); double high = High[0]; for (int i = 0; i < numBars; i++) { if (High[i] > high) { high = High[i]; } } double low = Low[0]; for (int i = 0; i < numBars; i++) { if (Low[i] < low) { low = Low[i]; } } vMedianPrice.Set((high + low + 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) { adaptCci.Set((vMedianPrice[0] - avg) / (0.015 * md)); CciPlot.Set(SMA(adaptCci, smaSmooth)[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); } }