Download MetaTrader 5
To add comments, please log in or register
Do you have idle PCs? Connect them to MQL5 Cloud Network and earn money!
manuel_campelo
45
manuel_campelo 2015.04.27 08:39 

   Hi, everyone.

   I'm trying to write an EA that uses several Strategies at the same time and using different Symbols & Timeframes in combination. So far I've written almost everything but the Strategies themselves and everything was alright by now but, when I wrote this function:

void Trade(){  
   bool check=true;
   for (int i=0;i<ArrayRange(TimeFrames,0);i++) {
      long nowtime=iTime(Sym_Name,TimeFrames[i],0);
      if (check && BarBegin[Sym_Code][i]!=nowtime) { //Means new Bar has been formed for this Symbol & TF
         //if (StrategyNameThaWaitForNewBar_Activated) {StrategyNameThatWaitForNewBar(i);} //Call Strategy Function searching for new trades
         BarBegin[Sym_Code][i]=nowtime; //Save new value of BarBegin.
      } else {
         check=false;
      }
      //@@@ Call Strategies that don't wait and do a continuous search for new trades.
      //if (StrategyNameThatDoesntWaitForNewBar_Activated) {StrategyNameThatDoesntWaitForNewBar(i);} //Call Strategy Function searching for new trades  
   }  
}

Terminal began to eat resources as much as 150.000 kb per i value. The code I ran is exactly the same than the one I wrote here (that means that the function only loops and does nothing else than that).

Does anyone know why it kills my memory in less than 10 seconds? Could it be an issue with iTime call? If so, does anyone know how to check for a new bar formed? I read different fora and I found several approaches but ussiong only one Symbol and one TF but nothing related to multisymbol and multitimeframes.

   Notes:

BarBegin --> long Array with 150 symbols in 1st Dimension and 8 timeframes in the second one (8 bytes * 150 * 8 <10 kb)

TimeFrames --> int Array with the value of those 8 timeframes (1,15,30,60,240...)

StrategyNameThatDoesntWaitForNewBar(i) && StrategyNameThatWaitForNewBar(i) will be Strategies' functions that search for a signal to open/close trades and save them into an array, after leaving Trades other functions will Open, Close or Modify those trades.

Ovo Cz
2955
Ovo Cz 2015.04.27 08:53  
Mafecaro:

   Hi, everyone.

   I'm trying to write an EA that uses several Strategies at the same time and using different Symbols & Timeframes in combination. So far I've written almost everything but the Strategies themselves and everything was alright by now but, when I wrote this function:

void Trade(){  
   bool check=true;
   for (int i=0;i<ArrayRange(TimeFrames,0);i++) {
      long nowtime=iTime(Sym_Name,TimeFrames[i],0);
      if (check && BarBegin[Sym_Code][i]!=nowtime) { //Means new Bar has been formed for this Symbol & TF
         //if (StrategyNameThaWaitForNewBar_Activated){StrategyNameThatWaitForNewBar(i);} //Call Strategy Functionsearching for new trades
         BarBegin[Sym_Code][i]=nowtime; //Save new value of BarBegin.
      } else {
         check=false;
      }
      //@@@ Call Strategies that don't wait and do a continuous search for new trades.
      //if (StrategyNameThatDoesntWaitForNewBar_Activated) {StrategyNameThatDoesntWaitForNewBar(i);} //Call Strategy Function searching for new trades  
   }  
   //Modify_Orders();  //Modify already openned orders.

}

Terminal began to eat resources as much as 150.000 kb per i value. The code I ran is exactly the same than the one I wrote here (that means that the function only loops and does nothing else than that).

Does anyone know why it kills my memory in less than 10 seconds? Could it be an issue with iTime call? If so, does anyone know how to check for a new bar formed? I read different fora and I found several approaches but ussiong only one Symbol and one TF but nothing related to multisymbol and multitimeframes.

BarBegin --> long Array with 150 symbols in 1st Dimension and 8 timeframes in the second one (8 bytes * 150 * 8 <10 kb)

TimeFrames --> int Array with the value of those 8 timeframes (1,15,30,60,240...)

I already reported this issue to the Service Desk on July 25, 2014 (#1045322), still open and no reply from Metaquotes. 

 

ArrayCopyRates - virtual copy allocates too much memory
Errors, MetaTrader 4 / MQL4, Open, Start: 2014.07.25 15:20, #1045322

Terminal Build 670.

Besides ArrayCopyRates it applies to all functions that can access other timeframes. 

 

Defect: 

Currently, when a value from other timeframe is accessed for the first time, a block of memory is allocated. This block is never released until the indicator unloads.  When additional instance of the same indicator is attached to the chart, a new block of memory is allocated with accessing other timeframe values.

Even a simple indicator can hit memory limits soon, supposing the candle history is large and the indicator is used multiple times.

FreeArray has no effect on memory when applied to array loaded by ArrayCopyRates

The help file reads like:  ArrayCopyRates - ...it performs the virtual data copying to the array of MqlRates type.

Expected behaviour: 

My expectations is, that the copy is virtual once the array gets created, without additional memory allocations.  

whroeder1
13597
whroeder1 2015.04.27 12:31  
    1. Don't paste code
      Play video
      Please edit your post.
      For large amounts of code, attach it.

    2. iTime returns a datetime not a long. Variable names should be choses carefully, so the code can be read aloud and be meaningful in English. Check says nothing. isNewBar would be better.
         bool check=true;
         for (int i=0;i<ArrayRange(TimeFrames,0);i++) {
            long nowtime=iTime(Sym_Name,TimeFrames[i],0);
            if (check && BarBegin[Sym_Code][i]!=nowtime) { //Means new Bar has been formed for this Symbol & TF
               BarBegin[Sym_Code][i]=nowtime; //Save new value of BarBegin.
            } else {
               check=false;
            }
         }
      Best would be to just exit the loop, on the first non-newBar
      // bool check=true;                            
         for (int i=0;i<ArrayRange(TimeFrames,0);i++) {
            datetime nowtime=iTime(Sym_Name,TimeFrames[i],0);
            if (/*check &&*/ BarBegin[Sym_Code][i]!=nowtime) { //Means new Bar has been formed for this Symbol & TF
               BarBegin[Sym_Code][i]=nowtime; //Save new value of BarBegin.
            } else break; //{          check=false; }
         }
    3. Terminal began to eat resources as much as 150.000 kb per i value. ... My expectations is, that the copy is virtual once the array gets created, without additional memory allocations. 
      And that is likely what it does. Your problem is likely not ArrayCopyRates, but the fact that you open seven charts (M1 .. MN1) with tools -> options -> charts -> Maximum bars in chart set to a high number (not in history.) Reduce to something reasonable (like 65000) and retry.
Ovo Cz
2955
Ovo Cz 2015.04.27 14:38  
BTW what brokers do you have that you need to trim candles to 65k? I have never seen more.
whroeder1
13597
whroeder1 2015.04.27 21:46  
Download load and install M1 history [2015-2000] * 5days/wk * 52 wk/year * 1440 M1 bars/day and you'll have some 5 million bars.
Ovo Cz
2955
Ovo Cz 2015.04.28 06:08  
WHRoeder:
Download load and install M1 history [2015-2000] * 5days/wk * 52 wk/year * 1440 M1 bars/day and you'll have some 5 million bars.
Anyway, 65k candles per timeframe runs out of resources pretty fast as well.
whroeder1
13597
whroeder1 2015.04.28 13:19  
Ovo: Anyway, 65k candles per timeframe runs out of resources pretty fast as well.
LOL: 65K * 56(8bytes*OHLCTVV) * 10(pairs)= 35.5 MB. Are you running on a 512K Macintosh (1982) with 10MB hard drive, a more likely a PC with multiple GB of RAM?
/
To add comments, please log in or register