Download MetaTrader 5

The Efficiency of MQL5 Indicators

To add comments, please log in or register
billbook
38
billbook  

I used many iMACD in MQL4, almost 100; I used only the last data of the iMACD; and the EA runs quickly ( no longer than 3 seconds), use about 1.1G ram ; 

yesterday I rewrote the EA in MQL5, it runs, very slowly,  waiting 5 minutes ,and no reply, used more than 2.8G ram;  so I cut down  the most of iMACD indicators to test, it runs more than 2 minutes, used more than 1.8G ram. 

so I guess , maybe the buffer-handle method slow down the calculation; can you settle the problem?

Dua Yong Rew
5447
Dua Yong Rew  
billbook:

I used many iMACD in MQL4, almost 100; I used only the last data of the iMACD; and the EA runs quickly ( no longer than 3 seconds), use about 1.1G ram ; 

yesterday I rewrote the EA in MQL5, it runs, very slowly,  waiting 5 minutes ,and no reply, used more than 2.8G ram;  so I cut down  the most of iMACD indicators to test, it runs more than 2 minutes, used more than 1.8G ram. 

so I guess , maybe the buffer-handle method slow down the calculation; can you settle the problem?

Show us the code to access your problem
Alain Verleyen
Moderator
31596
Alain Verleyen  
billbook:

I used many iMACD in MQL4, almost 100; I used only the last data of the iMACD; and the EA runs quickly ( no longer than 3 seconds), use about 1.1G ram ; 

yesterday I rewrote the EA in MQL5, it runs, very slowly,  waiting 5 minutes ,and no reply, used more than 2.8G ram;  so I cut down  the most of iMACD indicators to test, it runs more than 2 minutes, used more than 1.8G ram. 

so I guess , maybe the buffer-handle method slow down the calculation; can you settle the problem?

Certainly not, mql5 work with indicators is faster than mql4. Probably a coding error or at least inefficiency.
billbook
38
billbook  
angevoyageur:
Certainly not, mql5 work with indicators is faster than mql4. Probably a coding error or at least inefficiency.

thanks for you quickly reply;

 

the codes:

//===================================================

#import "excellinkW.dll"  

   int ExcelStart(string,int);

   int ExcelEnd();   

   int ExcelSaveFile(string);

   int ExcelPutString(int,int,int,string);

   string ExcelGetCalc(int,int,int);

   string ExcelGetString(int,int,int);

#import

input string filename="C:\\FX_trend_4T.xls";

int myExcel=0;

string time1;

double m2[2], m4[2], m8[2];

int h2, h4, h8;

//+------------------------------------------------------------------+

//| Expert initialization function                                   |

//+------------------------------------------------------------------+

int OnInit()

  {

//--- create timer

   EventSetTimer(60);

   myExcel = ExcelStart(filename,1);

   if (myExcel>=0) Print ("EXCEL-OK");

//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Expert deinitialization function                                 |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

  {

//--- destroy timer

   EventKillTimer();

   ExcelSaveFile(filename);

   ExcelEnd();      

  }

//+------------------------------------------------------------------+

//| Timer function                                                   |

//+------------------------------------------------------------------+

void OnTimer()

  {

//---

   time1=TimeToString(TimeLocal(),TIME_DATE|TIME_MINUTES);

   ExcelPutString(1,2,15,time1); //time

   MR248_set(PERIOD_M5 , 1, 2);

   MR248_set(PERIOD_M15, 1, 5);

   MR248_set(PERIOD_H4 , 1, 8);

   MR248_set(PERIOD_D1 , 1,11);

   PlaySound("tick.wav");

   if (ExcelGetString(1,1,14)=="ALARM") PlaySound("expert.wav");

  }

void MR248(string FX, ENUM_TIMEFRAMES T, int page, int row, int col) 

   {

   

    h2=iMACD( FX, T,  48, 104, 9, PRICE_CLOSE);

    h4=iMACD( FX, T,  96, 208, 9, PRICE_CLOSE);

    h8=iMACD( FX, T, 192, 516, 9, PRICE_CLOSE);

    CopyBuffer(h2,0,0,2,m2);

    CopyBuffer(h4,0,0,2,m4);

    CopyBuffer(h8,0,0,2,m8);

    IndicatorRelease(h2);

    IndicatorRelease(h4);

    IndicatorRelease(h8);

    ExcelPutString(page,row,col,DoubleToString(MathRound((m2[1]-m2[0]+m4[1]-m4[0]+m8[1]-m8[0])*10000000/SymbolInfoDouble(FX,SYMBOL_BID)),0));

   }

void MR248_set(ENUM_TIMEFRAMES T, int page, int col)

   {

    MR248("USDJPY",T,page,1 ,col);

    MR248("USDCHF",T,page,2 ,col);

    MR248("USDCAD",T,page,3 ,col);

    MR248("EURUSD",T,page,4 ,col);

    MR248("EURJPY",T,page,5 ,col);

    MR248("EURCHF",T,page,6 ,col);

    MR248("EURGBP",T,page,7 ,col);

    MR248("EURCAD",T,page,8 ,col);

    MR248("EURAUD",T,page,9 ,col);

    MR248("EURNZD",T,page,10,col);

    MR248("CHFJPY",T,page,11,col);

    MR248("GBPUSD",T,page,12,col);

    MR248("GBPJPY",T,page,13,col);

    MR248("GBPCHF",T,page,14,col);

    MR248("GBPCAD",T,page,15,col);

    MR248("GBPAUD",T,page,16,col);

    MR248("GBPNZD",T,page,17,col);

    MR248("CADJPY",T,page,18,col);

    MR248("CADCHF",T,page,19,col);

    MR248("AUDUSD",T,page,20,col);

    MR248("AUDJPY",T,page,21,col);

    MR248("AUDCHF",T,page,22,col);

    MR248("AUDCAD",T,page,23,col);

    MR248("AUDNZD",T,page,24,col);

    MR248("NZDUSD",T,page,25,col);

    MR248("NZDJPY",T,page,26,col);

    MR248("NZDCHF",T,page,27,col);

    MR248("NZDCAD",T,page,28,col);

   }

//+------------------------------------------------------------------+
billbook
38
billbook  
angevoyageur :
当然不是,用MQL5指标的工作比MQL4更快。大概一个编码错误,或者至少低效率。
at least the MQL5 indicators occupy much more RAM than MQL4.
Alain Verleyen
Moderator
31596
Alain Verleyen  
billbook:
at least the MQL5 indicators occupy much more RAM than MQL4.

Forum on trading, automated trading systems and testing trading strategies


Hello,

Please use the SRC button when you post code. Thank you.


This time, I edited it for you.

I will check your code when I have some time, however I don't have the excellinkW.dll so I can't run it.
billbook
38
billbook  
angevoyageur:
I will check your code when I have some time, however I don't have the excellinkW.dll so I can't run it.
thank you for your work!  
billbook
38
billbook  
billbook:
thank you for your work!  
//===================================================
#import "excellinkW.dll"  
   int ExcelStart(string,int);
   int ExcelEnd();   
   int ExcelSaveFile(string);
   int ExcelPutString(int,int,int,string);
   string ExcelGetCalc(int,int,int);
   string ExcelGetString(int,int,int);
#import
input string filename="C:\\FX_trend_4T.xls";
int myExcel=0;
string time1;
double m2[2], m4[2], m8[2];
int h2, h4, h8;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   EventSetTimer(60);
   myExcel = ExcelStart(filename,1);
   if (myExcel>=0) Print ("EXCEL-OK");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();
   ExcelSaveFile(filename);
   ExcelEnd();      
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   time1=TimeToString(TimeLocal(),TIME_DATE|TIME_MINUTES);
   ExcelPutString(1,2,15,time1); //time
   MR248_set(PERIOD_M5 , 1, 2);
   MR248_set(PERIOD_M15, 1, 5);
   MR248_set(PERIOD_H4 , 1, 8);
   MR248_set(PERIOD_D1 , 1,11);
   PlaySound("tick.wav");
   if (ExcelGetString(1,1,14)=="ALARM") PlaySound("expert.wav");
  }

void MR248(string FX, ENUM_TIMEFRAMES T, int page, int row, int col) 
   {
    h2=iMACD( FX, T,  48, 104, 9, PRICE_CLOSE);
    h4=iMACD( FX, T,  96, 208, 9, PRICE_CLOSE);
    h8=iMACD( FX, T, 192, 516, 9, PRICE_CLOSE);
    CopyBuffer(h2,0,0,2,m2);
    CopyBuffer(h4,0,0,2,m4);
    CopyBuffer(h8,0,0,2,m8);
    IndicatorRelease(h2);
    IndicatorRelease(h4);
    IndicatorRelease(h8);
    ExcelPutString(page,row,col,DoubleToString(MathRound((m2[1]-m2[0]+m4[1]-m4[0]+m8[1]-m8[0])*10000000/SymbolInfoDouble

(FX,SYMBOL_BID)),0));
   }

void MR248_set(ENUM_TIMEFRAMES T, int page, int col)
   {
    MR248("USDJPY",T,page,1 ,col);
    MR248("USDCHF",T,page,2 ,col);
    MR248("USDCAD",T,page,3 ,col);
    MR248("EURUSD",T,page,4 ,col);
    MR248("EURJPY",T,page,5 ,col);
    MR248("EURCHF",T,page,6 ,col);
    MR248("EURGBP",T,page,7 ,col);
    MR248("EURCAD",T,page,8 ,col);
    MR248("EURAUD",T,page,9 ,col);
    MR248("EURNZD",T,page,10,col);
    MR248("CHFJPY",T,page,11,col);
    MR248("GBPUSD",T,page,12,col);
    MR248("GBPJPY",T,page,13,col);
    MR248("GBPCHF",T,page,14,col);
    MR248("GBPCAD",T,page,15,col);
    MR248("GBPAUD",T,page,16,col);
    MR248("GBPNZD",T,page,17,col);
    MR248("CADJPY",T,page,18,col);
    MR248("CADCHF",T,page,19,col);
    MR248("AUDUSD",T,page,20,col);
    MR248("AUDJPY",T,page,21,col);
    MR248("AUDCHF",T,page,22,col);
    MR248("AUDCAD",T,page,23,col);
    MR248("AUDNZD",T,page,24,col);
    MR248("NZDUSD",T,page,25,col);
    MR248("NZDJPY",T,page,26,col);
    MR248("NZDCHF",T,page,27,col);
    MR248("NZDCAD",T,page,28,col);
   }

//+------------------------------------------------------------------+
billbook
38
billbook  
billbook:
the dll
I tried for many times ,but can't attach the dll...how can I do this?
billbook
38
billbook  

ZIP

Files:
Alain Verleyen
Moderator
31596
Alain Verleyen  
billbook:

I used many iMACD in MQL4, almost 100; I used only the last data of the iMACD; and the EA runs quickly ( no longer than 3 seconds), use about 1.1G ram ; 

yesterday I rewrote the EA in MQL5, it runs, very slowly,  waiting 5 minutes ,and no reply, used more than 2.8G ram;  so I cut down  the most of iMACD indicators to test, it runs more than 2 minutes, used more than 1.8G ram. 

so I guess , maybe the buffer-handle method slow down the calculation; can you settle the problem?

Ok, I have some time today. I already see to your code isn't written efficiently, but before saying more, can you tell me the running condition to reproduce what you report ?

What you posted is the complete version or the cut version ? Which symbol/timeframe are you using ? Is it on a live chart or a backtest ? If a backtest which settings (dates, ...) ?

Also it seems you are using the 32-bit version of mql5, can you confirm ?

2014.04.07 16:18:09.486    22932    xxxx\MQL5\Libraries\excellinkW.dll' is not 64-bit version

12
To add comments, please log in or register