PDA

View Full Version : Remove Drawn Objects


MAX
09-14-2007, 04:42 AM
Hi,

is there a way (by code) to remove all drawn objects (drawn by an indicator) once that the same indicator has been removed from the chart?

Thanks.

NinjaTrader_Dierk
09-14-2007, 05:38 AM
As you remove an indicators from a chart all drawing objects drawn by the indicator are removed.

MAX
09-16-2007, 10:01 AM
I tried to draw a rectangle on chart by a coded indicator but when I removed the indicator, the rectangle drawn was still there. I had to remove it manually.
Maybe there is some particular code string to add?

Thanks.

NinjaTrader_Dierk
09-16-2007, 11:45 PM
I just double checked by attached simple indicator and it works as expected:
protected override void OnBarUpdate()
{
Plot0.Set(Close[0]);
if (CurrentBar < 10)
return;
DrawRectangle("tag", 10, Close[10], 0, Close[10] - 10 * TickSize, Color.Blue);
}Please post your complete indicator if you experience something different.

Also: Please make sure you are on latest 6.0.1000.5

MAX
09-22-2007, 09:23 AM
I tried with your example and it does work, nevertheless using my code, the drawn rectangle remains on chart when the indicator is off.
Let's say I've got an Input in the indicator. When the Input has the value of NPat (5 in the case below) then a rectangle is drawn and the tb assumes a value of 1.
Everything works perfectly except that when I remove the Indicator the rectangle remains on chart.
I'm sure I'm missing something, but I don't know what..

================================================== ====
protected override void OnBarUpdate()
{
if (Open[0] < Low[1])
{
NPat = 5;
}
else
NPat = 0;
{


if (NPat == Input)
{
tb = 1;

DrawRectangle(CurrentBar.ToString(), 0, Math.Min(Low[0],Low[1]) - TickSize, 1, Math.Max(High[0],High[1]) + TickSize, Color.Gold, Color.Gold, 3);
}
else
{
tb = 0;
}


Plot0.Set(tb);

NinjaTrader_Josh
09-23-2007, 12:59 AM
I copied your code snippet and modified it slightly to allow it to compile. It works as expected. Removal of rectangle happens automatically. Please try the attached indicator and see if it works for you. If it still doesn't work perhaps your install/.NET got messed up somehow and I advise you to do a reinstall.

MAX
09-23-2007, 05:18 AM
Thanks Josh, nevertheless the trouble could be in this line of code:

if (NPat == 5)

My goal is: if NPat is equal to my Input (that, in this case, I insert with a value of 5) then draw a rectangle. If my input value is different from 5 the indicator does not draw anything.

Hope this is more clear.

Thanks.

NinjaTrader_Josh
09-23-2007, 10:07 AM
Okay MAX. The potential problem I see with using "Input" is because Input is generally already defined as an IDataSeries. When you go NPat == Input you are comparing an int to an IDataSeries which causes compile error. Take a look at the attached file. It replaces "Input" with "UserInput" and is a user definable value. It works in adding and removing the rectangles as expected on my end.

MAX
09-24-2007, 11:20 AM
Thanks Josh, but my goal is to allow the user to choose the value. If I put the input as internal variable this is not possible, because nothing is shown on the indicator as Input.

MAX
09-24-2007, 12:01 PM
Josh I tried your indicator but I have an error.

MAX
09-24-2007, 12:24 PM
Yes it works. Thanks very much Josh.

NinjaTrader_Josh
09-24-2007, 05:13 PM
Glad you got it working. If you have any more questions feel free to ask.