/// <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]); //} }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (CurrentBar == 0) { HAOpen.Set(Open[0]); HAClose.Set((High[0] + Low[0] + Close[0] + Open[0]) * 0.25); return; } HAClose.Set((High[0] + Low[0] + Close[0] + Open[0]) * 0.25); // Calculate the close HAOpen.Set((HAOpen[1] + HAClose[1]) * 0.5); // Calculate the open }
/// <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 }
/// <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); }