PDA

View Full Version : get value from IDrawObject


e-man
06-23-2010, 08:15 AM
saw this snip from Josh a while back ... references some new functionality in NT7 ... curious to know if this made it into the features and how one can read the current value of a draw object:

NT7 will have some enhancements:
"
Draw Objects Enhancements
Draw objects are now associated to an indicator which means that if a user removes a draw object from the chart, it will also remove the indicator. In addition, all draw objects spawned from an indicator share the indicator's z-order.
IDrawObject - IDrawObjects are now returned to the caller on all Draw() methods. IDrawObjects expose draw objects properties.
Work in progress - We will implement programmatic access to draw objects added to a chart manually. For example, you can have a user draw a line on a chart and add a "tag" to this object and you can retrieve this object, read it's value and do something with it."cf. http://www.ninjatrader.com/support/forum/showpost.php?p=107927&postcount=5

cheers,
-e

NinjaTrader_Tim
06-23-2010, 09:19 AM
Hi e-man,

Yes, you can access these using "IDrawObject"
More info at - http://www.ninjatrader.com/support/helpGuides/nt7/index.html?idrawobject.htm

For a line, you can access "Iline"
More info at - http://www.ninjatrader.com/support/helpGuides/nt7/index.html?iline.htm

e-man
06-23-2010, 10:30 AM
Hi Tim,

thanks for the link -- not seeing a signature to pull the current value. is that supported?

i have drawn a horizontal line and unlocked it so it can be moved around by user. next step is to programatically read the new value. does that make sense?

cheers,
-e

NinjaTrader_Tim
06-23-2010, 11:00 AM
Hi e-man,

Can you perhaps use IHorizontalLine for that - http://www.ninjatrader.com/support/helpGuides/nt7/index.html?ihorizontalline.htm

If not, please clarify what you are trying to do.

e-man
06-23-2010, 11:39 AM
fantastic -- that did the trick.

just in case anyone else needs the code, the following filters out user-drawn lines and resync's system-drawn values to local variables:

foreach (IDrawObject draw in DrawObjects)
{
if (!draw.UserDrawn && draw.DrawType == DrawType.HorizontalLine)
{
IHorizontalLine hline = (IHorizontalLine)draw;
double nBand = hline.Y;

switch (draw.Tag)
{
case "line1_name":
_Line1_local_var = nBand;
break;

case "line2_name":
_Line2_local_var = nBand;
break;

// repeat for each additional line

default:
break;
}
}
}
this assumes that the lines are "unlocked" ... i adapted this code from the user-guide and call this one time when CurrentBar == 0:
foreach (IDrawObject draw in DrawObjects)
{
if (!draw.UserDrawn && draw.DrawType == DrawType.HorizontalLine && draw.Locked)
{
draw.Locked = false;
}
}
cheers,
-e

NinjaTrader_Tim
06-23-2010, 11:59 AM
Hi e-man,

Nicely implemented, and thank you for posting!