Error handling

You can handler MQL error in _.NET ExpertAdvisor_ by handling MqlError event:

public class MyScript : ExpertAdvisor
    {
        public MyScript()
        {
            this.MqlError += this.OnMqlError;
        }
        private void OnMqlError(MqlErrorException mqlErrorException)
        {
            // handle mql error
        }
     }
For handling errors while dealing with custom application which hosts _.NET Bridge_ you can handle errors for each trading terminal separately:

public Form1()
        {
            Bridge.InitializeHosts(true);

            metaTrader4 = Bridge.GetTerminal(126728, "EURUSD");
            metaTrader4.MqlError += metaTrader4_MqlError;
        }

        private void metaTrader4_MqlError(MqlErrorException mql)
        {
            // handler mql error
        }

Unit tests

MQL API itself represented as set of extension method for MqlHandler class (base abstraction on _.NET ExpertAdvisor_). So it's easily can me mocked for testing purposed. You need to implement your own extension methods for MQL API and replace originals with yours my changing using directive in your expert:

 public static class PredefinedVariablesMock
    {
        public static double Ask(this MqlHandler handler)
        {
           return 100; //mocked
        }
     }

 

Last edited Nov 5, 2012 at 3:02 PM by vladkalos, version 11

Comments

No comments yet.