Download MetaTrader 5
To add comments, please log in or register
Does your signal already have a lot of of subscribers? It's time to think about the paid subscription!
MetaQuotes Software Corp.
Moderator
180310
MetaQuotes Software Corp. 2010.05.17 13:32 

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
15351
Jinsong Zhang 2010.06.24 11:19  

How about OrderMagicNumber() ? Thanks

Rashid Umarov
Admin
11709
Rashid Umarov 2010.06.24 11:38  
song_song:

How about OrderMagicNumber() ? Thanks

See  ORDER_MAGIC
Jinsong Zhang
15351
Jinsong Zhang 2010.07.01 11:13  

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

Cym Act
192
Cym Act 2010.07.01 13:29  

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

wangdaqing
5
wangdaqing 2010.07.13 03:01  

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.     

Alexander Piechotta
6933
Alexander Piechotta 2010.09.15 23:22  

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
631
williamwong 2010.09.16 05:59  

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
11709
Rashid Umarov 2010.09.16 06:57  
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.


Alexander Piechotta
6933
Alexander Piechotta 2010.09.30 23:22  
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
89
nonor 2010.12.09 17:25  

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


/ /123
To add comments, please log in or register