I have a question concerning an indicator with custom drawings using the IChartCustomDrawer interface. Everything works as expected except when I set the indicator status to "off" in the "Format Objects" dialog under the "Studies" tab the custom rendered text that I add to the chart still stays on the chart and is not cleared as expected.
I've looked through pretty much everything and I can not find a flag that would be connected to the "Status" of the indicator. In general I would think if there is no such flag that MC would re-render the chart and just not call the rendering routine of my indicator but that is not the case. When I put a break point in the IChartCustomDrawer.Draw method it is still called when the status is toggled to the "off" state and the text still appears on the chart.
Does anybody know how I'd go about checking the status of the indicator object? Here's my code for the IChartCustomDrawer.Draw just for reference:
Code: Select all
void IChartCustomDrawer.Draw(DrawContext context, EDrawPhases phase) {
//we only render text at the final drawing phase
//TBD: I'd have to check some status flag in the condition below to ensure I don't render the custom text on the chart.
if (phase == EDrawPhases.Final) {
Font textFont = new Font("Arial", TextFontSize, FontStyle.Regular);
StringFormat textFormat = new StringFormat(StringFormatFlags.DirectionVertical | StringFormatFlags.NoWrap);
Brush textBrush = new SolidBrush(TextColor);
//determine the location for the text in the window client area and render the text if it
//overlaps with the dirty rectangle area to be updated
for (int index = 0; index < barTexts.Count; index++) {
BarText barText = barTexts.Values[index];
if (barText.text != "") {
//update the location of the text in the window client area
ChartPoint startChartPoint = new ChartPoint(barText.timestamp, barText.low);
PointF startPoint = context.Environment.ChartPoint2Point(startChartPoint);
SizeF textSize = context.graphics.MeasureString(barText.text, textFont);
startPoint.X -= textSize.Height / 2;
barText.location.X = startPoint.X;
barText.location.Y = startPoint.Y;
//NOTE: We render the text vertically so the width and height is swapped
barText.location.Height = textSize.Width;
barText.location.Width = textSize.Height;
//render the text if it overlaps the dirty rectangle
if (context.DirtyRect.IntersectsWith(barText.location)) context.graphics.DrawString(barText.text, textFont, textBrush, barText.location, textFormat);
}
}
}
}
Cheers