예제 #1
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]);
            //}
        }
예제 #2
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;
        }
예제 #3
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;
        }
예제 #4
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
        }
예제 #5
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);
        }