myeatrade

MQL4 Reference

MQL4 Runtime errors

In the executing sub-system of the client terminal, the error code can be stored, in the case of its occurring at an mql4 program execution. There is a specific last_error variable provided for every executable mql4 program. Before the init function is run, the last_error variable has been zeroized. If an error occurs during the process of calculation or that of calling the built-in function, the last_error variable takes the corresponding error code. Value stored in this variable can be got using the GetLastError function. At that, the last_error variable will be zeroized.

There is a number of critical errors that cause immediate stopping of program execution:

Constant Value Description
ERR_WRONG_FUNCTION_POINTER 4001 At calling of an internal function, a wrong function pointer has been detected
ERR_NO_MEMORY_FOR_CALL_STACK 4003 At calling of an internal function, it is impossible to reallocate memory for the function calls stack
ERR_RECURSIVE_STACK_OVERFLOW 4004 The data stack is overflowed at the recursive function call
ERR_NO_MEMORY_FOR_PARAM_STRING 4006 At calling of an internal function, it is impossible to allocate memory for passing the string as a function parameter
ERR_NO_MEMORY_FOR_TEMP_STRING 4007 It is impossible to allocate the temporary buffer for string operations
ERR_NO_MEMORY_FOR_ARRAYSTRING 4010 At assignment, it is impossible to reallocate memory for a string in an array
ERR_TOO_LONG_STRING 4011 At assignment, too long resulting string to be placed into the service buffer (no possibility to reallocate for the service buffer)
ERR_REMAINDER_FROM_ZERO_DIVIDE 4012 Dividing by 0 when taking the remainder of the division
ERR_ZERO_DIVIDE 4013 Dividing by 0
ERR_UNKNOWN_COMMAND 4014 Unknown instruction

If the program stopped working due to a critical error, the code of this error can be read at the next launching of the start or deinit function using the GetLastError() function. Thelast_error variable is not zeroized before the start or deinit function starts.

There is a number of critical errors referred to imported functions call that cause immediate stopping of expert advisor or custom indicator execution the start function will not be launched until expert or indicator is re-initialized.

Constant Value Description
ERR_CANNOT_LOAD_LIBRARY 4018 At calling of an imported function, loading error of dll or ex4 library occurred
ERR_CANNOT_CALL_FUNCTION 4019 At calling of an imported function, it was found out that dll or ex4 library did not contain the called function
ERR_DLL_CALLS_NOT_ALLOWED 4017 At calling of an imported dll function, it was found out that dll imports were not allowed
ERR_EXTERNAL_CALLS_NOT_ALLOWED 4020 At calling of an ex4 function, it was found out that external ex4 imports were not allowed

Other errors do not interrupt program execution.

Constant Value Description
ERR_ARRAY_INDEX_OUT_OF_RANGE 4002 Attempt to access an array item number of which is out of the array range
ERR_NOT_INITIALIZED_STRING 4008 Not initialized string; no value was assigned to the string being an operand in an expression
ERR_NOT_INITIALIZED_ARRAYSTRING 4009 Not initialized string in the array string; no value was assigned to the string item being an operand in an expression
ERR_NO_MEMORY_FOR_RETURNED_STR 4021 It is impossible to reallocate memory for a string returned from function

The ERR_NO_MQLERROR (4000) code is never generated.

There is a number of errors which are possible only as a result of software or hardware failure.If any errors described below occur repeatedly, one should contact the developers.

Constant Value Description
ERR_WRONG_FUNCTION_POINTER 4001 At calling of an internal function, a wrong function pointer has been detected
ERR_UNKNOWN_COMMAND 4014 Unknown instruction
ERR_NOT_INITIALIZED_ARRAY 4016 Not initialized array
ERR_INVALID_FUNCTION_PARAMSCNT 4050 Invalid parameters count passed into built-in function
ERR_STRING_FUNCTION_INTERNAL 4052 String function internal error
ERR_TRADE_ERROR 4067 Trade function internal error
ERR_SOME_OBJECT_ERROR 4207 Object function internal error

There are some functions that always change the last_error variable value

Function Error codes
AccountFreeMarginCheck ERR_STRING_PARAMETER_EXPECTED (4062), ERR_INTEGER_PARAMETER_EXPECTED (4063), ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_UNKNOWN_SYMBOL (4106), ERR_NOT_ENOUGH_MONEY (134)
OrderSend ERR_CUSTOM_INDICATOR_ERROR (4055), ERR_STRING_PARAMETER_EXPECTED (4062), ERR_INTEGER_PARAMETER_EXPECTED (4063), ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_INVALID_PRICE_PARAM (4107), ERR_UNKNOWN_SYMBOL (4106), ERR_TRADE_NOT_ALLOWED (4109), ERR_LONGS_NOT_ALLOWED (4110), ERR_SHORTS_NOT_ALLOWED (4111), code returned by trade server
OrderClose ERR_CUSTOM_INDICATOR_ERROR (4055), ERR_INTEGER_PARAMETER_EXPECTED (4063), ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_INVALID_PRICE_PARAM (4107), ERR_INVALID_TICKET (4108), ERR_UNKNOWN_SYMBOL (4106), ERR_TRADE_NOT_ALLOWED (4109), code returned by trade server
OrderCloseBy ERR_CUSTOM_INDICATOR_ERROR (4055), ERR_INTEGER_PARAMETER_EXPECTED (4063), ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_INVALID_TICKET (4108), ERR_UNKNOWN_SYMBOL (4106), ERR_TRADE_NOT_ALLOWED (4109), code returned by trade server
OrderDelete ERR_CUSTOM_INDICATOR_ERROR (4055), ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_INVALID_TICKET (4108), ERR_UNKNOWN_SYMBOL (4106), ERR_TRADE_NOT_ALLOWED (4109), code returned by trade server
OrderModify ERR_CUSTOM_INDICATOR_ERROR (4055), ERR_INTEGER_PARAMETER_EXPECTED (4063), ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_INVALID_PRICE_PARAM (4107), ERR_INVALID_TICKET (4108), ERR_UNKNOWN_SYMBOL (4106), ERR_TRADE_NOT_ALLOWED (4109), code returned by trade server
GetLastError ERR_NO_ERROR (0)

Some functions change value of the last_error variable only if an error occurs.

Function Error codes
ArrayBsearch ERR_ARRAY_AS_PARAMETER_EXPECTED (4065), ERR_SOME_ARRAY_ERROR (4053), ERR_INVALID_FUNCTION_PARAMVALUE (4051)
ArrayCopy ERR_ARRAY_AS_PARAMETER_EXPECTED (4065), ERR_SOME_ARRAY_ERROR (4053), ERR_INCOMPATIBLE_ARRAYS (4056), ERR_INVALID_FUNCTION_PARAMVALUE (4051)
ArrayCopyRates ERR_ARRAY_AS_PARAMETER_EXPECTED (4065), ERR_SOME_ARRAY_ERROR (4053), ERR_INCOMPATIBLE_ARRAYS (4056), ERR_STRING_PARAMETER_EXPECTED (4062),
ArrayCopySeries ERR_ARRAY_AS_PARAMETER_EXPECTED (4065), ERR_SOME_ARRAY_ERROR (4053), ERR_INCORRECT_SERIESARRAY_USING (4054), ERR_INCOMPATIBLE_ARRAYS (4056), ERR_STRING_PARAMETER_EXPECTED (4062), ERR_HISTORY_WILL_UPDATED (4066), ERR_INVALID_FUNCTION_PARAMVALUE (4051)
ArrayDimension ERR_ARRAY_AS_PARAMETER_EXPECTED (4065), ERR_SOME_ARRAY_ERROR (4053)
ArrayGetAsSeries ERR_ARRAY_AS_PARAMETER_EXPECTED (4065), ERR_SOME_ARRAY_ERROR (4053)
ArrayInitialize ERR_ARRAY_AS_PARAMETER_EXPECTED (4065), ERR_SOME_ARRAY_ERROR (4053), ERR_INVALID_FUNCTION_PARAMVALUE (4051)
ArrayIsSeries ERR_ARRAY_AS_PARAMETER_EXPECTED (4065), ERR_SOME_ARRAY_ERROR (4053)
ArrayMaximum ERR_ARRAY_AS_PARAMETER_EXPECTED (4065), ERR_SOME_ARRAY_ERROR (4053), ERR_INVALID_FUNCTION_PARAMVALUE (4051)
ArrayMinimum ERR_ARRAY_AS_PARAMETER_EXPECTED (4065), ERR_SOME_ARRAY_ERROR (4053), ERR_INVALID_FUNCTION_PARAMVALUE (4051)
ArrayRange ERR_ARRAY_AS_PARAMETER_EXPECTED (4065), ERR_SOME_ARRAY_ERROR (4053), ERR_INTEGER_PARAMETER_EXPECTED (4063), ERR_INVALID_FUNCTION_PARAMVALUE (4051)
ArrayResize ERR_ARRAY_AS_PARAMETER_EXPECTED (4065), ERR_SOME_ARRAY_ERROR (4053), ERR_INVALID_FUNCTION_PARAMVALUE (4051)
ArraySetAsSeries ERR_ARRAY_AS_PARAMETER_EXPECTED (4065), ERR_SOME_ARRAY_ERROR (4053)
ArraySize ERR_ARRAY_AS_PARAMETER_EXPECTED (4065), ERR_SOME_ARRAY_ERROR (4053)
ArraySort ERR_ARRAY_AS_PARAMETER_EXPECTED (4065), ERR_SOME_ARRAY_ERROR (4053), ERR_INCORRECT_SERIESARRAY_USING (4054), ERR_INVALID_FUNCTION_PARAMVALUE (4051)
FileClose ERR_INVALID_FUNCTION_PARAMVALUE (4051)
FileDelete ERR_WRONG_FILE_NAME (4101), ERR_SOME_FILE_ERROR (4100)
FileFlush ERR_INVALID_FUNCTION_PARAMVALUE (4051)
FileIsEnding ERR_INVALID_FUNCTION_PARAMVALUE (4051)
FileIsLineEnding ERR_INVALID_FUNCTION_PARAMVALUE (4051)
FileOpen ERR_TOO_MANY_OPENED_FILES (4102), ERR_WRONG_FILE_NAME (4101), ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_SOME_FILE_ERROR (4100), ERR_CANNOT_OPEN_FILE (4103)
FileOpenHistory ERR_TOO_MANY_OPENED_FILES (4102), ERR_WRONG_FILE_NAME (4101), ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_SOME_FILE_ERROR (4100), ERR_CANNOT_OPEN_FILE (4103)
FileReadArray ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_INCOMPATIBLE_FILEACCESS (4104), ERR_SOME_ARRAY_ERROR (4053), ERR_SOME_FILE_ERROR (4100), ERR_END_OF_FILE (4099)
FileReadDouble ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_INCOMPATIBLE_FILEACCESS (4104), ERR_END_OF_FILE (4099)
FileReadInteger ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_INCOMPATIBLE_FILEACCESS (4104), ERR_END_OF_FILE (4099)
FileReadNumber ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_INCOMPATIBLE_FILEACCESS (4104), ERR_SOME_FILE_ERROR (4100), ERR_END_OF_FILE (4099)
FileReadString ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_INCOMPATIBLE_FILEACCESS (4104), ERR_SOME_FILE_ERROR (4100), ERR_TOO_LONG_STRING (4011), ERR_END_OF_FILE (4099)
FileSeek ERR_INVALID_FUNCTION_PARAMVALUE (4051)
FileSize ERR_INVALID_FUNCTION_PARAMVALUE (4051)
FileTell ERR_INVALID_FUNCTION_PARAMVALUE (4051)
FileWrite ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_SOME_FILE_ERROR (4100)
FileWriteDouble ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_INCOMPATIBLE_FILEACCESS (4104), ERR_SOME_FILE_ERROR (4100)
FileWriteInteger ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_INCOMPATIBLE_FILEACCESS (4104), ERR_SOME_FILE_ERROR (4100)
FileWriteString ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_INCOMPATIBLE_FILEACCESS (4104), ERR_SOME_FILE_ERROR (4100), ERR_STRING_PARAMETER_EXPECTED (4062)
FileWriteArray ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_INCOMPATIBLE_FILEACCESS (4104), ERR_SOME_FILE_ERROR (4100),
GlobalVariableCheck ERR_STRING_PARAMETER_EXPECTED (4062)
GlobalVariableDel ERR_STRING_PARAMETER_EXPECTED (4062), ERR_GLOBAL_VARIABLES_PROCESSING (4057)
GlobalVariableGet ERR_STRING_PARAMETER_EXPECTED (4062), ERR_GLOBAL_VARIABLE_NOT_FOUND (4058)
GlobalVariablesDeleteAll ERR_STRING_PARAMETER_EXPECTED (4062), ERR_GLOBAL_VARIABLES_PROCESSING (4057)
GlobalVariableSet ERR_STRING_PARAMETER_EXPECTED (4062), ERR_GLOBAL_VARIABLES_PROCESSING (4057), ERR_GLOBAL_VARIABLE_NOT_FOUND (4058)
GlobalVariableSetOnCondition ERR_STRING_PARAMETER_EXPECTED (4062), ERR_GLOBAL_VARIABLE_NOT_FOUND (4058)
iCustom ERR_STRING_PARAMETER_EXPECTED (4062), ERR_INVALID_FUNCTION_PARAMVALUE (4051)
technical indicators, series access functions ERR_HISTORY_WILL_UPDATED (4066)
technical indicators OnArray ERR_ARRAY_AS_PARAMETER_EXPECTED (4065), ERR_SOME_ARRAY_ERROR (4053)
IndicatorBuffers ERR_INVALID_FUNCTION_PARAMVALUE (4051)
IndicatorDigits ERR_INVALID_FUNCTION_PARAMVALUE (4051)
IndicatorShortName ERR_STRING_PARAMETER_EXPECTED (4062), ERR_INVALID_FUNCTION_PARAMVALUE (4051)
MarketInfo ERR_STRING_PARAMETER_EXPECTED (4062), ERR_FUNC_NOT_ALLOWED_IN_TESTING (4059), ERR_UNKNOWN_SYMBOL (4106), ERR_INVALID_FUNCTION_PARAMVALUE (4051)
MathArccos ERR_INVALID_FUNCTION_PARAMVALUE (4051)
MathArcsin ERR_INVALID_FUNCTION_PARAMVALUE (4051)
MathMod ERR_ZERO_DIVIDE (4013)
MathSqrt ERR_INVALID_FUNCTION_PARAMVALUE (4051)
MessageBox ERR_FUNC_NOT_ALLOWED_IN_TESTING (4059), ERR_CUSTOM_INDICATOR_ERROR (4055), ERR_STRING_PARAMETER_EXPECTED (4062)
ObjectCreate ERR_STRING_PARAMETER_EXPECTED (4062), ERR_NO_OBJECT_NAME (4204), ERR_UNKNOWN_OBJECT_TYPE (4203), ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_OBJECT_ALREADY_EXISTS (4200), ERR_NO_SPECIFIED_SUBWINDOW (4206)
ObjectDelete ERR_STRING_PARAMETER_EXPECTED (4062), ERR_NO_OBJECT_NAME (4204), ERR_OBJECT_DOES_NOT_EXIST (4202)
ObjectDescription ERR_STRING_PARAMETER_EXPECTED (4062), ERR_NO_OBJECT_NAME (4204), ERR_OBJECT_DOES_NOT_EXIST (4202)
ObjectFind ERR_STRING_PARAMETER_EXPECTED (4062), ERR_NO_OBJECT_NAME (4204)
ObjectGet ERR_STRING_PARAMETER_EXPECTED (4062), ERR_NO_OBJECT_NAME (4204), ERR_OBJECT_DOES_NOT_EXIST (4202), ERR_UNKNOWN_OBJECT_PROPERTY (4201)
ObjectGetFiboDescription ERR_STRING_PARAMETER_EXPECTED (4062), ERR_NO_OBJECT_NAME (4204), ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_OBJECT_DOES_NOT_EXIST (4202), ERR_UNKNOWN_OBJECT_TYPE (4203), ERR_UNKNOWN_OBJECT_PROPERTY (4201)
ObjectGetShiftByValue ERR_STRING_PARAMETER_EXPECTED (4062), ERR_NO_OBJECT_NAME (4204), ERR_OBJECT_DOES_NOT_EXIST (4202), ERR_OBJECT_COORDINATES_ERROR (4205)
ObjectGetValueByShift ERR_STRING_PARAMETER_EXPECTED (4062), ERR_NO_OBJECT_NAME (4204), ERR_OBJECT_DOES_NOT_EXIST (4202), ERR_OBJECT_COORDINATES_ERROR (4205)
ObjectMove ERR_STRING_PARAMETER_EXPECTED (4062), ERR_NO_OBJECT_NAME (4204), ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_OBJECT_DOES_NOT_EXIST (4202)
ObjectName ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_ARRAY_INDEX_OUT_OF_RANGE (4002)
ObjectSet ERR_STRING_PARAMETER_EXPECTED (4062), ERR_NO_OBJECT_NAME (4204), ERR_OBJECT_DOES_NOT_EXIST (4202), ERR_UNKNOWN_OBJECT_PROPERTY (4201)
ObjectSetText ERR_STRING_PARAMETER_EXPECTED (4062), ERR_NO_OBJECT_NAME (4204), ERR_OBJECT_DOES_NOT_EXIST (4202)
ObjectSetFiboDescription ERR_STRING_PARAMETER_EXPECTED (4062), ERR_NO_OBJECT_NAME (4204), ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_STRING_PARAMETER_EXPECTED (4062), ERR_OBJECT_DOES_NOT_EXIST (4202), ERR_UNKNOWN_OBJECT_TYPE (4203), ERR_UNKNOWN_OBJECT_PROPERTY (4201)
ObjectType ERR_STRING_PARAMETER_EXPECTED (4062), ERR_NO_OBJECT_NAME (4204), ERR_OBJECT_DOES_NOT_EXIST (4202)
OrderClosePrice ERR_NO_ORDER_SELECTED (4105)
OrderCloseTime ERR_NO_ORDER_SELECTED (4105)
OrderComment ERR_NO_ORDER_SELECTED (4105)
OrderCommission ERR_NO_ORDER_SELECTED (4105)
OrderExpiration ERR_NO_ORDER_SELECTED (4105)
OrderLots ERR_NO_ORDER_SELECTED (4105)
OrderMagicNumber ERR_NO_ORDER_SELECTED (4105)
OrderOpenPrice ERR_NO_ORDER_SELECTED (4105)
OrderOpenTime ERR_NO_ORDER_SELECTED (4105)
OrderPrint ERR_NO_ORDER_SELECTED (4105)
OrderProfit ERR_NO_ORDER_SELECTED (4105)
OrderStopLoss ERR_NO_ORDER_SELECTED (4105)
OrderSwap ERR_NO_ORDER_SELECTED (4105)
OrderSymbol ERR_NO_ORDER_SELECTED (4105)
OrderTakeProfit ERR_NO_ORDER_SELECTED (4105)
OrderTicket ERR_NO_ORDER_SELECTED (4105)
OrderType ERR_NO_ORDER_SELECTED (4105)
PlaySound ERR_WRONG_FILE_NAME (4101)
SendFTP ERR_FUNC_NOT_ALLOWED_IN_TESTING (4059), ERR_CUSTOM_INDICATOR_ERROR (4055), ERR_STRING_PARAMETER_EXPECTED (4062)
SendMail ERR_FUNC_NOT_ALLOWED_IN_TESTING (4059), ERR_STRING_PARAMETER_EXPECTED (4062), ERR_FUNCTION_NOT_CONFIRMED (4060), ERR_SEND_MAIL_ERROR (4061)
SetIndexArrow ERR_INVALID_FUNCTION_PARAMVALUE (4051)
SetIndexBuffer ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_INCORRECT_SERIESARRAY_USING (4054), ERR_INCOMPATIBLE_ARRAYS (4056)
SetIndexDrawBegin ERR_INVALID_FUNCTION_PARAMVALUE (4051)
SetIndexEmptyValue ERR_INVALID_FUNCTION_PARAMVALUE (4051)
SetIndexLabel ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_STRING_PARAMETER_EXPECTED (4062)
SetIndexShift ERR_INVALID_FUNCTION_PARAMVALUE (4051)
SetIndexStyle ERR_INVALID_FUNCTION_PARAMVALUE (4051)
SetLevelValue ERR_INVALID_FUNCTION_PARAMVALUE (4051)
Sleep ERR_CUSTOM_INDICATOR_ERROR (4055)
StringFind ERR_STRING_PARAMETER_EXPECTED (4062)
StringGetChar ERR_STRING_PARAMETER_EXPECTED (4062), ERR_NOT_INITIALIZED_STRING (4008), ERR_ARRAY_INDEX_OUT_OF_RANGE (4002)
StringLen ERR_STRING_PARAMETER_EXPECTED (4062)
StringSetChar ERR_STRING_PARAMETER_EXPECTED (4062), ERR_INVALID_FUNCTION_PARAMVALUE (4051), ERR_NOT_INITIALIZED_STRING (4008), ERR_TOO_LONG_STRING (4011), ERR_ARRAY_INDEX_OUT_OF_RANGE (4002)
StringSubstr ERR_STRING_PARAMETER_EXPECTED (4062), ERR_TOO_LONG_STRING (4011)
StringTrimLeft ERR_STRING_PARAMETER_EXPECTED (4062)
StringTrimRight ERR_STRING_PARAMETER_EXPECTED (4062)
WindowIsVisible ERR_FUNC_NOT_ALLOWED_IN_TESTING (4059)
WindowFind ERR_FUNC_NOT_ALLOWED_IN_TESTING (4059), ERR_STRING_PARAMETER_EXPECTED (4062), ERR_NOT_INITIALIZED_STRING (4008)
WindowHandle ERR_FUNC_NOT_ALLOWED_IN_TESTING (4059), ERR_STRING_PARAMETER_EXPECTED (4062), ERR_NOT_INITIALIZED_STRING (4008)
WindowScreenShot ERR_WRONG_FILE_NAME (4101), ERR_INVALID_FUNCTION_PARAMVALUE (4051)

Other functions never change the last_error variable value.

This article url: http://www.myeatrade.com/429/

Please login to post comment, if you haven't account you can register free