Write a function like:
prtErr(const string prt) { switch(_LastError) //case 0: ERR_NO_ERROR { case 1:return; // nothing to alarm! case 2:return; // nothing to alarm! case 3:Alert("ERR_INVALID_TRADE_PARAMETERS: "+prt); ResetLastError(); return; ... } }
Now you can use it:
prtErr(StringConcatenate(__LINE__," var1: ",var1," var2: ",var2,...));
Hello again,
So take GetLastError() and store value?
Compare GetLastError() to new GetLastError().
if (statement)
do this
else
do this
{
errorlevel=(GetLastError());
swt();
}
Hello again,
So take GetLastError() and store value?
Compare GetLastError() to new GetLastError().
if (statement)
do this
else
do this
why?
The code I posted to start with, I believe was posted somewhere in the forum. I was unable to find it, so I wrote it again as far as I was able to remember it.
Not all the code, but here:
Any really newble people out there "DON'T USE IT"
//+------------------------------------------------------------------+ void Buy_It() { TakeProfit = Ask + stoploss; StopLoss = Ask - stoploss; ticket=OrderSend(NULL,OP_BUY,0.05,Ask,3,StopLoss,TakeProfit,"Buy",TicketNumber,0,clrBlue); TicketNumber=ticket; if(ticket<0) { errorlevel=(GetLastError()); swt(); } else errorlevel=(GetLastError()); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void swt() { switch(errorlevel) //case 0: ERR_NO_ERROR { case 1 : Alert(""); // ERR_NO_RESULT case 2 : Alert(""); // ERR_COMMON_ERROR case 3 : Alert(""); // ERR_INVALID_TRADE_PARAMETERS case 4 : Alert(""); // ERR_SERVER_BUSY case 5 : Alert(""); // ERR_OLD_VERSION case 6 : Alert(""); // ERR_NO_CONNECTION case 7 : Alert(""); // ERR_NOT_ENOUGH_RIGHTS case 8 : Alert(""); // ERR_TOO_FREQUENT_REQUESTS case 9 : Alert(""); // ERR_MALFUNCTIONAL_TRADE case 64 : ExpertRemove(); // ERR_ACCOUNT_DISABLED case 65 : Wrong_Account(); // ERR_INVALID_ACCOUNT case 128 : Alert(""); // ERR_TRADE_TIMEOUT case 129 : Alert(""); // ERR_INVALID_PRICE case 130 : Alert(""); // ERR_INVALID_STOPS case 131 : Alert(""); // ERR_INVALID_TRADE_VOLUME case 132 : ExpertRemove(); // ERR_MARKET_CLOSED case 133 : Alert(""); // ERR_TRADE_DISABLED case 134 : Alert(""); // ERR_NOT_ENOUGH_MONEY case 135 : Alert(""); // ERR_PRICE_CHANGED case 136 : Alert(""); // ERR_OFF_QUOTES case 137 : Alert(""); // ERR_BROKER_BUSY case 138 : Alert(""); // ERR_REQUOTE case 139 : Alert(""); // ERR_ORDER_LOCKED case 140 : Alert(""); // ERR_LONG_POSITIONS_ONLY_ALLOWED case 141 : Alert(""); // ERR_TOO_MANY_REQUESTS case 145 : Alert(""); // ERR_TRADE_MODIFY_DENIED case 146 : Alert(""); // ERR_TRADE_CONTEXT_BUSY case 147 : Alert(""); // ERR_TRADE_EXPIRATION_DENIED case 148 : Alert(""); // ERR_TRADE_TOO_MANY_ORDERS case 149 : Alert(""); // ERR_TRADE_HEDGE_PROHIBITED case 150 : Alert(""); // ERR_TRADE_PROHIBITED_BY_FIFO case 4000 : Alert(""); // ERR_NO_MQLERROR case 4001 : Alert(""); // ERR_WRONG_FUNCTION_POINTER case 4002 : Alert(""); // ERR_ARRAY_INDEX_OUT_OF_RANGE case 4003 : Alert(""); // ERR_NO_MEMORY_FOR_CALL_STACK case 4004 : Alert(""); // ERR_RECURSIVE_STACK_OVERFLOW case 4005 : Alert(""); // ERR_NOT_ENOUGH_STACK_FOR_PARAM case 4006 : Alert(""); // ERR_NO_MEMORY_FOR_PARAM_STRING case 4007 : Alert(""); // ERR_NO_MEMORY_FOR_TEMP_STRING case 4008 : Alert(""); // ERR_NOT_INITIALIZED_STRING case 4009 : Alert(""); // ERR_NOT_INITIALIZED_ARRAYSTRING case 4010 : Alert(""); // ERR_NO_MEMORY_FOR_ARRAYSTRING case 4011 : Alert(""); // ERR_TOO_LONG_STRING case 4012 : Alert(""); // ERR_REMAINDER_FROM_ZERO_DIVIDE case 4013 : Alert(""); // ERR_ZERO_DIVIDE case 4014 : Alert(""); // ERR_UNKNOWN_COMMAND case 4015 : Alert(""); // ERR_WRONG_JUMP case 4016 : Alert(""); // ERR_NOT_INITIALIZED_ARRAY case 4017 : Alert(""); // ERR_DLL_CALLS_NOT_ALLOWED case 4018 : Alert(""); // ERR_CANNOT_LOAD_LIBRARY case 4019 : Alert(""); // ERR_CANNOT_CALL_FUNCTION case 4020 : Alert(""); // ERR_EXTERNAL_CALLS_NOT_ALLOWED case 4021 : Alert(""); // ERR_NO_MEMORY_FOR_RETURNED_STR case 4022 : Alert(""); // ERR_SYSTEM_BUSY case 4023 : Alert(""); // ERR_DLLFUNC_CRITICALERROR case 4024 : Alert(""); // ERR_INTERNAL_ERROR case 4025 : Alert(""); // ERR_OUT_OF_MEMORY case 4026 : Alert(""); // ERR_INVALID_POINTER case 4027 : Alert(""); // ERR_FORMAT_TOO_MANY_FORMATTERS case 4028 : Alert(""); // ERR_FORMAT_TOO_MANY_PARAMETERS case 4029 : Alert(""); // ERR_ARRAY_INVALID case 4030 : Alert(""); // ERR_CHART_NOREPLY case 4050 : Alert(""); // ERR_INVALID_FUNCTION_PARAMSCNT case 4051 : Alert(""); // ERR_INVALID_FUNCTION_PARAMVALUE case 4052 : Alert(""); // ERR_STRING_FUNCTION_INTERNAL case 4053 : Alert(""); // ERR_SOME_ARRAY_ERROR case 4054 : Alert(""); // ERR_INCORRECT_SERIESARRAY_USING case 4055 : Alert(""); // ERR_CUSTOM_INDICATOR_ERROR case 4056 : Alert(""); // ERR_INCOMPATIBLE_ARRAYS case 4057 : Alert(""); // ERR_GLOBAL_VARIABLES_PROCESSING case 4058 : Alert(""); // ERR_GLOBAL_VARIABLE_NOT_FOUND case 4059 : Alert(""); // ERR_FUNC_NOT_ALLOWED_IN_TESTING case 4060 : Alert(""); // ERR_FUNCTION_NOT_CONFIRMED case 4061 : Alert(""); // ERR_SEND_MAIL_ERROR case 4062 : Alert(""); // ERR_STRING_PARAMETER_EXPECTED case 4063 : Alert(""); // ERR_INTEGER_PARAMETER_EXPECTED case 4064 : Alert(""); // ERR_DOUBLE_PARAMETER_EXPECTED case 4065 : Alert(""); // ERR_ARRAY_AS_PARAMETER_EXPECTED case 4066 : Alert(""); // ERR_HISTORY_WILL_UPDATED case 4067 : Alert(""); // ERR_TRADE_ERROR case 4068 : Alert(""); // ERR_RESOURCE_NOT_FOUND case 4069 : Alert(""); // ERR_RESOURCE_NOT_SUPPORTED case 4070 : Alert(""); // ERR_RESOURCE_DUPLICATED case 4071 : Alert(""); // ERR_INDICATOR_CANNOT_INIT case 4072 : Alert(""); // ERR_INDICATOR_CANNOT_LOAD case 4073 : Alert(""); // ERR_NO_HISTORY_DATA case 4074 : Alert(""); // ERR_NO_MEMORY_FOR_HISTORY case 4075 : Alert(""); // ERR_NO_MEMORY_FOR_INDICATOR case 4099 : Alert(""); // ERR_END_OF_FILE case 4100 : Alert(""); // ERR_SOME_FILE_ERROR case 4101 : Alert(""); // ERR_WRONG_FILE_NAME case 4102 : Alert(""); // ERR_TOO_MANY_OPENED_FILES case 4103 : Alert(""); // ERR_CANNOT_OPEN_FILE case 4104 : Alert(""); // ERR_INCOMPATIBLE_FILEACCESS case 4105 : Alert(""); // ERR_NO_ORDER_SELECTED case 4106 : Alert(""); // ERR_UNKNOWN_SYMBOL case 4107 : Alert(""); // ERR_INVALID_PRICE_PARAM case 4108 : Alert(""); // ERR_INVALID_TICKET case 4109 : Alert(""); // ERR_TRADE_NOT_ALLOWED case 4110 : Alert(""); // ERR_LONGS_NOT_ALLOWED case 4111 : Alert(""); // ERR_SHORTS_NOT_ALLOWED case 4112 : Alert(""); // ERR_TRADE_EXPERT_DISABLED_BY_SERVER case 4200 : Alert(""); // ERR_OBJECT_ALREADY_EXISTS case 4201 : Alert(""); // ERR_UNKNOWN_OBJECT_PROPERTY case 4202 : Alert(""); // ERR_OBJECT_DOES_NOT_EXIST case 4203 : Alert(""); // ERR_UNKNOWN_OBJECT_TYPE case 4204 : Alert(""); // ERR_NO_OBJECT_NAME case 4205 : Alert(""); // ERR_OBJECT_COORDINATES_ERROR case 4206 : Alert(""); // ERR_NO_SPECIFIED_SUBWINDOW case 4207 : Alert(""); // ERR_SOME_OBJECT_ERROR case 4210 : Alert(""); // ERR_CHART_PROP_INVALID case 4211 : Alert(""); // ERR_CHART_NOT_FOUND case 4212 : Alert(""); // ERR_CHARTWINDOW_NOT_FOUND case 4213 : Alert(""); // ERR_CHARTINDICATOR_NOT_FOUND case 4220 : Alert(""); // ERR_SYMBOL_SELECT case 4250 : Alert(""); // ERR_NOTIFICATION_ERROR case 4251 : Alert(""); // ERR_NOTIFICATION_PARAMETER case 4252 : Alert(""); // ERR_NOTIFICATION_SETTINGS case 4253 : Alert(""); // ERR_NOTIFICATION_TOO_FREQUENT case 4260 : Alert(""); // ERR_FTP_NOSERVER case 4261 : Alert(""); // ERR_FTP_NOLOGIN case 4262 : Alert(""); // ERR_FTP_CONNECT_FAILED case 4263 : Alert(""); // ERR_FTP_CLOSED case 4264 : Alert(""); // ERR_FTP_CHANGEDIR case 4265 : Alert(""); // ERR_FTP_FILE_ERROR case 4266 : Alert(""); // ERR_FTP_ERROR case 5001 : Alert(""); // ERR_FILE_TOO_MANY_OPENED case 5002 : Alert(""); // ERR_FILE_WRONG_FILENAME case 5003 : Alert(""); // ERR_FILE_TOO_LONG_FILENAME case 5004 : Alert(""); // ERR_FILE_CANNOT_OPEN case 5005 : Alert(""); // ERR_FILE_BUFFER_ALLOCATION_ERROR case 5006 : Alert(""); // ERR_FILE_CANNOT_DELETE case 5007 : Alert(""); // ERR_FILE_INVALID_HANDLE case 5008 : Alert(""); // ERR_FILE_WRONG_HANDLE case 5009 : Alert(""); // ERR_FILE_NOT_TOWRITE case 5010 : Alert(""); // ERR_FILE_NOT_TOREAD case 5011 : Alert(""); // ERR_FILE_NOT_BIN case 5012 : Alert(""); // ERR_FILE_NOT_TXT case 5013 : Alert(""); // ERR_FILE_NOT_TXTORCSV case 5014 : Alert(""); // ERR_FILE_NOT_CSV case 5015 : Alert(""); // ERR_FILE_READ_ERROR case 5016 : Alert(""); // ERR_FILE_WRITE_ERROR case 5017 : Alert(""); // ERR_FILE_BIN_STRINGSIZE case 5018 : Alert(""); // ERR_FILE_INCOMPATIBLE case 5019 : Alert(""); // ERR_FILE_IS_DIRECTORY case 5020 : Alert(""); // ERR_FILE_NOT_EXIST case 5021 : Alert(""); // ERR_FILE_CANNOT_REWRITE case 5022 : Alert(""); // ERR_FILE_WRONG_DIRECTORYNAME case 5023 : Alert(""); // ERR_FILE_DIRECTORY_NOT_EXIST case 5024 : Alert(""); // ERR_FILE_NOT_DIRECTORY case 5025 : Alert(""); // ERR_FILE_CANNOT_DELETE_DIRECTORY case 5026 : Alert(""); // ERR_FILE_CANNOT_CLEAN_DIRECTORY case 5027 : Alert(""); // ERR_FILE_ARRAYRESIZE_ERROR case 5028 : Alert(""); // ERR_FILE_STRINGRESIZE_ERROR case 5029 : Alert(""); // ERR_FILE_STRUCT_WITH_OBJECTS case 5200 : Alert(""); // ERR_WEBREQUEST_INVALID_ADDRESS case 5201 : Alert(""); // ERR_WEBREQUEST_CONNECT_FAILED case 5202 : Alert(""); // ERR_WEBREQUEST_TIMEOUT case 5203 : Alert(""); // ERR_WEBREQUEST_REQUEST_FAILED default: break; } }
- Why don't you use the debugger?
- Why didn't check the logs?
- Buy = Ask (ok) Exist-Buy = Sell(!!)
- Are the stoploss ok: a) > 0; b) prices (not pips or points?)
My advice for you for 2018: Start learning how you can control yourself what you are doing!
I agree 100%
Learning is a 1000% effort, and you can get it wrong anyway.
Hello again,
Happy New Year to you Carl.
All the best wishes for the year to be.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello everyone, I have started writing some switch statements to hopefully fix some possible problems with my code running. I admit most of which I doubt I will ever come across, or in fact need to use.
Now if more than one error occurs, where the solution to the first causes errors with others. A decision about which error is most important and simply ResetLastError() and wait for the error to occur again?