Function that will delete horizontal lines in a specific chart.

 

Hello every one. It is possible that an EA will detect Horizontal Lines on a specific chart and will delete it? Because I am trying to develop an EA that will open a buy position if the price crosses above the horizontal line and will sell if the price crosses below the horizontal line. If the profit is greater than to the target..the EA will close all the open positions and WILL DELETE THE HORIZONTAL LINES in that specific chart. 

I tried using the DeleteAll script but it will delete all the object in all the charts that has an objects in it. I hope someone can help me. God Bless you all and Pips be with you always.

 

https://www.mql5.com/en/docs/objects/objectdelete


But you have to know beforehand the Chart ID, AND, the string name of the object to delete it...


;)

Documentation on MQL5: Object Functions / ObjectDelete
Documentation on MQL5: Object Functions / ObjectDelete
  • www.mql5.com
An asynchronous call is always used for ObjectDelete(), that is why the function only returns the results of adding the command to a chart queue. In this case, true only means that the command has been successfully enqueued, but the result of its execution is unknown. To check the command execution result, you can use the ObjectFind() function...
 

Use a prefix so that only and all lines starting with that prefix are removed the function for this is:

ObjectsDeleteAll();
Notice it's slightly different than ObjectDelete();
 
Marco vd Heijden:

Use a prefix so that only and all lines starting with that prefix are removed the function for this is:

Notice it's slightly different than ObjectDelete();

Just to add to that

Declared globally and used when naming and drawing objects

string prefix = "My Prefix";
ObjectsDeleteAll(0,Prefix);

will delete all objects with that prefix but only on the same chart that the EA is attached to. The first parameter is 0 which means the current chart.

You will have to figure a way to get the ChartID for the relevant chart.

 

Thank you very to all of you. May God Bless you all for your generosity to me. 

ObjectsDeleteAll(0,OBJ_HLINE) is working...

 
Nieco Pama:

Thank you very to all of you. May God Bless you all for your generosity to me. 

ObjectsDeleteAll(0,OBJ_HLINE) is working...

Yes but that is incorrect use of the Function:

int  ObjectsDeleteAll( 
   long  chart_id,           // chart identifier 
   int   sub_window=-1,      // window index 
   int   type=-1             // object type 
   );

Removes all objects of the specified type using prefix in object names.

int  ObjectsDeleteAll( 
   long           chart_id,   // chart ID 
   const string     prefix,   // prefix in object name 
   int       sub_window=-1,   // window index 
   int      object_type=-1    // object type 
   );

If you want to delete all hlines:

ObjectsDeleteAll(0,-1,OBJ_HLINE);

parameter 1 = chart ID

parameter 2 = window index, 0 means the main chart window, -1 means all the subwindows of the chart, including the main window.

parameter 3 = Object Type 

 
Marco vd Heijden:

Yes but that is incorrect use of the Function:

If you want to delete all hlines:

parameter 1 = chart ID

parameter 2 = window index, 0 means the main chart window, -1 means all the subwindows of the chart, including the main window.

parameter 3 = Object Type 

Thank you sir for the ideas.. anyway i am doing trial and error regarding with this. I dont make it a function. I only attached it in another function that returns the total profit of all the open position in a current chart. I try it 

if (Profit >= Target) CloseAll;
if (Profit >= Target) ObjectsDeleteAll (0,OBJ_HLINE); 

Anyway, i will try it in a demo and i open my ea in several currency pair so that i may iknow it it is working or not. I tried it in a tester and it is working but i dont know if it is still working in a multiple currency. 

God Bless you. 
 
Objects are usually for the chart instrument only, unless you design an specific interface that is coded to present more data.
 
Marco vd Heijden:
Objects are usually for the chart instrument only, unless you design an specific interface that is coded to present more data.
I try to use it in a demo acct but it didnt work. If i try it in tester it works. Anyway, i must have to look for another alternative for this. If the horizontal lines will not be deleted then i must have another function to make my EA sleep after closing a trades or as long as i cant find the solution i will use only one currency so that it wil be safe. If this works in a tester then it will work in a single currency only. So i need to look for a currency with a good set up for the S/R to open my ea...
 

The solution is usually elegant and simple.

I am not exactly sure what you are trying to do because you did not post the relevant code.

 
Marco vd Heijden:

The solution is usually elegant and simple.

I am not exactly sure what you are trying to do because you did not post the relevant code.

Sorry but i am using now an android phone. 

My EA strategy is this:

lotsize;
target;

Manually i put two horizontal lines. The S/R. 
If the price cross above the upper horizontal lines, the EA will open buy order. 
If the price cross the lower horizontal line, the EA will open a sell order. 

If the profit is greater than target, the EA will close the open trades and will delete the horizontal lines on the current chart. I also make that ea EA sleep if there is no horizontal lines in the current chart. 

Sometimes the market id fluctuating. The next problem on me now is, if there an open buy order, then the market moves sideways, i need to make it open a sell if it cross below the lower horizontal line. 

Theis means if open order 1= buy..the next will be open order 2 must a sell...then open order3 must a buy. 

Sometimes it happens that open order1 = buy..then open order 2 = buy and so on.. because the market runs sideways.. i hope i can solve this also.... 

I think i must make another rule to do that...
if the last order is a buy..then the next will be a sell...and vice versa. Im very sorry because i am not a programmer..i just started reading mql4 manual two months ago. As of now i am not expert in making tricks with the operators and some conditions. But i am still hoping that i can make this perfectly according to what is in my mind.. 

THANK YOU VERY MUCH AND GOD BLESS YOU...