API Support Forum
OEC API > API Support > Custom Indicator Question
Author Topic: Custom Indicator Question
(3 messages, Page 1 of 1)
Moderators: VPfau
SThompson30
Posts: 20
Joined: Jan 09, 2008


Posted: Oct 08, 2009 @ 11:52 AM             Msg. 1 of 3
Hello,

I asked OEC Support but they suggested I ask here:

I am trying to figure out how to place a label on a chart, in a C#
indicator, such that it stays in the same place all the time.

In particular, I want to display the date in the upper left corner,
near the contract symbol name, for example. So, when the user scrolls the chart, I want to see the date in the upper left.

Any suggestions? Victor? :-)

Thanks,

-Scott
VictorV
Posts: 746
Joined: May 08, 2007


Posted: Oct 12, 2009 @ 01:57 PM             Msg. 2 of 3
Hello,

please try to use the next code inside your indicator:

bool hooked = false;

protected override void Calculate()
{
if (!hooked)
{
hooked = true;
MainSeries.AssignedArea.Chart.CustomPaint += OnCustomPaintEvent;
}
}

void OnCustomPaintEvent(object sender, CustomPaintArgs e)
{
if (Visible && e.Stage == PaintStage.PostGrid && e.Area == MainSeries.AssignedArea)
{
using (SolidBrush brush = new SolidBrush(Color))
{
e.Graphics.DrawString(
DateTime.Today.ToShortDateString(),
AreaProfile.Profile.GridAxisFont,
brush,
new PointF(4 + e.Graphics.MeasureString(e.Area.Name, AreaProfile.Profile.GridAxisFont).Width, 3));
}
}
}


public override void Delete()
{
if (hooked)
{
MainSeries.AssignedArea.Chart.CustomPaint -= OnCustomPaintEvent;
hooked = false;
}
base.Delete();
}

This sample code will be available in the next release of Chart Package.
SThompson30
Posts: 20
Joined: Jan 09, 2008


Posted: Oct 12, 2009 @ 02:42 PM             Msg. 3 of 3
Fantastic!

Thanks Victor, that is great. Somehow I knew you would know what to do!

Have a great week,

-Scott