I use my indicator on 1 min chart.
1. I got blink effect of drawed rectangles on chart. Suppose this is because I filter 1 tick period in Plot(). But I dont need draw indicator for 1tick Bars on chart. And without filter I got error "Index out of range".
How can I get Bars object for main period of chart?
2. Why ChartControl.BarWidth is smaller than actual candle width on chart? Where is true width of a candle?
// AggressiveTradeDraw class
public void Draw(Graphics graphics)
{
int barWidth = indicator.ChartControl.BarWidth + 4;
int x0 = indicator.ChartControl.GetXByBarIdx(indicator.Bars, AggressiveTrade.StartBarIdx) - barWidth / 2;
int x1 = indicator.ChartControl.GetXByBarIdx(indicator.Bars, AggressiveTrade.StopBarIdx) + barWidth / 2;
int y0 = indicator.ChartControl.GetYByValue(indicator.Bars, AggressiveTrade.StartPrice);
int y1 = indicator.ChartControl.GetYByValue(indicator.Bars, AggressiveTrade.StopPrice);
int h = Math.Abs(y0 - y1);
y0 = Math.Min(y0, y1);
graphics.FillRectangle(brush, x0, y0, x1 - x0, h);
}
protected override void Initialize()
{
Add(PeriodType.Tick, 1);
CalculateOnBarClose = false;
Overlay = true;
//LogLevel = 3;
}
public override void Plot( Graphics graphics, Rectangle bounds, double min, double max)
{
//base.Plot(graphics, bounds, min, max);
if (BarsInProgress == 0)
{
SmoothingMode oldSmoothingMode = graphics.SmoothingMode;
graphics.SmoothingMode = SmoothingMode.AntiAlias;
foreach (AggressiveTradeDraw d in aggressiveTradeDraw)
{
#if DEBUG
//WinLog(3, "mzAggressiveTrade", d.AggressiveTrade.ToString());
#endif
d.Draw(graphics);
}
graphics.SmoothingMode = oldSmoothingMode;
}
}

Comment