is there a bug in mt5 ObjectDelete? - page 3

To add comments, please log in or register
honest_knave
Moderator
2308
honest_knave  
Fernando Carreiro:
Which build did you use? Since there seems to be a possible bug in the latest build with the "ObjectDelete()" function, it could be there is are also problems with the "ObjectFind()" as well!

MT5: Build 1495 (09 Dec 2016) 

Fernando Carreiro
4955
Fernando Carreiro  
honest_knave:

MT5: Build 1495 (09 Dec 2016) 

I ran your code on build 1491 and got similar results:

2016.12.11 12:31:05.739 test (EURUSD.m,H1)      ObjectFind took 20126 μs
2016.12.11 12:31:05.739 test (EURUSD.m,H1)      ObjectDelete took 247 μs
honest_knave
Moderator
2308
honest_knave  
Fernando Carreiro:

I ran your code on build 1491 and got similar results:

Consistently strange. Perhaps there is a good explanation why...?
Farzin Sadeghi
5494
Farzin Sadeghi  
honest_knave:

This could be semantic rather than a bug.

The purpose of ObjectDelete is to "remove the object with the specified name".

At the end of running the function, is there an object called "Non-existing Object" still on the chart? No... so is this success?

Looking at it another way, did ObjectDelete remove an object called "Non-existing Object"? No... so is this failure? 

Do you measure success by the outcome or the action taken?

Perhaps a false would be expected if the named object remains on the chart after running the function. Otherwise, it was a success.

Maybe what you say is true but as we are migrating from MQL4 to MQL5 we are expecting to see the same result or at least a result that is clearly written in return value of the reference.

passing this first problem , I tested the ObjectMove function , and again I am getting TRUE result too! this moves beyond your explanation that because the object is not available in the end so the true is correct.

with ObjectMove on an object that is not available it should return false!  

moveResult=ObjectMove(ChartID(),"not available trend line",1,time[4950],low[4980]);

   Print(__LINE__,"-moveResult=",moveResult); 

2016.12.11 17:22:39.367 Far-Test-ChangeTrendLine (EURUSD,H1) 44-moveResult=true

Rashid Umarov
Admin
16503
Rashid Umarov  
Farzin Sadeghi:

hi , I am writing an indicator in MQL5, but whatever I write as string name ObejectDelete returns true ! even on an empty chart with no objects!

 

Read Object Functions description

This is the group of functions intended for working with graphic objects relating to any specified chart.

The functions defining the properties of graphical objects, as well as ObjectCreate() and ObjectMove() operations for creating and moving objects along the chart are actually used for sending commands to the chart. If these functions are executed successfully, the command is included in the common queue of the chart events. Visual changes in the properties of graphical objects are implemented when handling the queue of the chart events.

It means that command "Delete this object " successfully accepted. You can control the result of your command by GetLastError(). Try it - whic code is retutned?
Farzin Sadeghi
5494
Farzin Sadeghi  
Rashid Umarov:

Read Object Functions description

It means that command "Delete this object " successfully accepted. You can control the result of your command by GetLastError(). Try it - whic code is retutned?

I changed the code this way : 

int ObjCount = ObjectsTotal(ChartID(),/*0=main subwindow*/0,/*all objectTypes*/-1);

   ResetLastError();

   bool deleteResult=ObjectDelete(ChartID(),"non existing object"); 

   Print(__LINE__,"-",deleteResult," | ObjCount=",ObjCount," | LastError=",GetLastError()); 

 

here is the result :

2016.12.12 12:38:43.373 Far-TestObjectDelete (EURUSD,H1) 38-true | ObjCount=0 | LastError=0

ERR_SUCCESS

0

The operation completed successfully


so it does not return error to find out for example it couldn't access that object. but in MT4 it does return the error. 

Rashid Umarov
Admin
16503
Rashid Umarov  
Farzin Sadeghi:

ERR_SUCCESS

0

The operation completed successfully


so it does not return error to find out for example it couldn't access that object. but in MT4 it does return the error. 

OK. As I found out we do not raise any error in such case in MQL5 because these operations are asynchronous.  So you have 2 options:

  • check yourself whether the object exists before deleting
  • try to delete it in any case and do not worry if object is absent
Farzin Sadeghi
5494
Farzin Sadeghi  
Rashid Umarov:

OK. As I found out we do not raise any error in such case in MQL5 because these operations are anisochronous.  So you have 2 options:

  • check yourself wether the object exists before deleting
  • try to delete it in any case and do not worry if obect is absent
This way there is no use of checking result of ObjectDelete or ObjectMove in MQL5  ! isn't it better to fix it to the way it used to be in MQL4 ?
Alain Verleyen
38115
Alain Verleyen  
Rashid Umarov:

OK. As I found out we do not raise any error in such case in MQL5 because these operations are asynchronous.  So you have 2 options:

  • check yourself whether the object exists before deleting
  • try to delete it in any case and do no worry if object is absent

How it could return false in this case ?

ObjectDelete() documentation says :

Return Value

Returns true if the removal was successful, otherwise returns false.

The documentation should be clearer, it doesn't say "true if the command is accepted".

If we want to be sure an object is delete, we will have to check if it exists after the delete command, it's non sense.

Documentation on MQL5: Object Functions / ObjectDelete
Documentation on MQL5: Object Functions / ObjectDelete
  • www.mql5.com
Object Functions / ObjectDelete - Reference on algorithmic/automated trading language for MetaTrader 5
Rashid Umarov
Admin
16503
Rashid Umarov  
Alain Verleyen:

How it could return false in this case ?

ObjectDelete() documentation says :

The documentation should be clearer, it doesn't say "true if the command is accepted".

Wiil be fixed in such way

Return Value

Returns true if the command is placed in the common queue of the chart events, otherwise returns false.
To add comments, please log in or register