Download MetaTrader 5

EA runs slow on one platform but other EAs run fast.

To add comments, please log in or register
Paul
632
Paul  
I have been developing an EA but after a few backtest runs it now goes really slowly. It runs fast on my other computer with the same broker like it used to do where it runs slow now. It has nothing to do with my EA code and I have cleared all the log files, caches or any other files related to the EA but no change so I reinstalled MT4 but still runs slow. Equally it can't be the history file since other programs run fast over the same dates so I don't know where to look for the problem. This is really irritating since it takes minutes to run a backtest that should only take 15 seconds. Any ideas?
Paul
632
Paul  
A completely new install of MT4 has made the EA run fast on backtest again then I copied the eurusd.hst file across from the slow platform and it made my Ea run slow again. However I deleted the history file and my EA still runs slow so what file is left that holds the corruption? I deleted the .raw files that were in the history directory but leaving the directory empty but it still runs slow.
whroeder1
15719
whroeder1  
Ruptor:  It has nothing to do with my EA code and I have cleared all the log files,

It has to do with your setting
Paul
632
Paul  
WHRoeder:

It has to do with your setting
Thanks for the suggestion but I am not using visual mode. I go by how long the progress bar takes to cross the screen. Between slow and fast it is 3 minutes or 15 seconds respectively.
Paul
632
Paul  

I found a bug in the compiler but fixing the code has still not made it run fast again. For some reason the compiler thinks this code is correct but clearly it isn't. The compiler has missed the "vspread="  and a semicolon. Not sure why the colours are messed up in the code segment. Another strange thing is that the original EA now runs fast without doing any changes but the copy that I was going to mess around with to find the slow problem is still running slow.

int DecideEntry(){
 static double hilvl,lolvl;
 static int initok=0,togin=1;
 int trdun,trdseq,vspread;
   
  trdseq= PKamaOP(periodAMA,nfast,nslow,G,dK);
  if(trdseq!=0){
    togin=0;
    vspread = 
    hilvl=kama;
//    hilvl=iMA(NULL, 0, 3, 0, MODE_SMA, PRICE_OPEN, 0);
    lolvl=hilvl-pnt*Level;
    hilvl=hilvl+pnt*(Level+(Ask-Bid)/2);
//    Comment("Seq1 HiL= ",DoubleToString(hilvl),"  LoL= ",DoubleToString(lolvl),"  vspread= ",(vspread*pnt/2));
ffoorr
1089
ffoorr  

The problem could be with your indicators, according the way they are coded,


either if an extern is missing or if there is an additional extern, the icustom could work, but slow the EA,

 

try to replace this

trdseq= PKamaOP(periodAMA,nfast,nslow,G,dK);

with this

trdseq= iCustom( NULL,0,"name_of_kama", periodAMA,nfast,nslow,G,dK, buffer, index );

following the kama you use

Paul
632
Paul  
I have two EAs called Kama and KamaSolo because Kama that calls external indicators went slow so I removed the external indicators and coded the indicator PKamaOP as an internal procedure to see if it was something to do with calling the external indicator. The result was that both EAs were running slow then after reinstalling MT4 in a different directory it appears the EA with external indicator calls, Kama, now runs fast again but KamaSolo is still slow. I have seen this happen over the years with other EAs where after an edit they run slow then at some point after further edits they run fast again so this smacks of yet another compiler bug or maybe more precisely an interpreter bug. It can't be my code since I never edited Kama between reinstalling a new MT4 and suddenly it runs fast again but KamaSolo stays slow so it has to be a platform/system problem. Both EAs give exactly the same results with the same dates on backtests. It looks like the slow one is going around loops that take a 1000 times longer or something but I don't have a clue what is going on.
Paul
632
Paul  

Some more information after a brain wave & the observation that the progress bar gradually went slower towards the end of a backtest. Since the progress bar slows down slightly it must be that the length of data must be part of the problem. By editing the indicator so it only goes back a couple of bars further than period of the longest MA it uses the EA now runs very fast. What doesn't make sense is that the trigger that makes the EA go slow does not change the number of times the indicator is called it just does a bit of extra code when in a trade. Could it be my poor little computer doesn't have enough memory with 2 GB?

Another question in relation to the bars seen by the indicator is does the indicator always use all the bars from the start of a backtest? In normal operation on a live chart I know the indicator code only uses the latest tick and does not load all the bars but in a backtest it can't work like that because it is reloaded on every call. Therefore indicators have to be specially written for use in EAs so they only load the bars they need.

Alain Verleyen
Moderator
32817
Alain Verleyen  
Ruptor:
I have been developing an EA but after a few backtest runs it now goes really slowly. It runs fast on my other computer with the same broker like it used to do where it runs slow now. It has nothing to do with my EA code and I have cleared all the log files, caches or any other files related to the EA but no change so I reinstalled MT4 but still runs slow. Equally it can't be the history file since other programs run fast over the same dates so I don't know where to look for the problem. This is really irritating since it takes minutes to run a backtest that should only take 15 seconds. Any ideas?
Of course it comes from your code.
Ruptor:

I found a bug in the compiler but fixing the code has still not made it run fast again. For some reason the compiler thinks this code is correct but clearly it isn't. The compiler has missed the "vspread="  and a semicolon. Not sure why the colours are messed up in the code segment. Another strange thing is that the original EA now runs fast without doing any changes but the copy that I was going to mess around with to find the slow problem is still running slow.

That's not a bug, this code is valid. The compiler can't detect logical errors.

Please show your code if you need help.

ydrol
590
ydrol  

Find the bottleneck using the current GMT time and Print. To get the real world GMT time during backtesting  (ie. OS/PC time not the modelled time)  use the output from GlobalVariableSet() e.g.

//untested/uncompiled 

datetime logtime(string msg)

datetime now = GlobalVariableSet(WindowExpertName()+"#time");

Print(TimeToStr(now,-1),msg);

There might be a better way? 

Paul
632
Paul  
Please read my last post guys where I have reached a conclusion that shows a quirk in the MT4 interpreter when running. My inefficient code shows the problem but it shouldn't create it or be there in the first place. Is it because I only have 2GB that it occurs?
12
To add comments, please log in or register