Error handling


for example, forex

As I mentioned many times in the previous articles if a function returns an error the code of this error you can get with the help of the GetLastError() function:

   int GetLastError()

After this function is called the last error code is set to zero, that’s why if a new error doesn’t emerge between two calls of the GetLastError() function for the second time it will return 0.

The GetLastError() function returns the numerical code of an error. If You want to get a text messages of errors you should use the ErrorDescription() function, defined in the stdlib.mqh file:

   string ErrorDescription(int error_code)
     {
      string error_string;
   //----
      switch(error_code)
        {
         //---- codes returned from trade server
         case 0:
           case 1:   error_string="no error";            break;
           case 2:   error_string="common error";   break;
            ...
        }
   //----
      return(error_string);
     }

The error codes returned from the trade server:

ConstantValueDescription
ERR_NO_ERROR0 No error returned
ERR_NO_RESULT1 No error returned, but the result is unknown
ERR_COMMON_ERROR2 Common error
ERR_INVALID_TRADE_PARAMETERS3 Invalid parameters
ERR_SERVER_BUSY4 The trading server is busy
ERR_OLD_VERSION5 The old version of the client terminal
ERR_NO_CONNECTION6 No connection with the trading server
ERR_NOT_ENOUGH_RIGHTS7 Not enough rights
ERR_TOO_FREQUENT_REQUESTS8 Too frequent requests
ERR_MALFUNCTIONAL_TRADE9 Malfunctional trade operation
ERR_ACCOUNT_DISABLED64 Account disabled
ERR_INVALID_ACCOUNT65 Invalid account
ERR_TRADE_TIMEOUT128 Trade timeout
ERR_INVALID_PRICE129 Invalid price
ERR_INVALID_STOPS130 Invalid stops
ERR_INVALID_TRADE_VOLUME131 Invalid trade volume
ERR_MARKET_CLOSED132 Market is closed
ERR_TRADE_DISABLED133 Trade is disabled
ERR_NOT_ENOUGH_MONEY134 Not enough money for performing an operation
ERR_PRICE_CHANGED135 Price changed
ERR_OFF_QUOTES136 Off quotes
ERR_BROKER_BUSY137 Broker is busy
ERR_REQUOTE138 Requote (new prices)
ERR_ORDER_LOCKED139 Order is locked and is being processed
ERR_LONG_POSITIONS_ONLY_ALLOWED140 Long positions only are allowed
ERR_TOO_MANY_REQUESTS141 Too many requests
ERR_TRADE_MODIFY_DENIED145 Modification denied because order is too close to market
ERR_TRADE_CONTEXT_BUSY146 Trade context is busy
ERR_TRADE_EXPIRATION_DENIED147 To use expiration date of an order is prohibited by broker
ERR_TRADE_TOO_MANY_ORDERS148 The number of open and pending orders has reached the limit set by broker


MQL4 run time error codes:

ConstantValueDescription
ERR_NO_MQLERROR4000 No error
ERR_WRONG_FUNCTION_POINTER4001 Wrong function pointer
ERR_ARRAY_INDEX_OUT_OF_RANGE4002 Array index is out of range
ERR_NO_MEMORY_FOR_FUNCTION_CALL_STACK4003 No memory for function call stack
ERR_RECURSIVE_STACK_OVERFLOW4004 Recursive stack overflow
ERR_NOT_ENOUGH_STACK_FOR_PARAMETER4005 Not enough stack for parameter
ERR_NO_MEMORY_FOR_PARAMETER_STRING4006 No memory for parameter string
ERR_NO_MEMORY_FOR_TEMP_STRING4007 No memory for temporary string
ERR_NOT_INITIALIZED_STRING4008 Not initialized string
ERR_NOT_INITIALIZED_ARRAYSTRING 4009 Not initialized string in array
ERR_NO_MEMORY_FOR_ARRAYSTRING4010 No memory for array string
ERR_TOO_LONG_STRING4011 Too long string
ERR_REMAINDER_FROM_ZERO_DIVIDE4012 Remainder from zero divide
ERR_ZERO_DIVIDE4013 Zero divide
ERR_UNKNOWN_COMMAND4014 Unknown command
ERR_WRONG_JUMP4015 Wrong jump
ERR_NOT_INITIALIZED_ARRAY4016 Not initialized array
ERR_DLL_CALLS_NOT_ALLOWED4017 DLL calls are not allowed
ERR_CANNOT_LOAD_LIBRARY4018 Cannot load library
ERR_CANNOT_CALL_FUNCTION4019 Cannot call function
ERR_EXTERNAL_EXPERT_CALLS_NOT_ALLOWED4020 External expert function calls are not allowed
ERR_NOT_ENOUGH_MEMORY_FOR_RETURNED_STRING4021 Not enough memory for temp string returned from function
ERR_SYSTEM_BUSY4022 System is busy
ERR_INVALID_FUNCTION_PARAMETERS_COUNT4050 Invalid function parameters count
ERR_INVALID_FUNCTION_PARAMETER_VALUE4051 Invalid function parameter value
ERR_STRING_FUNCTION_INTERNAL_ERROR4052 String function internal error
ERR_SOME_ARRAY_ERROR4053 Some array error
ERR_INCORRECT_SERIES_ARRAY_USING4054 Incorrect series array using
ERR_CUSTOM_INDICATOR_ERROR4055 Custom indicator error
ERR_INCOMPATIBLE_ARRAYS4056 Arrays are incompatible
ERR_GLOBAL_VARIABLES_PROCESSING_ERROR4057 Global variables processing error
ERR_GLOBAL_VARIABLE_NOT_FOUND4058 Global variable not found
ERR_FUNCTION_NOT_ALLOWED_IN_TESTING_MODE4059 Function is not allowed in testing mode
ERR_FUNCTION_NOT_CONFIRMED4060 Function is not confirmed
ERR_SEND_MAIL_ERROR4061 Send mail error
ERR_STRING_PARAMETER_EXPECTED4062 String parameter expected
ERR_INTEGER_PARAMETER_EXPECTED4063 Integer parameter expected
ERR_DOUBLE_PARAMETER_EXPECTED4064 Double parameter expected
ERR_ARRAY_AS_PARAMETER_EXPECTED4065 Array as parameter expected
ERR_HISTORY_WILL_UPDATED4066 Requested history data in updating state
ERR_TRADE_ERROR4067 Trade error
ERR_END_OF_FILE4099 End of file
ERR_SOME_FILE_ERROR4100 Some file error
ERR_WRONG_FILE_NAME4101 Wrong file name
ERR_TOO_MANY_OPENED_FILES4102 Too many opened files
ERR_CANNOT_OPEN_FILE4103 Cannot open a file
ERR_INCOMPATIBLE_ACCESS_TO_FILE4104 Incompatible access to a file
ERR_NO_ORDER_SELECTED4105 No order selected
ERR_UNKNOWN_SYMBOL4106 Unknown symbol
ERR_INVALID_PRICE_PARAM4107 Invalid price parameter for trading function
ERR_INVALID_TICKET4108 Invalid ticket
ERR_TRADE_NOT_ALLOWED4109 Trade is not allowed
ERR_LONGS_NOT_ALLOWED4110 Longs are not allowed
ERR_SHORTS_NOT_ALLOWED4111 Shorts are not allowed
ERR_OBJECT_ALREADY_EXISTS4200 Object exists already
ERR_UNKNOWN_OBJECT_PROPERTY4201 Unknown object property is requested
ERR_OBJECT_DOES_NOT_EXIST4202 Object does not exist
ERR_UNKNOWN_OBJECT_TYPE4203 Unknown object type
ERR_NO_OBJECT_NAME4204 No object name
ERR_OBJECT_COORDINATES_ERROR4205 Object coordinates error
ERR_NO_SPECIFIED_SUBWINDOW4206 No specified subwindow
ERR_SOME_OBJECT_ERROR4207 Some object error

Next article: "Secrets of proper trade"

+7 (495) 710-76-76
© 1998—2008 «Alpari»

close

Your Personal Area

For alpari.classic enter your account number (a letter and 4 figures) and the code word for the Personal Area.

For alpari.micro account: enter your login (6 figures) and the password for MT.

Open an account!Forgotten your password?