MQL4 Language Updates

Overview

MQL4 has been completely revised to reach MQL5 levels, enabling the development of trading robots using a unified MetaEditor, single style, libraries, and debugging tools. This revision integrates MQL5 features like OOP and native code compilation while preserving MQL4 functionality. The unified compiler supports both MQL4 and MQL5. MQL5 Storage and enhanced security for EX4 applications are now available.

Key Language Changes

  • **Data Types**: Added char, short, long, uchar, ushort, uint, ulong, double. Typecasting is implemented.
  • **Strings**: Now Unicode format (previously ANSI).
  • **Predefined Variables**: Volume is now long type. Time series for volumes are long type arrays.
  • **Object-Oriented Programming (OOP)**: Structures, classes, object pointers, void type, and this keyword are supported. Features include Encapsulation, Inheritance, Polymorphism, Overload, and Virtual functions.
  • **Event Handlers**: New handlers: OnInit(), OnDeinit(), OnStart(), OnCalculate(), OnTick(), OnTimer(), OnChartEvent(), OnTester().
  • **Function Signatures**: Predefined functions must strictly correspond to their signatures (defined parameters and return type).
  • **Variable Naming**: Cannot contain special characters or points. New MQL4 keywords cannot be used as names.
  • **Operator Precedence**: Matches C language standards. Parentheses recommended for clarity.
  • **Logical Operations**: Shortened condition check (short-circuit evaluation) is used.
  • **ArrayCopyRates()**: Behavior changed. New format uses MqlRates structure array. Old format (copying to double[][6]) performs real copying.
  • **RateInfo Structure**: Updated format includes fields for spread and trading volume. Old EX4 applications and DLLs based on old RateInfo will not work.
  • #property strict Directive

    Introduced for compatibility and enhanced control. When enabled:

  • **Variable Scope**: From declaration to the end of the block (not just function end).
  • **Local Arrays**: Released when exiting the block.
  • **Array Out of Range**: Critical error causing program stop (especially for structures and classes).
  • **Function Return Values**: Functions of any type must return a value.
  • **String Representation of datetime**: Depends on compilation mode (Unicode with #property strict).
  • **Libraries**: export modifier required for exported functions.
  • File Operations

  • **Simultaneous Files**: Increased from 32 to 64.
  • **File Opening Mode**: Must be specified explicitly (FILE_SHARE_READ, FILE_SHARE_WRITE).
  • **FileWrite* Functions**: Return type changed from int to uint (number of bytes written or 0 on error).
  • File Structure Changes

  • **Old Structure**: \experts\ subdirectories.
  • **New Structure**: \MQL4\ subdirectories (e.g., MQL4\Experts, MQL4\Indicators, MQL4\Files).
  • **Update Process**: Files from old directories are automatically copied to new ones. User-created subfolders are not processed. Old EX4 files will work, but EX4 libraries compiled with the new compiler can only be called from EX4 programs compiled with the new version.
  • Compatibility Notes

  • Old MQL4 programs can be recompiled with the new compiler to correct errors.
  • Old EX4 applications and DLLs based on the old RateInfo format require conversion.
  • The #include paths might need adjustment.
  • Array out of range errors are more critical in strict mode.