This project is read-only.
1

Closed

MqlError is not working

description

I'm using the MetaTrader4.MqlScope() method to run OrderModify() function on the mql object.
I have the following code to catch the mql error:
    mql.MqlError = metaTrader4_MqlError;

    private void metaTrader4_MqlError(MqlErrorException mql)
    {
    }
When I provide invalid Stop Loss in the OrderModify function then nothing happen.
The order is not modified (this is ok), but also there is no MqlErrorException (this is wrong, becuase I don't know that something goes wrong with the order modification).

I have debug this and found a fix.
In file System_NET.mql about line 120 you use GetLastError() before running the OrderModify() as a message in the System_NET_MQL() function:
    int errorCode = GetLastError();
    string lastError = ErrorDescription(errorCode);
    string value = System_NET_MQL(message);
I have changed the order. I run the System_NET_MQL() first and then the GetLastError():
    string value = System_NET_MQL(message);
    int errorCode = GetLastError();
    string lastError = ErrorDescription(errorCode);
Now everything is working fine and after providing invalid Stop Loss I can see the exception which I expect in the metaTrader4_MqlError function:
    TradePlatform.MT4.Core.Exceptions.MqlErrorException: MQL returned error: '130:invalid stops' for method OrderModify().
Closed Sep 23, 2013 at 12:15 PM by vladkalos

comments

vladkalos wrote Sep 23, 2013 at 12:15 PM

thx. fixed in Demo solution

wrote Sep 23, 2013 at 12:15 PM