+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12

Thread: Converting from MQL4 to MQL5

  1. #1
    Administrator Jim's Avatar
    Join Date
    Apr 2010
    Location
    South West England
    Posts
    383

    Converting from MQL4 to MQL5

    I've copied this query here from the blog. The forum seems a more appropriate place to answer this sort of question:

    I am new to MQL5 and am in the process of converting an MQL4 program to MQL5. Could you please direct me to how to retrieve a list of open orders in MQL5? Corresponding to the OrderFields in MQ4(OrderSymbol(). OrderType(), etc. Basically what has to be done to process the MQL4 parsing of orders used in the Select
    ex
    Code:
        for(int i=0;i< OrdersTotal();i++)
             if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol() =="EURUSD")
             {
                   some code
             }
    Thanks in advance,

    Guillermo
    Reality is merely an illusion, albeit a very persistent one - Albert Einstein

  2. #2
    Administrator Jim's Avatar
    Join Date
    Apr 2010
    Location
    South West England
    Posts
    383
    Hi Guillermo,

    I'm afraid there isn't an easy answer to this one. MetaTrader 5 has added the new concept of "positions", and what you're thinking of as "open orders", are now referred to as "deals" in MQL5. With luck that's enough information to get you started, but the answer really depends on exactly what you are trying to achieve with your "some code" inside the if() statement. Can you provide any more details?

    You could also download the source code for the version of Ray the Random Robot that we entered in the MetaTrader 5 Automated Trading Championship. Firstly it's a working example of a multi-currency expert advisor. Also the MartingaleSize() function in there iterates over closed "deals", which might be some help to you.
    Reality is merely an illusion, albeit a very persistent one - Albert Einstein

  3. #3
    Junior Member gjrexach's Avatar
    Join Date
    Nov 2010
    Location
    Balneario Camboriu, Brasil
    Posts
    8
    Thank you kindly for your response, Jim.
    I am looking at some of the example code that appears on the site, but to answer your question: I am converting a version of the !xMeter EA which I have re-written.
    I am an IT consultant with over 40 years of experience in Mainframes. In order to get a better understanding of the psycology of OOP which is parallel driven(Events), whereas my background is serial programming, I want to use the new features of MQL5 such as structures, events, etc.. !xMeter as you probably know, parses throught the open orders in order to determine ratings and a "Grade" or "Score" if you will, regarding the Currencies. In doing so, I ran it through a conversion program I found on the net, but resolving the errors has become a problem because of this issue. Perhaps you could point me in some direction which might help? Nevertheless I am gratefull for what you have said so far! Again,thanks at lot for your prompt response!

  4. #4
    Administrator Jim's Avatar
    Join Date
    Apr 2010
    Location
    South West England
    Posts
    383
    Hi Guillermo,

    Quote Originally Posted by gjrexach View Post
    I am looking at some of the example code that appears on the site, but to answer your question: I am converting a version of the !xMeter EA which I have re-written.
    The currency strength meter?

    I am an IT consultant with over 40 years of experience in Mainframes.
    I have over 40 years programming experience too. However I ditched FORTRAN for assembler shortly after the 8080 was invented.

    In order to get a better understanding of the psycology of OOP which is parallel driven(Events), whereas my background is serial programming, I want to use the new features of MQL5 such as structures, events, etc..
    A whole new ball game! Unfortunately MQL5 is still sadly lacking in the events department.

    !xMeter as you probably know, parses throught the open orders in order to determine ratings and a "Grade" or "Score" if you will, regarding the Currencies. In doing so, I ran it through a conversion program I found on the net, but resolving the errors has become a problem because of this issue. Perhaps you could point me in some direction which might help? Nevertheless I am gratefull for what you have said so far! Again,thanks at lot for your prompt response!
    I'm not sure what your translator has been up to, but my MT4 version of the !xMeter doesn't iterate over open orders! Are we talking about the same thing?

    !xMeter.zip

    Cheers,

    Jim
    Reality is merely an illusion, albeit a very persistent one - Albert Einstein

  5. #5
    Junior Member gjrexach's Avatar
    Join Date
    Nov 2010
    Location
    Balneario Camboriu, Brasil
    Posts
    8
    That source you have is the original xMeter Indicator. It has been converted into an EA. I have tried to attach a copy of the source I'm converting, but have not been able to do so. Perhaps I do not have permission for doing attachments?

    Anyway, here is the link:

    http://www.forex-tsd.com/suggestions...xmeter-39.html
    Last edited by gjrexach; 11-23-2010 at 05:20 PM.

  6. #6
    Administrator Jim's Avatar
    Join Date
    Apr 2010
    Location
    South West England
    Posts
    383
    Hi Guillermo,

    Quote Originally Posted by gjrexach View Post
    That source you have is the original xMeter Indicator. It has been converted into an EA. I have tried to attach a copy of the source I'm converting, but have not been able to do so. Perhaps I do not have permission for doing attachments?
    You should have permission. Stan has been providing numerous attachments for example.

    Thanks for that. So the problem is you have a multi-currency EA, but MT4 doesn't do multi-currency backtests?

    Jim
    Reality is merely an illusion, albeit a very persistent one - Albert Einstein

  7. #7
    Administrator Jim's Avatar
    Join Date
    Apr 2010
    Location
    South West England
    Posts
    383
    Hi Guillermo,

    Quote Originally Posted by gjrexach View Post
    Hi, All!!
    As my first contribution to the site, I am attaching the MQ5 version of the !xMeter Indicator, as well as my MQ4toMQ5 Conversion Script, with its .mqh Include files.
    Thanks very much for what sounds like an extremely useful contribution to the MQL5 community codebase. I've just tried your converted MT5 xMeter indicator, and at first glance it looks like it does indeed do just the same job as the MT4 original.

    Given where we seem to be heading, I've also changed the title of this thread!

    Thanks again.

    Jim
    Reality is merely an illusion, albeit a very persistent one - Albert Einstein

  8. #8
    Junior Member gjrexach's Avatar
    Join Date
    Nov 2010
    Location
    Balneario Camboriu, Brasil
    Posts
    8
    Quick observation;
    The Pairs for establishing currency correlation are hardcoded in the !xMeter Indicator. Unfortunately, since MQ5 is still in demo, I have not been able to find a broker that includes all the currency pairs that are available on the MQ4 Platform. Therefore, you will need to change the !xMeter Indicator currency pairs that are available within your MQ5 platform. If you dont know how to do this, send me the list of MQ5 pairs offered by you Broker/Platform, so that I can send you the changes.

  9. #9
    Junior Member gjrexach's Avatar
    Join Date
    Nov 2010
    Location
    Balneario Camboriu, Brasil
    Posts
    8
    More Changes: 12/05/10
    A: OutOfSequence Array was causing some entries to be missed.
    B: Include "SetArrayAsTimeSeries" into OnCalculate for Indicators(As comments)
    C: Final message indicating Program type converted.

    I have resolved the RefreshRates issue and have incorporated the changes into the Conversion Program MQ4ToMQ5. Additional enhances have also been made.....

    Hi, All!!
    As my first contribution to the site, I am attaching the MQ5 version of the !xMeter Indicator, as well as my MQ4toMQ5 Conversion Script, with its .mqh Include files. I have also included my "enhanced" version of the MQ4 !xMeter Indicator and !xMeter EA which I ran through the Conversion Script. Although 95% of the the !xMeter Indicator was converted correctly, changes to the x,y location of the various objects were made manually, given the fact that the Chart coordinate system origin seemed to have changed from MQ4 to MQ5.
    The !xMeterEA.MQ5 is a Work-In-Progress, as I am new to OOPs, and need to get a better understanding of this environment. Be advised that this MQ5 EA does not have a clean compile as of yet. You will also notice that there are differences in the "Scoring" between the MQ4 and MQ5 !xMeter Indicators, which is, I believe, due to the fact that price data needs to be refreshed,i.e. RefreshRates() function, and this has not been worked out.
    I decided to write my own conversion Script, as the one that keiji coded(mq4tomq5_script_sample.mq4 from http://www.dr-ea.com/meta-blog/ would not handle tabs and was a bit difficult to follow the logic. The MQ4toMQ5 will detect what type of program it is, without the need of specifying it in the input parameters. Furthermore, it is entirely "Table-Driven", so that addition of new "Words" as well as functions is easily accomplished.
    I welcome any and all suggestions regarding improvements to any of the programs above, as well as assistance in the completion of the EA conversion.

    ==========Instructions for using the MQ4toMQ5 conversion Script==========
    1. Copy !xMeter.mq4 and !xMeterEA.mq4 to MQ4\....\Experts\files Directory.
    2. Copy and Compile MQ4toMQ5.mq4 to MQ4\...\Experts\Scripts Directory.
    3. Run the MQ4toMQ5 Script on these programs to get the conversion output in the same Directory.
    4. Transfer the output to the MQ5 Platform into their corresponding Directory.
    5. Copy the Include Folder Files into the MQ5 Include Directory.
    6. Compile the modules. (the !xMeter.mq5 that I have also included is ready to compile and run).
    Attached Files

  10. #10
    Junior Member gjrexach's Avatar
    Join Date
    Nov 2010
    Location
    Balneario Camboriu, Brasil
    Posts
    8

    New MQL5 Indicator Gadgets

    Hi All..
    I have attached 2 Indicator Gadgets which I have rewritten from MQL4:
    !clock
    !Sessions

    Enjoy
    Attached Files

+ Reply to Thread
Page 1 of 2 1 2 LastLast

Tags for this Thread

Posting Permissions

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