What are your computer's technical specs?
Use a sleep function within the cycle. It will reduce your processor usage a lot.
while(IsStopped()==false) { Sleep(100); }
- Use
while( !IsStopped() ){ : if (IsTesting()) break; Sleep(100); RefreshRates(); }
Since you must return in the tester. - Add a Sleep
- Add a RefreshRates after the Sleep to see new values.
- Why? Just return and wait for the new tick.
Hello, everyone,
I met a problem while coding in MT4. It is just a simple script that caused the CPU occupied at 100% percent.
I was wondering whether you would be kind enough to enlighten me what is going wrong.
Thank you so much!
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
while(IsStopped()==false)
{}
I think the question has been satisfactorily answered in the preceding posts. I would just comment that you have initially called it a script but the code comments say it is an EA. You have to be a bit careful with the exact terminology you use since these are two different pieces of code, run from different directories, and perform quite differently, even though the code appears to be similar.
For an EA, where the start function is called for every new tick (provided the run from the previous tick has completed), there is little point in using the IsStopped function. When EA operation is disabled the next incoming tick will not generate a call to the start routine anyway. This IsStopped function is very useful for a script which only runs once. If the script needs to be temporarily stopped then the IsStopped function is ideal. In this case the only problem was the lack of a sleep function within the while loop, as mentioned by others. I would not put a RefreshRates within the while loop. That just wastes processing time for no reason, but you do need a RefreshRates as soon as you exit the while loop.
I would not put a RefreshRates within the while loop. That just wastes processing time for no reason, but you do need a RefreshRates as soon as you exit the while loop.
That depends on the purpose of the loop. What else is being tested inside. Bid and Ask will not change between calls to start() unless RefreshRates() is called. If the code is looking at the those, you must call RR. If the code is looking at a mutex for example then the call can be outside the loop.
I did ask

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello, everyone,
I met a problem while coding in MT4. It is just a simple script that caused the CPU occupied at 100% percent.
I was wondering whether you would be kind enough to enlighten me what is going wrong.
Thank you so much!
//+------------------------------------------------------------------+
//| mySQLTester.mq4 |
//| Copyright ?2006, GP2X |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2006, GP2X"
#property link ""
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
while(IsStopped()==false)
{}
//----
return(0);
}
//+------------------------------------------------------------------+