Esempio n. 1
0
        public override void GetMinMaxValues(ChartControl chartControl, ref double min, ref double max)
        {
            if (Bars == null)
            {
                return;
            }

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

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

            for (int index = firstBar; index <= lastBar; index++)
            {
                if ((index <= lastcalcbar) && (index >= Math.Max(1, startbar)))
                {
                    min = Math.Min(min, HALow.Get(index));
                    max = Math.Max(max, HAHigh.Get(index));
                }
            }

            if ((max - min) < 1)
            {
                min -= 1;
                max += 1;
            }
        }
Esempio n. 2
0
        protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
        {
            if (Bars == null || ChartControl == null)
            {
                return;
            }

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

            for (int idx = ChartBars.FromIndex; idx <= ChartBars.ToIndex; idx++)
            {
                if (idx - Displacement < 0 || idx - Displacement >= BarsArray[0].Count || (idx - Displacement < BarsRequiredToPlot))
                {
                    continue;
                }

                double valH = HAHigh.GetValueAt(idx);
                double valL = HALow.GetValueAt(idx);
                double valC = HAClose.GetValueAt(idx);
                double valO = HAOpen.GetValueAt(idx);
                int    x    = chartControl.GetXByBarIndex(chartControl.BarsArray[0], idx);
                int    y1   = chartScale.GetYByValue(valO);
                int    y2   = chartScale.GetYByValue(valH);
                int    y3   = chartScale.GetYByValue(valL);
                int    y4   = chartScale.GetYByValue(valC);

                SharpDX.Direct2D1.Brush shadowColordx = shadowColor.ToDxBrush(RenderTarget);                    // prepare for the color to use
                var xy2 = new Vector2(x, y2);
                var xy3 = new Vector2(x, y3);
                RenderTarget.DrawLine(xy2, xy3, shadowColordx, shadowWidth);

                if (y4 == y1)
                {
                    RenderTarget.DrawLine(new Vector2(x - barPaintWidth / 2, y1), new Vector2(x + barPaintWidth / 2, y1), shadowColordx, shadowWidth);
                }
                else
                {
                    if (y4 > y1)
                    {
                        SharpDX.Direct2D1.Brush barColorDowndx = barColorDown.ToDxBrush(RenderTarget);                           // prepare for the color to use
                        RenderTarget.FillRectangle(new RectangleF(x - barPaintWidth / 2, y1, barPaintWidth, y4 - y1), barColorDowndx);
                        barColorDowndx.Dispose();
                    }
                    else
                    {
                        SharpDX.Direct2D1.Brush barColorUpdx = barColorUp.ToDxBrush(RenderTarget);                             // prepare for the color to use
                        RenderTarget.FillRectangle(new RectangleF(x - barPaintWidth / 2, y4, barPaintWidth, y1 - y4), barColorUpdx);
                        barColorUpdx.Dispose();
                    }
                    RenderTarget.DrawRectangle(new RectangleF(x - barPaintWidth / 2 + (float)shadowWidth / 2,
                                                              Math.Min(y4, y1), barPaintWidth - (float)shadowWidth, Math.Abs(y4 - y1)), shadowColordx, shadowWidth);
                }
                shadowColordx.Dispose();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (CurrentBar < Period)
            {
                return;
            }
            if (Displacement + (CalculateOnBarClose ? 1 : 0) > 0 && CurrentBar > 0 && BarColorSeries[1] != Color.Transparent)
            {
                InitColorSeries();
            }
            BarColorSeries.Set(Math.Max(0, CurrentBar + Math.Max(0, Displacement) + (CalculateOnBarClose ? 1 : 0)), Color.Transparent);
            CandleOutlineColorSeries.Set(Math.Max(0, CurrentBar + Math.Max(0, Displacement) + (CalculateOnBarClose ? 1 : 0)), Color.Transparent);
            // Use this method for calculating your indicator values. Assign a value to each
            // plot below by replacing 'Close[0]' with your own formula.

            PlotEMA_H.Set(CurrentBar == 0 ? High[0] : High[0] * (2.0 / (1 + Period)) + (1 - (2.0 / (1 + Period))) * PlotEMA_H[1]);
            PlotEMT_C.Set(CurrentBar == 0 ? Close[0] : Close[0] * (2.0 / (1 + Period)) + (1 - (2.0 / (1 + Period))) * PlotEMT_C[1]);
            PlotEMA_L.Set(CurrentBar == 0 ? Low[0] : Low[0] * (2.0 / (1 + Period)) + (1 - (2.0 / (1 + Period))) * PlotEMA_L[1]);

            if (CurrentBar == 0)
            {
                HAOpen.Set(Open[0]);
                HAHigh.Set(High[0]);
                HALow.Set(Low[0]);
                HAClose.Set(Close[0]);
                return;
            }
            if (Close[0] > PlotEMA_H[0])
            {
                HAOpen.Set(Open[0]);
                HAHigh.Set(High[0]);
                HALow.Set(Low[0]);
                HAClose.Set(Close[0]);
            }
            //else if (Close[0] < PlotEMA_L[0])
            //{
            //    brushUp = brushRed;
            //    brushDown = brushMaroon;
            //    HAOpen.Set(Open[0]);
            //    HAHigh.Set(High[0]);
            //    HALow.Set(Low[0]);
            //    HAClose.Set(Close[0]);
            //}
            //else
            //{
            //    brushUp = brushLightSteelBlue;
            //    brushDown = brushSteelBlue;
            //    HAOpen.Set(Open[0]);
            //    HAHigh.Set(High[0]);
            //    HALow.Set(Low[0]);
            //    HAClose.Set(Close[0]);
            //}
        }
Esempio n. 4
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (CurrentBar == 0)
            {
                opens.Update();
                highs.Update();
                lows.Update();
                closes.Update();
                haopen  = Open[0];
                haclose = (High[0] + Low[0] + Close[0] + Open[0]) * 0.25;
                HAHigh.Set(High[0]);
                HALow.Set(Low[0]);
                HAMid.Set((HAHigh[0] + HALow[0]) * 0.5);
                return;
            }

            haopen  = (haopen + haclose) * 0.5;
            haclose = (highs[0] + lows[0] + opens[0] + closes[0]) * 0.25;
            if (haopen < haclose)
            {
                HAHigh.Set(Math.Max(haclose, highs[0]));
                HALow.Set(Math.Min(haopen, lows[0]));
            }
            else
            {
                HAHigh.Set(Math.Max(haopen, highs[0]));
                HALow.Set(Math.Min(haclose, lows[0]));
            }
            HAMid.Set((HAHigh[0] + HALow[0]) * 0.5);
            Color col;

            if (haopen != haclose)
            {
                isRising = (haopen < haclose);
            }
            if (isRising)
            {
                col = ((HALow[0] < haopen)?ltup:upcolor);
            }
            else
            {
                col = ((HAHigh[0] > haopen)?ltdn:dncolor);
            }

            PlotColors[0][0] = col;
            PlotColors[1][0] = col;
            PlotColors[2][0] = col;
        }
Esempio n. 5
0
        public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
        {
            base.Plot(graphics, bounds, min, max);

            if (Bars == null)
            {
                return;
            }

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

            int x, yHigh, yClose, yOpen, yLow;

            using (Pen drawPen = new Pen(Color.Transparent, ShadowWidth), HiLoPen = new Pen(hiloBarColor))
            {
                for (int index = firstBar; index <= lastBar; index++)
                {
                    if ((index <= lastcalcbar) && (index >= Math.Max(1, startbar)))
                    {
                        x      = ChartControl.GetXByBarIdx(BarsArray[0], index);
                        yHigh  = ChartControl.GetYByValue(this, HAHigh.Get(index));
                        yClose = ChartControl.GetYByValue(this, HAClose.Get(index));
                        yOpen  = ChartControl.GetYByValue(this, HAOpen.Get(index));
                        yLow   = ChartControl.GetYByValue(this, HALow.Get(index));

                        if (Direction.Get(index) > 0)
                        {
                            drawPen.Color = BarColorUp;
                        }
                        else if (Direction.Get(index) < 0)
                        {
                            drawPen.Color = BarColorDown;
                        }
                        else
                        {
                            drawPen.Color = BarColorWarn;
                        }

                        graphics.DrawLine(HiLoPen, x, yHigh, x, yLow);
                        graphics.DrawLine(drawPen, x, yOpen, x, yClose);
                    }
                }
            }
        }
Esempio n. 6
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 = HAHigh.Get(idx);
                double valL = HALow.Get(idx);
                double valC = HAClose.Get(idx);
                double valO = HAOpen.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
                {
                    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));
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            habars.update();
            HAMid.Set((habars.High + habars.Low) * 0.5);
            HAHigh.Set(habars.High);
            HALow.Set(habars.Low);
            Color col;

            if (habars.Open < habars.Close)
            {
                col = ((habars.Low < habars.Open)?ltup:upcolor);
            }
            else
            {
                col = ((habars.High > habars.Open)?ltdn:dncolor);
            }
            PlotColors[0][0] = col;
            PlotColors[1][0] = col;
            PlotColors[2][0] = col;
        }
Esempio n. 8
0
        protected override void OnTermination()
        {
            if (HAClose != null)
            {
                HAClose.Dispose();
            }

            if (HAOpen != null)
            {
                HAOpen.Dispose();
            }

            if (HAHigh != null)
            {
                HAHigh.Dispose();
            }

            if (HALow != null)
            {
                HALow.Dispose();
            }
        }
Esempio n. 9
0
        public override void GetMinMaxValues(ChartControl chartControl, ref double min, ref double max)
        {
            if (Bars == null || ChartControl == null)
            {
                return;
            }

            for (int idx = FirstBarIndexPainted; idx <= LastBarIndexPainted; idx++)
            {
                double tmpHigh = HAHigh.Get(idx);
                double tmpLow  = HALow.Get(idx);

                if (tmpHigh != 0 && tmpHigh > max)
                {
                    max = tmpHigh;
                }
                if (tmpLow != 0 && tmpLow < min)
                {
                    min = tmpLow;
                }
            }
        }
Esempio n. 10
0
        public override void OnCalculateMinMax()
        {
            base.OnCalculateMinMax();

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

            for (int idx = ChartBars.FromIndex; idx <= ChartBars.ToIndex; idx++)
            {
                double tmpHigh = HAHigh.GetValueAt(idx);
                double tmpLow  = HALow.GetValueAt(idx);

                if (tmpHigh != 0 && tmpHigh > MaxValue)
                {
                    MaxValue = tmpHigh;
                }
                if (tmpLow != 0 && tmpLow < MinValue)
                {
                    MinValue = tmpLow;
                }
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (Displacement + (CalculateOnBarClose ? 1 : 0) > 0 && CurrentBar > 0 && BarColorSeries[1] != Color.Transparent)
            {
                InitColorSeries();
            }

            BarColorSeries.Set(Math.Max(0, CurrentBar + Math.Max(0, Displacement) + (CalculateOnBarClose ? 1 : 0)), Color.Transparent);
            CandleOutlineColorSeries.Set(Math.Max(0, CurrentBar + Math.Max(0, Displacement) + (CalculateOnBarClose ? 1 : 0)), Color.Transparent);

            if (CurrentBar == 0)
            {
                HAOpen.Set(Open[0]);
                HAHigh.Set(High[0]);
                HALow.Set(Low[0]);
                HAClose.Set(Close[0]);
                return;
            }

            HAClose.Set((Open[0] + High[0] + Low[0] + Close[0]) * 0.25); // Calculate the close
            HAOpen.Set((HAOpen[1] + HAClose[1]) * 0.5);                  // Calculate the open
            HAHigh.Set(Math.Max(High[0], HAOpen[0]));                    // Calculate the high
            HALow.Set(Math.Min(Low[0], HAOpen[0]));                      // Calculate the low
        }
Esempio n. 12
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (!initialized)
            {
                if (ChartControl != null && saveDownColor == Color.Empty && ChartControl.ChartStyle.DownColor != Color.Transparent)
                {
                    saveDownColor = ChartControl.ChartStyle.DownColor;
                    saveUpColor   = ChartControl.ChartStyle.UpColor;
//					savePen			= ChartControl.ChartStyle.Pen;

                    // Use the defined chart colors
                    barColorDown = ChartControl.ChartStyle.DownColor;
                    barColorUp   = ChartControl.ChartStyle.UpColor;

                    // make normal bars invisible
                    ChartControl.ChartStyle.DownColor = Color.Transparent;
                    ChartControl.ChartStyle.UpColor   = Color.Transparent;
                    ChartControl.ChartStyle.Pen.Color = Color.Transparent;
                    //ChartControl.ChartStyle.Pen			= new Pen(Color.Transparent);
                }
                initialized = true;
            }

            if (CurrentBar == 0)
            {
                HAOpen.Set(0);
                HAHigh.Set(0);
                HALow.Set(0);
                HAClose.Set(0);
                return;
            }

            // Draw HeikenAshi bars as specified by user

            int lastBar  = Math.Min(ChartControl.LastBarPainted, Bars.Count - 1);
            int firstBar = (lastBar - ChartControl.BarsPainted) + 1;

            switch (PaintStyle)
            {
            case PaintingStyle.PaintVisibleOnly:
                if (CurrentBar <= firstBar + 2)
                {
                    return;
                }
                if (CurrentBar >= lastBar + 1)
                {
                    return;
                }
                break;

            case PaintingStyle.PaintToLast:
                if (CurrentBar <= firstBar + 2)
                {
                    return;
                }
                break;

            case PaintingStyle.PaintAll:
//
//					break;
//
            default:

                break;
            }

            HAClose.Set((HMA(Open, smoothingPeriod)[0] + HMA(High, smoothingPeriod)[0] + HMA(Low, smoothingPeriod)[0] + HMA(Close, smoothingPeriod)[0]) / 4); // Calculate the close
            HAOpen.Set((HMA(HAOpen, smoothingPeriod)[1] + HMA(HAClose, smoothingPeriod)[1]) / 2);                                                             // Calculate the open
            HAHigh.Set(Math.Max(HMA(High, smoothingPeriod)[0], HMA(HAOpen, smoothingPeriod)[0]));                                                             // Calculate the high
            HALow.Set(Math.Min(HMA(Low, smoothingPeriod)[0], HMA(HAOpen, smoothingPeriod)[0]));                                                               // Calculate the low

            Color barColor    = (HAClose[0] > HAOpen[0] ? BarColorUp : BarColorDown);
            Color ShadowColor = (Close[0] > Open[0] ? BarColorUp : BarColorDown);

            int BodyWidth = Math.Max(ChartControl.BarWidth + 2, ChartControl.BarSpace - 3);

            DrawLine(CurrentBar.ToString(), false, 0, HAHigh[0], 0, HALow[0], ShadowColor, DashStyle.Solid, ShadowWidth);
            DrawLine(CurrentBar.ToString() + "OC", false, 0, HAOpen[0], 0, HAClose[0], barColor, DashStyle.Solid, BodyWidth);
        }
Esempio n. 13
0
        protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
        {
            base.OnRender(chartControl, chartScale);

            BodyWidth = (int)ChartControl.BarWidth + Math.Min(ShadowWidth * 2, 4);
            if (ChartBars != null)
            {
                // loop through all of the viewable range of the chart
                for (int barIndex = ChartBars.FromIndex; barIndex <= ChartBars.ToIndex; barIndex++)
                {
                    if (ShadowColor == Brushes.Transparent)
                    {
                        if (Close.GetValueAt(barIndex) > Open.GetValueAt(barIndex))
                        {
                            DrawLineNT("BarBrushUp",
                                       barIndex,
                                       HAHigh.GetValueAt(barIndex),
                                       barIndex,
                                       Math.Max(HAClose.GetValueAt(barIndex), HAOpen.GetValueAt(barIndex)),
                                       ShadowWidth,
                                       chartScale);

                            DrawLineNT("BarBrushUp",
                                       barIndex,
                                       HALow.GetValueAt(barIndex),
                                       barIndex,
                                       Math.Min(HAClose.GetValueAt(barIndex), HAOpen.GetValueAt(barIndex)),
                                       ShadowWidth,
                                       chartScale);
                        }
                        else
                        {
                            DrawLineNT("BarBrushDown",
                                       barIndex,
                                       HAHigh.GetValueAt(barIndex),
                                       barIndex,
                                       Math.Max(HAClose.GetValueAt(barIndex), HAOpen.GetValueAt(barIndex)),
                                       ShadowWidth,
                                       chartScale);

                            DrawLineNT("BarBrushDown",
                                       barIndex,
                                       HALow.GetValueAt(barIndex),
                                       barIndex,
                                       Math.Min(HAClose.GetValueAt(barIndex), HAOpen.GetValueAt(barIndex)),
                                       ShadowWidth,
                                       chartScale);
                        }
                    }
                    else
                    {
                        DrawLineNT("ShadowBrush",
                                   barIndex,
                                   HAHigh.GetValueAt(barIndex),
                                   barIndex,
                                   Math.Max(HAClose.GetValueAt(barIndex), HAOpen.GetValueAt(ShadowWidth)),
                                   ShadowWidth,
                                   chartScale);

                        DrawLineNT("ShadowBrush",
                                   barIndex,
                                   HALow.GetValueAt(barIndex),
                                   barIndex,
                                   Math.Min(HAClose.GetValueAt(barIndex), HAOpen.GetValueAt(ShadowWidth)),
                                   ShadowWidth,
                                   chartScale);
                    }

                    if (HAClose.GetValueAt(barIndex) > HAOpen.GetValueAt(barIndex))
                    {
                        DrawLineNT("BarBrushUp",
                                   barIndex,
                                   HAOpen.GetValueAt(barIndex),
                                   barIndex,
                                   HAClose.GetValueAt(barIndex),
                                   BodyWidth,
                                   chartScale);
                    }
                    else
                    {
                        DrawLineNT("BarBrushDown",
                                   barIndex,
                                   HAOpen.GetValueAt(barIndex),
                                   barIndex,
                                   HAClose.GetValueAt(barIndex),
                                   BodyWidth,
                                   chartScale);
                    }
                }
                // Draw price line if wanted

                if (ShowPriceLine)
                {
                    DrawLineNT("PriceLineBrush",
                               Math.Max(PriceLineLength, CurrentBar - 15),
                               Close.GetValueAt(CurrentBar),
                               CurrentBar,
                               Close.GetValueAt(CurrentBar),
                               PriceLineWidth,
                               PriceLineStyle,
                               chartScale);

                    DrawStringNT("  -- " + Close.GetValueAt(CurrentBar).ToString() + " = Last Price",
                                 Font,
                                 "PriceTextBrush",
                                 CurrentBar,
                                 Close.GetValueAt(CurrentBar),
                                 "PriceAreaBrush",
                                 chartScale);
                }
            }
        }