Re: MT4 Charts Do Not Trade Equally
Without confirmation from MetaQuotes that MT5 doesn't have the same problem, I'm not sure it is worth the time and effort to go down that path. My guess this most likely is a threading issue -- and it may be that MetaQuotes also has to deal with it in MT5. From MetaQuotes perspective, the most important thing is MT4 never crashes or hangs due to a mis-behaved indicator or EA. This is why indicators get removed if their OnCalculate() takes too long. And now I suspect MT4 throttles charts by withholding ticks. As we joke, everything is a trade-off. They think it is preferable to miss trades if it helps to protect MT4 and keep it up and running. And, of course, though I write this as a statement, I'm just guessing -- I do not know for sure this is the case.
Some additional testing seems to indicate that EA Studio-generated strategies and portfolio EAs are also affected, but to a lesser extent. In the results below magic numbers [3000,3019] are identical EA Studio-generated strategies running in their own charts, and magic numbers [40000,40019] are identical strategies running in an EA Studio-generated portfolio. Even though EA Studio-generated strategies and portfolios are less dependent on ticks, you can see they are still affected. EA Studio-generated strategies running in their own charts appear to trade less often as the chart number increases. The good news is that within a portfolio they appear to trade the same, but about 25% less frequently than chart #1.
Here's where I think things currently stand:
(1) MT4 throttles OnTick in order to control how much CPU time is allotted to each chart.
(2) If a chart is taking too long to process OnTick, then MT4 either kills that thread or drastically lowers its priority.
(3) MT4 does not appear to penalize an EA for using OnTimer().
(4) There is a large drop-off in trading after 7 or 8 charts.
One possible solution is to use OnTimer() instead of OnTick().
Another solution -- place an infinite loop inside OnInit() -- for example:
int OnInit()
{
//---
while(!IsStopped())
{
// Perform all calculations and trading here...
...
...
...Sleep(10000);
}
//---
return(INIT_SUCCEEDED);
}
In other words, the goal is to allow our code to take as much time as it needs to complete its computations and trading without allowing MT4 to intervene and throttle it by withholding ticks or lowering the thread's priority.
Again -- this is just speculation based on our observations. Only MetaQuotes knows for sure how all this works.