Everyone has to go through same process
Please understand: MetaQuotes has changed almost everything in MQL. They have tried to make MQL compatible with old versions but there are still points they did not make compatible intentionally. We host thousands of source code from clients and i would like to introduce you to common compiler problems in new Metatrader Builds. This may help you to adapt your code. This page will be updated continiously, plesae check this page regularly and post it to your friends.
Variable Names does not allow special characters and points
Statement from MetaQuotes about this subject is clear: “Now, variable names cannot contain special characters and points, and new MQL4 language keywords cannot be used as names. Old MQL4 programs can be recompiled with the new compiler in order to easily correct all such errors while following the compiler’s messages.” We see many such errors, fixing this kind of error is pretty easy. You open your source in MetaEditor and start replacing all variable names with specialchars (this also includes point) with names without specialchars. This is very easy and common compiler error in new builds. Compiler may throw “semicolor expected” error by this problem.
System Functions cannot be overwritten
New compiler is protecting System Functions. As example: if you had a function called “string StringReplace” in your code and Metatrader has introduced new function (they have introduced many new functions) with same name, this will collide and you will see error “override system function” in your compiler.
Cross References
int pos2 = pos2;
This was possible in previous compiler now you will get “undeclared identifier”. New compiler is more strict but this was bad coding style anyways, so its good you fix such problems in your code. New compiler will throw error anyways. There is no way to ignore this error.
event handling function not found
This may have several reasons. Make sure you have read this page first to understand about event handling functions. They are basically start(), init(), deinit(), OnStart(), OnInit(), OnDeinit(), OnTick(), OnTrade() etc… Make sure you have at least OnInit() or init() and start() or OnStart() functions defined in your source code. If this does not solve your problem we have discovered strange behaviour in new compiler. Simply remove the start() or/and init() line in MetaEditor and type it once again and try to compile again. This is usually working and probably a bug on compiler. For Video Demonstratino check: Watch Video
Expressions are not allowed on a global scope
Normally every expression must be inside a function and out ouf functions you can only define new variables and define compiler settings. If you get this error make sure and find any expression outside of function. Here is very good example:
Fixing this error is easy as well, simply locate such lines and make sure you put them inside proper event function such as OnInit or OnStart. Of course you must know what you are doing to decide where it should be placed
Invalid index value
double Spread[0];
This is not allowed anymore. Arrays with 0 size does not exist. Its better you simply remove [0] tag if you dont use ArrayResize later. If you are using ArrayResize later start with a start index like “[10]” instead of “[0]”. You may also try to put “[1]” to fix this error. But depending on intention it may vary how to fix this error. You may also get “array required” error if you remove [0] index. This means that your source code requires an error. Try to put [10] for example.
Reserved words cannot be used as Variable Name
If you get “unexpected token” you may be using a reserved word as variable name:
bool long=false;
bool short=false;
As you know new compiler now supports new variable types long and short. These are reserved keywords for mql and they cannot be used in variable names anymore. There are dozenz of other keywords they have been introduced in new mql compiler. Make sure you change variable names simply. For example append an understore to fix this problem, of course you must change whole source code with this variable name, otherwise you will get big gargabe. This error may also throw “name expected” error in combination.
“comma expected” but problem somewhere else
If you have a code like this:
#property link "http://www.fx1.net"
#define link "http://www.metaquotes.net/"
Compiler shows you the error somewhere random! If you dobule click to compiler error, it brings you to nirvana. This is obviously a bug inside Compiler. This is caused by using “link” property also inside #define. There are many predefined properties. Finding this error is not very easy. Check all your #define lines if they contain any reserved property keyword!
Switch needs type of integer
Previous MQL compiler did not throw any error here but its different now. Try to fix this error by rewriting and re-thinking your algoritm. Non-integer values cannot be compared well without loosing precission, thats why MQL requires integer values. This is industry standard for switch expression. Please adapt your code regarding that.
Case value already used
case 1: Ls_4 = "no error"; break;
case 1: Ls_4 = "no error and no result"; break;
This is now allowed anymore. Please resolve this conflict. New switch cannot manage such a conflict and throws “case value already used” error
Leave a Reply