ePayments1 468x60
Results 1 to 10 of 10
Like Tree1Likes
  • 1 Post By newdigital

Migrating old MQL4 to new MQL4

This is a discussion on Migrating old MQL4 to new MQL4 within the General Discussion forums, part of the Trading Forum category; Migrating old MQL4 to new MQL4 This guide is for people that want to migrate existing MQL4 scripts to work ...

      
   
  1. #1
    Administrator newdigital's Avatar
    Join Date
    Feb 2013
    Posts
    9,964
    Blog Entries
    1706
    Follow newdigital On Twitter Add newdigital on Facebook Add newdigital on Google+ Add newdigital on MySpace
    Add newdigital on Linkedin

    Migrating old MQL4 to new MQL4

    Migrating old MQL4 to new MQL4



    This guide is for people that want to migrate existing MQL4 scripts to work with the new terminal build as quickly as possible without taking advantage of the new object oriented contructs available.
    It has been collated from various posts on the mql4 forum.
    Disclaimer: I've not tested all of this myself! First read as much as you can about the language changes (ignoring any Object Oriented related stuff).
    Then check you code for all of the following contructs and review/fix...
    In some cases the fixes below are not as good as restructuring your code to properly use the new features!
    Once running, if your script is still a work in progress you may want to add the

    Migrating old MQL4 to new MQL4-terminal_portable_en__1.png


    #property strict directive and recompile again. This will mean you need to make more changes , to get your code to compile cleanly but it will result in cleaner code and may find some bugs.
    New Reserved Keywords

    MQL4 has some new reserved keywords such as 'char','long','short' and 'new'. If you have variables with the same name you'll need to change them. datetime is 64bit

    The datetime type is a 64bit integer, so you will get loss of precision errors converting to int(which is 32bit). Avoid converting it to any other type but datetime ArrayCopyRates()

    This has changed to making a static copy of the rates array (as opposed to pointing to a virtual area that is updated with each tick). Change code to use the new CopyRates() GetLastError()

    GetLastError does not reset the previous error anymore. Call ResetError as required. Or replace with:
    int GetLastErrorOld() { int err = GetLastError(); ResetError(); return err; } The Data Folder Location

    Change all reference to file data paths. eg TerminalPath() becomes either TerminalInfoString(TERMINAL_DATA_PATH); or TerminalInfoString(TERMINAL_COMMONDATA_PATH) Unicode(UTF16) Strings

    Strings are now unicode in MQL4. When passing strings to DLL functions either:
    1. Use the UTF16(2byte wide) version of the function Eg. Use ShellExecuteW instead of ShellExecuteA
    2.Convert the string to ASCII and use the existing function Arrays pass by value

    You cannot pass arrays by value. There are two simple fixes:
    1. If the function does not modify the local array, then simply pass it by reference (adding '&' ), and if applicable add a comment "do not modify local array"
    2. If the function modified the local copy, then change it so it doesnt - eg make a local copy inside the function and use that. StringSubstr - end of string flag

    The end-of-string flag is changed from 0 to -1 in line with MQL5. Also if thre start character is less than 0 then new MQL4 may corrupt strings. Use the following when migrating existing code:
    string StringSubstrOld(string x,int a,int b=-1) { if (a < 0) a= 0; // Stop odd behaviour if (b<=0) b = -1; // new MQL4 EOL flag return StringSubstr(x,a,b); } It might be possible to #define this. Short Circuiting

    Boolean expresions now short circuit. So if an expression contains a function call, that function would always get called on old MQL4, but might not get called in new MQL4. If the function changed something in the program (ie had a side effect), and that change is required to happen, then place the function call ahead of the boolean expression. Eg. replace and ensure functions with required side effects are called ahead of expression evaluation.
    if (Ask > price && GetNextPrice(price2)) then ... with
    bool tmp = GetNextPrice(price2); if (Ask > price && tmp) ) then ... Precedence

    MQL4 Precedence is changed. In Old MQL4 boolean OR(||) had higher precedence than boolean AND(&&). Inew new MQL4 the precedence is the same. Search for expressions where || folow && and add brackets around immediate || arguments. History Files

    History files and offline charts are changed. I must admit I haven't looked into these changes because I have not used these features. Sorry! Bug build 604: ArrayResize on non-dynamic arrays fails silently

    Compiler should issue a warning when trying to resize a non-dynamic array. see Forum post Bug build 604: FileReadArray bug with strings

    Strings are corrupted when read. Use FileReadString(handle) in a loop until fixed. see Forum post Bug build 604: Array Resize returns size of first dimension

    ArrayResize returns size of first dimension not whole array. Contrary to documentation... Cant find thread where this was reported.. old version:
    double ratesArrayCopy[][6]; int size = ArrayResize(ratesArrayCopy, 10); //I got size= 60 new version:
    double ratesArrayCopy[][6]; int size = ArrayResize(ratesArrayCopy, 10); //I got size= 10 ?
    mi@ndw likes this.
    Premium Trading Forum: subscription, public discussion and latest news
    Trading Forum wiki || Social networks for the forum
    Trading blogs || My blog
    ePayments: premium subscription without paypal

  2. #2
    Administrator newdigital's Avatar
    Join Date
    Feb 2013
    Posts
    9,964
    Blog Entries
    1706
    Follow newdigital On Twitter Add newdigital on Facebook Add newdigital on Google+ Add newdigital on MySpace
    Add newdigital on Linkedin
    The table of differences between compilers:
    Old MQL4 compiler New MQL4 compiler New MQL4 with #property strict
    init(), start() and deinit() entry points may have any parameters and any return type init(), start() and deinit() have been remained intact for compatibility,
    while new OnInit(), OnStart(), OnCalculate(), OnTick(), OnTimer(), OnChartEvent(), OnTester() and OnDeinit() should strictly correspond to their signatures
    Ditto
    Virtually any variable names (except for the reserved words) are possible, including special characters and points Variable names cannot have special characters and points.
    The list of the reserved words has been expanded. Thus, such widespread words as short, long, const, etc. cannot be used as names
    Ditto
    Variable scope is from declaration (even in the nested block) to the function end Ditto Variable scope is from declaration to the end of the block, in which the variable is declared
    Implicit initialization of all the variables (both global and local ones) by zero Ditto Only global variables are initialized. In local variables, only strings are initialized implicitly
    Local arrays are not released when exiting the function Local arrays are released when exiting the function Local arrays are released when exiting {} block
    "Array out of range" does not cause a critical error Ditto, except for the arrays of structures and classes, for which this error is critical one "Array out of range" is a critical error causing the program to stop
    No structures and classes Structures and classes are present. Additional data types are implemented Ditto
    Strings are single-byte.
    datetime is a 32-bit integer
    Predefined Volume variable is of double type
    Strings are unicode ones.
    datetime is a 64-bit integer
    Predefined Volume variable is of ulong type
    Ditto
    ArrayCopyRates() performs virtual copying to double[][6] array ArrayCopyRates() performs virtual copying to MqlRates[] array. Copying to double[][6] array has remained intact for the sake of compatibility, however, that copying is real, not virtual. Ditto
    The functions may not return values even if they have a type. To do this, return(0) is automatically inserted by the compiler in the function end Ditto Functions of any type should return a value
    The number of simultaneously opened files is 32 The number of simultaneously opened files is 64 Ditto
    The files are always opened in FILE_SHARE_READ, FILE_SHARE_WRITE mode ** FILE_SHARE_READ and/or FILE_SHARE_WRITE should be specified explicitly Ditto
    Premium Trading Forum: subscription, public discussion and latest news
    Trading Forum wiki || Social networks for the forum
    Trading blogs || My blog
    ePayments: premium subscription without paypal

  3. #3
    Administrator newdigital's Avatar
    Join Date
    Feb 2013
    Posts
    9,964
    Blog Entries
    1706
    Follow newdigital On Twitter Add newdigital on Facebook Add newdigital on Google+ Add newdigital on MySpace
    Add newdigital on Linkedin
    Get Ready to Meet New MetaTrader 4 with Updated MQL4 Language

    The beta test of the new MetaTrader 4 version is currently underway. The update's main features include changes in MQL4 programming language. It has been substantially revised, and its functionality has been brought closer to that of MQL5.

    Of course, we have made every effort to ensure compatibility with older MQL4 applications. However, some issues may still occasionally occur. If you have encountered an error while compiling a new code, please inform us in the appropriate thread of the official MQL4 forum.
    We also urge you to pay special attention to the following points:

    1) In the new build, the file structure for storing the source codes has changed. Previously, all MQL4 programs were stored in Program Files\<terminal_installation_folder>\ root directory. Now, they should be stored in Users\<data_folder>\MQL4\. Thus, if a program has an absolute pathname for some file, you may run into an error message in the compiler. To avoid this, specify a relative pathname in the source code and re-compile it. The data folder can be accessed via File -> Open Data Folder.

    2) All old EX4 files will work correctly in the new terminal assuming that they are not changed. In order to maintain compatibility, the runtime environment copy of the previous MQL4 version has been implemented providing operability of all older codes.

    Find out more about all changes in the new MetaTrader 4 build here. We strongly recommend that you have a close look at the provided material.
    Premium Trading Forum: subscription, public discussion and latest news
    Trading Forum wiki || Social networks for the forum
    Trading blogs || My blog
    ePayments: premium subscription without paypal

  4. #4
    Administrator newdigital's Avatar
    Join Date
    Feb 2013
    Posts
    9,964
    Blog Entries
    1706
    Follow newdigital On Twitter Add newdigital on Facebook Add newdigital on Google+ Add newdigital on MySpace
    Add newdigital on Linkedin
    MetaTrader 4 Build 600 with Updated MQL4 Language and Market of Applications Released :

    All custom executable EX4 files created by old MQL4 compiler will be automatically moved to the new Navigator directory and will work in the new terminal the same way as before.
    Premium Trading Forum: subscription, public discussion and latest news
    Trading Forum wiki || Social networks for the forum
    Trading blogs || My blog
    ePayments: premium subscription without paypal

  5. #5
    Administrator newdigital's Avatar
    Join Date
    Feb 2013
    Posts
    9,964
    Blog Entries
    1706
    Follow newdigital On Twitter Add newdigital on Facebook Add newdigital on Google+ Add newdigital on MySpace
    Add newdigital on Linkedin
    I want to remind one thread - Requests and Raw Ideas.

    I mean - if someone is having the difficulties to improve/fix some indicator/EA to new builds of MT4 - use this thread for request.
    Premium Trading Forum: subscription, public discussion and latest news
    Trading Forum wiki || Social networks for the forum
    Trading blogs || My blog
    ePayments: premium subscription without paypal

  6. #6
    Senior Member mql5's Avatar
    Join Date
    May 2013
    Posts
    1,671
    Blog Entries
    529

    Upgrade to MetaTrader 4 Build 600 and Higher

    Upgrade to MetaTrader 4 Build 600 and Higher

    Migrating old MQL4 to new MQL4-509to610all_f_1.png


    On February 3, 2014 we released the new MetaTrader 4 build 600 with the completely revised MQL4 language and access to the Market of applications.
    In addition to the updated MQL4 language for programming trading strategies, the new version of the MetaTrader 4 terminal provides a revised structore of user data storage. In earlier versions all programs, templates, profiles etc. were stored directly in the terminal installation folder. Now all necessary data required for a particular user are stored in a separate directory called data folder. However, some traders who have never worked with the latest versions of Windows may have question about the operation of the new terminal.



    Metatrader 5 / Metatrader 4 for MQL5 / MQL4 articles preview preview
    Trading blogs || My blog

  7. #7
    Senior Member matfx's Avatar
    Join Date
    Sep 2013
    Posts
    894
    Blog Entries
    103
    Follow matfx On Twitter
    An article about migrating indicators/EA from MQL4 to MQL5

    https://www.mql5.com/en/articles/81

  8. #8
    Senior Member Taylor Woods's Avatar
    Join Date
    Jan 2019
    Posts
    185
    Great FX brokers will enable you to store funds and pull back your income bother free. Brokers really have no reason to make it difficult for you to pull back your benefits in light of the fact that the main reason they hold your funds is to encourage trading. Your broker just holds your money to make trading simpler so there is no reason for you to experience serious difficulties getting the benefits you have earned. Your broker should ensure that the withdrawal procedure is expedient and smooth.

  9. #9
    Senior Member
    Join Date
    Jul 2014
    Posts
    636
    ND, why we are seeing this msg iin many threads?

    Quote Originally Posted by Taylor Woods View Post
    Great FX brokers will enable you to store funds and pull back your income bother free. Brokers really have no reason to make it difficult for you to pull back your benefits in light of the fact that the main reason they hold your funds is to encourage trading. Your broker just holds your money to make trading simpler so there is no reason for you to experience serious difficulties getting the benefits you have earned. Your broker should ensure that the withdrawal procedure is expedient and smooth.

  10. #10
    Administrator newdigital's Avatar
    Join Date
    Feb 2013
    Posts
    9,964
    Blog Entries
    1706
    Follow newdigital On Twitter Add newdigital on Facebook Add newdigital on Google+ Add newdigital on MySpace
    Add newdigital on Linkedin
    Quote Originally Posted by jagadish123 View Post
    ND, why we are seeing this msg iin many threads?
    seems - flooding.
    I delete some of his posts.
    Premium Trading Forum: subscription, public discussion and latest news
    Trading Forum wiki || Social networks for the forum
    Trading blogs || My blog
    ePayments: premium subscription without paypal

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •