[...] Any ideas appreciated.
Are you sure that the error 4051 is generated during the code which you have posted, rather than before it?
It seems far more likely that the sequence of events, and the issue, is as follows:
- Block of code earlier to that which you have posted, which does something leading to error 4051
- Then the code which you have posted, which doesn't generate an error
- Checking GetLastError() then gives you the earlier error, which happened before the block of code which you are querying here.
Are you sure that the error 4051 is generated during the code which you have posted, rather than before it?
[...]
To put that another, briefer way:
// The following fails... ObjectDelete("any invalid object name which doesn't exist"); // Fails // The following succeeds... ObjectCreate(0, "new object", OBJ_LABEL, 0, 0, 0); // Succeeds // The following returns 4202, because the error from the use of ObjectDelete() // isn't cleared by the subsequent successful ObjectCreate() int err = GetLastError(); // Returns 4202
To put that another, briefer way: [...]
... or, more generally, use of GetLastError() is meaningless "in isolation". You should only use GetLastError() under one of the following circumstances:
A. You know that GetLastError() is applicable to the most recent action.
For example:
if (OrderSend(...) < 0) { // Order-send has failed // The MT4 documentation guarantees that GetLastError() now contains the reason for the failure of this most recent action }
B. You deliberately reset GetLastError() before carrying out an action which you want to test
For example:
GetLastError(); // Dummy call which gets, discards, and clears the last-error, setting it to zero ... some action which you think may generate an error ... // Use of GetLastError() now tells you whether an error occurred since the time // when you explicitly cleared it, or returns 0 if no error occurred in that block of code int err = GetLastError();
Many thanks to everyone.
I have placed a GetLastError before the statement in question - and correct the error exists prior to this statement.
I am now trying to track the appropriate code.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I use a routine to create an entire table as a summary of all my active trades and each object has a name created by using its x and y positions.
The table maybe 10 columns by 10 lines - i.e. 100 objects created in the same routine -- but all very similar
I noticed the following error 4051 and created some additional 'FileWrite' statements to try and track the error.
It is only COD330_130 that appears to generate this problem.
The next line would be - say - COD345_130 and no problem
There don't appear to be any other problems and the EA continues to work
The 'FileWrite' generated the following
1 ObjName = COD330_130, Object_label = EURCHF colour = clrMidnightBlue xd = 330 yd = 130, 4051 invalid function parameter value
Any ideas appreciated.