Discussion of article "Migrating from MQL4 to MQL5"

To add comments, please log in or register
MetaQuotes
Moderator
219141
MetaQuotes  

New article Migrating from MQL4 to MQL5 is published:

Many developers have accumulated a lot of indicators and trading strategies written in MQL4. To use them in Metatrader 5, they should be converted to MQL5. It's not so easy to rewrite all programs in MQL5. It would be much easier to convert them, if there were a translation-reference, and better with examples.

This article is a quick guide to MQL4 language functions, it will help you to migrate your programs from MQL4 to MQL5. For each MQL4 function (except trading functions) the description and MQL5 implementation are presented, it allows you to reduce the conversion time significantly. For convenience, the MQL4 functions are divided into groups, similar to MQL4 Reference.

Author: Sergey

Jinsong Zhang
14936
Jinsong Zhang  

How about OrderMagicNumber() ? Thanks

Rashid Umarov
Admin
16860
Rashid Umarov  
song_song:

How about OrderMagicNumber() ? Thanks

See  ORDER_MAGIC
Jinsong Zhang
14936
Jinsong Zhang  

iBarShift() is easy to use but iBarShiftMQL4() is quite complex. And so on...

Cym Act
32
Cym Act  

Why both "TickValue() and SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_VALUE)" always return "0"?!

wangdaqing
5
wangdaqing  

Hi, Rosh:

    I am very appreciated you said that:" I have plans to develop the MQL4 emulator, which will allow you to run your MQL4 programs in new MetaTrader 5 client terminal."

I am not a good programme designer but a trader. MQL5 is too difficult for me. 

    Waiting for your MQL4 emulator. TKS a Million!

    Best  Wishes for you.     

FinGeR
3915
FinGeR  

I found a mistake 

If only one chart window is open. Then the ID of this window of  =  -1 

int WindowHandleMQL4(string symbol,
                     int tf)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   long currChart,prevChart=ChartFirst();
   int i=0,limit=100;
   while(i<limit)
     {
      currChart=ChartNext(prevChart);
      if(currChart<0) break; 
      if(ChartSymbol(currChart)==symbol
         && ChartPeriod(currChart)==timeframe)
         return((int)currChart);
      prevChart=currChart;
      i++;
     }
   return(0);
  }

-

int WindowHandleMQL4(string symbol,
                     int tf)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   long currChart,prevChart=ChartFirst();
   int i=0,limit=100;
   while(i<limit)
     {
      currChart=ChartNext(prevChart);
        
      if( currChart<0 && currChart != -1) break;
        
      if(ChartSymbol(currChart)==symbol
        && ChartPeriod(currChart)==timeframe)
         
         return((int)currChart);
      prevChart=currChart;
      i++;
     }
   return(0);
  }

 

williamwong
299
williamwong  

Also be careful on the precedence.  I spent half a day debugging a logic and found that the precedence of && and || are different between MQL4 (|| first) and MQL5 (&& first).  So in migrating from MQL4 to MQL5, make sure you search through all the comparison expressions.

Migrating from MQL4 to MQL5
  • 2010.05.17
  • Sergey Pavlov
  • www.mql5.com
This article is a quick guide to MQL4 language functions, it will help you to migrate your programs from MQL4 to MQL5. For each MQL4 function (except trading functions) the description and MQL5 implementation are presented, it allows you to reduce the conversion time significantly. For convenience, the MQL4 functions are divided into groups, similar to MQL4 Reference.
Rashid Umarov
Admin
16860
Rashid Umarov  
williamwong:

Also be careful on the precedence.  I spent half a day debugging a logic and found that the precedence of && and || are different between MQL4 (|| first) and MQL5 (&& first).  So in migrating from MQL4 to MQL5, make sure you search through all the comparison expressions.

You are right. See Precedence Rules:

Each group of operations in the table has the same priority. The higher the priority of operations is, the higher it is position of the group in the table. The precedence rules determine the grouping of operations and operands.

Attention: Precedence of operations in the MQL5 language corresponds to the priority adopted in C++, and differs from the priority given in the MQL4 language.


FinGeR
3915
FinGeR  
FinGeR:

I found a mistake 

If only one chart window is open. Then the ID of this window of  =  -1 

-

 

My mistake, it is true. :)

int WindowHandleMQL4(string symbol,
                     int tf)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   long currChart,prevChart=ChartFirst();
   int i=0,limit=100;
   while(i<limit)
     {
      
         currChart=ChartNext(prevChart);
      if(i==0)currChart=prevChart; // Wenn nur ein Chartfenster offen ist
  
      if( currChart<0) break;
        
      if(ChartSymbol(currChart)==symbol
        && ChartPeriod(currChart)==timeframe)
        
         return((int)currChart);
      prevChart=currChart;
      i++;
     }
   return(0);
  }
nonor
59
nonor  

Hello


I will be pleased to know if all these functions have been validated, I didn't succed

to make the function "CopyBufferMQL4" working.


Thank you


Noel


To add comments, please log in or register