I got a pretty big problem...

 
So I've been testing some scripts with my demo MT4 account.

Today I had a couple trades that got stopped out almost immediately. Considering I had 50 pip stops, I found it a little weird (to say the least) that a trade would be stopped out within a matter of minutes. Barring news releases, price doesn’t usually move 50 pips in a matter of 2 minutes.

I look at the trade time and then the chart to see what happened. To my amazement, I look at the charts (H4 charts) and all four of them, each chart a different pair, show a *huge* gap two bars ago. I manually refreshed the charts by right-clicking and hitting "Refresh"; the gap goes away and is replaced by correct bars.

Needless to say, my EA was computing data based on the corrupted bars/information. This is so unbelievably not acceptable!! I understand that from time to time communication errors are going to occur. So I think the logical thing would be to have a function in MQL that refreshes the *chart data* to ensure that correct data is present on the chart, and if a refresh fails the EA should act accordingly, i.e. not enter any new trades until a chart refresh is successful.

I looked for a refresh function in the editor’s dictionary, but I all get is RefreshRates( ). Obviously this function does not refresh the price data on the chart…unless I’m misunderstanding something.

The bottom line is that EA’s use the data that is present on the chart. Therefore, EA’s must have a way of ensuring the data on the chart is accurate. I had not run into this problem before, but it is very serious and can easily be fixed. Just have an MQL function that runs the same code as clicking “Refresh” on the context menu. Simple.

Finally, if I am being stupid and not seeing something that I should be seeing, then I sincerely apologize for bringing this up. But could you please explain to me what I am not seeing or what I am missing so that in the future I am able to prevent this problem from occurring.

Thank you very much.
Tony C…

PS. I would also like to reiterate the fact that the text box on the Publish tab of the Options dialog box is too small for me to fit my entire FTP login/username, and therefore prevents me from using this feature. I think this is also an easy fix.
 
Please specify, what build of the terminal do you use?
 
I also find this unbelievably unacceptable. Has this situation been fixed on the latest version of MetaTrader 4?

Just where are the prices coming from then; when we call functions in MQL4 to get indicator values and price values, are they based entirly of what's displayed on the chart, or are they being broadcasted through your server?
 
It was the latest build:
Version 4.00 Build 173 (Jun 6 2005)


Other factors that might effect it are that I have 4 instances of MT4 running...that might cause problem. One of the instances is running off Alpari's demo server. But each instance has its own demo account, no overlap. And each instance is installed to its own directory on the hard disk.

In the instance that had the problem, I had 4 charts open, each H4, each a different pair, each with same EA. And all 4 charts, in that instance, had the exact same problem.

None of the other instances had this or any problem. I immediately checked that.

Thank you for the response.
 
To better explain the problem; basically the last two bars on each chart were way off from where they should have been. Open[2] was at least 75 pips above Close[3], on all four charts. Time[2] was ‘12:00 on 2005.06.22’ on all charts. This is a completely odd time for such a gap. And once I hit "Refresh" on each chart, the bars re-aligned and changed to the correct shape/size and position.

Also, normally an EA will place an arrow where it enters an order (if you have it set to do that, which I did). All the other “valid” orders had a corresponding arrow…the wrong orders did not have a corresponding arrow. They only appear in my account history.

I think the only thing that is needed is an MQL function that mimics the “Refresh” action for the chart. That’s all. If that already exists, let me know.

====

Russell, to answer your question…yes, function and indicator calls are based entirely off what is displayed on the chart. Think of the chart as a holding area for the data. It is downloaded from the server and held “on the chart”. Really it is temporarily stored in memory and then written to history files on the hard disk for permanent storage. Hitting “Refresh” on the context menu is supposed to ensure that the data “on the chart” (in the history file on your hard disk) is accurate and correct.

For me, something got messed between my computer and the server. Simply having a function in MQL to allow my EA’s to ensure the data is accurate is the easiest way to fix this problem. Because then I can just set my EA to refresh before it enters a trade. If the refresh fails, then the EA doesn’t enter a trade until the refresh is successful. Also, if the terminal automatically refreshed the data from time to time, this would also help.

The problem could have occurred entirely on my end…my computer could have had any kind of glitch and decided not to behave properly for any kind of reason. But the point is that EA’s need a way to programmatically ensure the data on the chart is accurate before it uses that data to enter a trade…that is all!!!
 
tonyC2a,

I had exactly the same problem recently... I was going nuts because I was being stopped out at 'impossible' times (I guess my screen had been refreshed).

Had I not read your post, I would still be looking to find the problem.

This really is a fundamental problem in MT4 and with the release date coming up in a few days !

The workaround off course, is just not to put stops! (Sorry, just joking!)
 
hdb....

errr...actually, your advise is good. Don't put your stops on in when you open the trade, rather look for the condition that that will cause your close, when true wait a tick, check it again on the next tick and if it's still true then close the trade from your expert.

That way you won't get caught by funny ticks...
 
Well technically isn't this flawed regardless of whether you use an expert or not.. what happens if you place an order manually and it hit stops etc due to bad data?
 
This problem has been fixed. It will be available in the next client build
 
thank-you for taking this problem so seriously.. it deserves it!
Reason: