ObjectCreate - VLine help

 
I want to use the ObjectCreate feature to create a vertical line when certain parameters occur. I also want the old line to be deleted each time a new line is created.

I know I have to use ObjectCreate, but I don't fully understand how to use it. I would really appreciate it if someone could post the code for something simple like, "If EMA1 crosses EMA2, draw a vertical line at the bar of the cross". Also, how do you delete the old line when a new cross occurs.

If I had that code I know that I'd be able to modify it to fit more complex parameters.

Thanks to anybody that can help.
 
Hello!

To delete the old line, use ObjectDelete("somename"); I have not worked with objects myself, but found a bit of code in an indicator I recently downloaded.

        datetime T1,T2;
        int B1, B2;  // bar index on the chart (the bar# you'd use to access the bar).
        double PP, PP2; // price values
...

        T1=Time[B1]; T2=Time[B2];
	ObjectCreate("TL1",OBJ_TREND,0,T2,PP2,T1,PP); 
		ObjectSet("TL1",OBJPROP_COLOR,Lime); 
		ObjectSet("TL1",OBJPROP_WIDTH,2); 
		ObjectSet("TL1",OBJPROP_STYLE,STYLE_SOLID); 



This snippet practically creates a line with the name TL1 from B1/PP to B2/PP2.
If you do an ObjectDelete("TL1"); before that and then create it for new.

Or use an ObjectFind() to find your existing line and use ObjectSet() to modify the points and prices there.


Hope this helps.


Markus


Reason: