How i can get all symbol rates of market watch Without full my CPU

 

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);
  } 

 

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.

 
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??
 
  • 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)
 
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.
 
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
 
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
 
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

 
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.
 
Alain Verleyen:
You should talk to ServiceDesk.
Tanks.
 
better try close all other chart, EA, indicator and try again, then show your processes.
Reason: