I'm having trouble identifying which user-drawn rectangles are attached to the visible chart and which are attached to other instrument / time frames.
Either I do not understand the correct usage (likely) or there is unexpected behaviour.
The attached indicator tries to identify rectangles drawn on the visible instrument / time frame with this code in OnBarUpdate():
[SIZE=2] if ( drawObj.AttachedTo.AttachedToType == AttachedToType.Bars ) // attached to the chart Bars
{
ChartBars attachedToChartBars = (ChartBars)(drawObj.AttachedTo.ChartObject);
if ( Bars.Instrument == attachedToChartBars.Bars.Instrument // the visible instrument
&& Bars.BarsPeriod == attachedToChartBars.Bars.BarsPeriod // the period
&& drawObj is Rectangle && drawObj.IsUserDrawn ) // user-drawn rectangle
{
Rectangle rect = drawObj as Rectangle;
Print( "Doing some stuff with " + drawObj.Tag );
}
}[/SIZE]
In a workspace with 1 chart (e.g. 1 min EURUSD) and the Ninjascript output window...
Add the attached indicator. At the new bar it should output DrawObjects.Count.
Draw a rectangle. At the next new bar it outputs rectangle info.
Change instrument. At the next new bar it shows the same rectangle attached the new instrument.
Is this expected behaviour?
How else do I identify which rectangles do not belong on the visible chart, so I can avoid working with them?
Cheers
Tony

Comment