Download MetaTrader 5
To add comments, please log in or register
Create Forum topics and improve your rating!
Ehsan Tavakoli
164
Ehsan Tavakoli 2016.11.19 13:35 

Hi . i make this cod for get rates of all symbol in marketwatch

But when number of symbol in market watch is too much ( 300 symbol ) my CPU Be filled slowly & empty slowly

for example any copyRates use 2% of my CPU and i think after any CopyRates my CPU must be empty and then refill another 2%

But not like that . in process any 2% sum whit before 2% and full my CPU . And after finished loop my CPU not empty immediately and fast 

I don't want use sleep() between any copyrates for solve my problem. 

I want do fast and light.  How i can do that ?

Than you for your guide . 

(This Is My CPU In Process) 

 This is my CPU in Process time

int    TotallSymbol ,
       BarNum  ;  
string Symboll ;

struct MqlRatesAll
{
   MqlRates Rates[];
   string   Name;
};
MqlRatesAll SymList[];
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

  
   TotallSymbol = SymbolsTotal( true );
   ArrayResize( SymList , TotallSymbol );
  
   for( int i=0 ; i<TotallSymbol ; i++ )
      {
        Symboll = SymbolName( i , true );
        CopyRates( Symboll , PERIOD_D1 , 0 , 10 , SymList[i].Rates );
        SymList[i].Name = Symboll;
      }

  
//---
   return(0);
  } 

Marco vd Heijden
Moderator
4504
Marco vd Heijden 2016.11.19 13:42  

If you want it to drop, you will have to make up for it in speed.

So it will take slightly longer.

For example when you run the mechanism in OnMillisecondTimer() function you can set the timing interval by EventSetMillisecondTimer();

Then you simply ++i on every timer cycle in stead of in that loop so you have to adjust the code a bit.

Carl Schreiber
6389
Carl Schreiber 2016.11.19 14:16  
To me looks as if MQL5 is able to start several (300) independent threads for CopyRates. Have you looked at the single threads and their 'distribution' on the kernels??
Alain Verleyen
Moderator
30243
Alain Verleyen 2016.11.19 14:27  
  • Are you sure this CPU usage is due to MT5 ?
  • It's not a good idea to execute such code in OnInit(), initialization should be fast.
  • I tried your code, 328 symbols, it took 2 minutes 30. The CPU usage was from 24% when it starts to maximum 41% (I have Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz, and a lot of other applications running)
Alain Verleyen
Moderator
30243
Alain Verleyen 2016.11.19 14:33  
Carl Schreiber:
To me looks as if MQL5 is able to start several (300) independent threads for CopyRates. Have you looked at the single threads and their 'distribution' on the kernels??
Right (almost). On mty test with 328 symbols, the number of threads go from 31 up to 234 maximum.
Ehsan Tavakoli
164
Ehsan Tavakoli 2016.11.19 16:18  
Marco vd Heijden:

If you want it to drop, you will have to make up for it in speed.

So it will take slightly longer.

For example when you run the mechanism in OnMillisecondTimer() function you can set the timing interval by EventSetMillisecondTimer();

Then you simply ++i on every timer cycle in stead of in that loop so you have to adjust the code a bit.

No difference . I test in OnTimeEvent before this cod . but still have that problem
Ehsan Tavakoli
164
Ehsan Tavakoli 2016.11.19 16:20  
Carl Schreiber:
To me looks as if MQL5 is able to start several (300) independent threads for CopyRates. Have you looked at the single threads and their 'distribution' on the kernels??
For me number of threads go from 1025 up to 1260 . by 250 symbol
Ehsan Tavakoli
164
Ehsan Tavakoli 2016.11.19 16:32  
Alain Verleyen:
  • Are you sure this CPU usage is due to MT5 ?
  • It's not a good idea to execute such code in OnInit(), initialization should be fast.
  • I tried your code, 328 symbols, it took 2 minutes 30. The CPU usage was from 24% when it starts to maximum 41% (I have Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz, and a lot of other applications running)

Yes this is MT5 usage .

You are Right  . I put in OnInit just for run and test 

scale of usage Percent  depend to CPU power.

But amount of usage not my problem.

Why after any run copyrates and CPU occupy then end copyrates , CPU not release ?

It is My problem : How i release CPU usage after any run copyRates ????

When i can release CPU after any copyRates , so i can solve this problem

Alain Verleyen
Moderator
30243
Alain Verleyen 2016.11.19 18:07  
Ehsan Tavakoli:

Yes this is MT5 usage .

You are Right  . I put in OnInit just for run and test 

scale of usage Percent  depend to CPU power.

But amount of usage not my problem.

Why after any run copyrates and CPU occupy then end copyrates , CPU not release ?

It is My problem : How i release CPU usage after any run copyRates ????

When i can release CPU after any copyRates , so i can solve this problem

You should talk to ServiceDesk.
Ehsan Tavakoli
164
Ehsan Tavakoli 2016.11.21 12:06  
Alain Verleyen:
You should talk to ServiceDesk.
Tanks.
Trinh Dat
36676
Trinh Dat 2016.11.21 13:37  
better try close all other chart, EA, indicator and try again, then show your processes.
/ /123
To add comments, please log in or register