Delete an object from only 1 of the open pairs, not all of them...

 

Hey all,

I use my EA to draw a line called "Trigger" on the chart upon the first tick which I then move to a support/resistance area i want to wait for a signal from to take a trade, I have then also programmed it to delete this line when the EA takes a trade to avoid opening multiple trades for the same signal. 

The issue is that I have multiple pairs open in multiple windows and it deletes the trigger line from all of the windows, not just the window with the pair that has an open trade. If I were to change  {ObjectDelete(0,"Trigger"); to   {ObjectDelete(Symbol(),"Trigger");  is that how I make it only delete the line in the chart with the trade? 

Or would I have to say, find an open trade, find the symbol that trade is on, delete the line from that symbol?

Thanks for any help, been scratching my head on this for a while an google isn't helping much..

int new_HLine()
{
int i,a;
int total = OrdersTotal();
string comentario,par;
for (i=total-1; i >=-1; i--)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if (OrderType()==OP_BUY || OrderType()==OP_SELL)
{
for (a=total-1; a >=-1; a--)
{
ObjectCreate("Trigger", OBJ_HLINE,0, Time[0], Bid, 0, 0); 
}
//delete the line
for (i=total-1; i >=0; i--)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if (OrderType()==OP_BUY || OrderType()==OP_SELL)
{
for (a=total-1; a >=0; a--)
{ObjectDelete(0,"Trigger"); 
}
}}
}return(1);}
return(1);}
 
  1. Why did you post your MT4 question in the Root / MT5 EA section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. Jowin6789:

    The issue is that I have multiple pairs open in multiple windows and it deletes the trigger line from all of the windows, not just the window with the pair that has an open trade. If I were to change  {ObjectDelete(0,"Trigger"); to   {ObjectDelete(Symbol(),"Trigger");  is that how I make it only delete the line in the chart with the trade?

    Perhaps you should read the manual.
              ObjectDelete - Object Functions - MQL4 Reference
    ObjectDelete(0,"Trigger") or just ObjectDelete("Trigger")
    The function removes the object with the specified name at the specified chart.
    and ObjectDelete(Symbol(),"Trigger") would not compile. So it does not "deletes the trigger line from all of the windows, not just the window with the pair that has an open trade." Your problem is elsewhere.

  3. Jowin6789: Or would I have to say, find an open trade, find the symbol that trade is on, delete the line from that symbol?
    Lines are not on symbols, lines are on charts.

  4. int total = OrdersTotal();
    for (i=total-1; i >=-1; i--){
        OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
        if (OrderType()==OP_BUY || OrderType()==OP_SELL)
    Check your return codes for errors and report them.
              What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  5. Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 and MetaTrader 4 - MQL4 programming forum

  6. for (a=total-1; a >=-1; a--){
    ObjectCreate("Trigger", OBJ_HLINE,0, Time[0], Bid, 0, 0);
    What is the point creating the same object multiple times?

  7. for (a=total-1; a >=0; a--)
    {ObjectDelete(0,"Trigger"); 
    }
    What is the point of deleting the same object multiple times?

 
whroeder1:
  1. Why did you post your MT4 question in the Root / MT5 EA section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. Perhaps you should read the manual.
              ObjectDelete - Object Functions - MQL4 Reference
    ObjectDelete(0,"Trigger") or just ObjectDelete("Trigger")
    and ObjectDelete(Symbol(),"Trigger") would not compile. So it does not "deletes the trigger line from all of the windows, not just the window with the pair that has an open trade." Your problem is elsewhere.

  3. Lines are not on symbols, lines are on charts.

  4. Check your return codes for errors and report them.
              What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  5. Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 and MetaTrader 4 - MQL4 programming forum

  6. What is the point creating the same object multiple times?

  7. What is the point of deleting the same object multiple times?

Thanks for your response!

1. didn't know there was such a section, i'll do that in the future.

2. i read the manual section for object delete but I'm not sure how to use the simple two parameter delete function to get what i want it to do?

3. noted!

4. will read through these, i've not used return codes for errors before,

5. I see what you mean, it will count orders on all charts that are open currently right? Need to change the magic number when i add the same EA to a new chart or write the EA to do this when added to a chart..

6. & 7. What I'm doing is looking for a pin bar at a support or resistance line, i don't like the automatic support resistance line indicators/EA's I have researched as they put lines where i would not. I therefore get the EA to draw me a line when I add it to the chart, I then move this line to the support or resistance level that i want to look out for a trade at, I then write a double to get the OBJPROP_PRICE and write this into my if() function that identifies the pin bar, i.e. low[1] < Trigger, close[1] > Trigger.

I delete the line once a trade is opened to avoid opening multiple trades on the same chart and the same time, then when there is no trade open it re draws the Trigger line..


So, to get it to do what I want it to do, am i right in thinking:

  1. in order to get the EA to count the number of trades on one chart, I need to change the magic number of the EA every chart I add it to, get it to look for trades just on each chart individually,
  2. and in order to get it to delete the line from the chart with an open trades only i need to identify the chart in the object delete function - however if i don't know which chart will have a trade how can I? Would i possible get it to search for an open trade of the magic number i set, then get the chart ID that trade is on, then enter that into the object delete function?

 
Jowin6789:

1. didn't know there was such a section, i'll do that in the future.

2. i read the manual section for object delete but I'm not sure how to use the simple two parameter delete function to get what i want it to do?

3.

4. will read through these, i've not used return codes for errors before,

5. I see what you mean, it will count orders on all charts that are open currently right? Need to change the magic number when i add the same EA to a new chart or write the EA to do this when added to a chart..

6. & 7.

  1. in order to get the EA to count the number of trades on one chart, I need to change the magic number of the EA every chart I add it to, get it to look for trades just on each chart individually,
  2. and in order to get it to delete the line from the chart with an open trades only i need to identify the chart in the object delete function - however if i don't know which chart will have a trade how can I? Would i possible get it to search for an open trade of the magic number i set, then get the chart ID that trade is on, then enter that into the object delete function?

  1. Then how can you code anything?
  2. You want it to not delete "from all of the windows." That is what it does.

  3. Then how can you code anything?
  4. Had you read the link provided at #2.5 You would know the choices are A) different MN for each chart, B) same MN and also filter by chart symbol, or C) computed range of MNs and symbol, for multiple TFs per symbol.
  1. #5 above
  2. No need for any of that. You have the code is running on all charts. If it finds an open order for it's symbol (wether it opened it or not) delete the line on its chart.
 
whroeder1:
  1. Then how can you code anything?
  2. You want it to not delete "from all of the windows." That is what it does.

  3. Then how can you code anything?
  4. Had you read the link provided at #2.5 You would know the choices are A) different MN for each chart, B) same MN and also filter by chart symbol, or C) computed range of MNs and symbol, for multiple TFs per symbol.
  1. #5 above
  2. No need for any of that. You have the code is running on all charts. If it finds an open order for it's symbol (wether it opened it or not) delete the line on its chart.

1. trial and error, i've never done this before this is my first EA

2. okay thanks

3.

4. trial and error,

5. change the magic number it is then!


thanks for the help. by the way i was wondering, you often seem to be the one giving people answers when they're stuck. Are you employed to do all of this or is it just for 'fun'?


Much appreciated either way.

 
This is a user's forum not Metaquotes. No employees here, only volunteers.
 
whroeder1:
This is a user's forum not Metaquotes. No employees here, only volunteers.

You need to stop calling this a "user's forum". MQL5.com is not a user's forum, it is a Metaquotes owned and operated forum. Metaquotes employees will occasionally participate in the threads, but it's very rare.  

 
nicholishen: You need to stop calling this a "user's forum". MQL5.com is not a user's forum, it is a Metaquotes owned and operated forum.

MQL5.com is not a user's forum, it's not a forum at all. Mql5.com/<language>/forum is. You are not a Metaquotes employee, you are a Metatrader user. Therefor this is a user's forum.

The Service Desk, is not a user's forum. There are no users answering questions there. Only Metaquotes employees. That is not a user's forum.

Don't be a troll.

 

So i've tried changing the magic number by clicking the smiley face and change it in there, but this doesn't seem to work. The EA is still treating all charts the same. I do have the following written at the beginning of the EA:


extern int     magic             = 962231;


should I not be doing this if I want each chart to have a different magic number?

 
Jowin6789: I do have the following written at the beginning of the EA:
Asked and answered at #1.5 and at #3.5. A variable does nothing, you have to code your selection/count loops to use it.
Reason: