vdemydiuk / mtapi

MetaTrader API (terminal bridge)
http://mtapi4.net/
MIT License
524 stars 283 forks source link

MT5 connection problems with Windows Forms #265

Open ljchuello opened 2 years ago

ljchuello commented 2 years ago

Hello.

I have followed each of the instructions step by step, and despite this I cannot connect.

I always get the connection status: Mt5ConnectionState.Failed

` static readonly EventWaitHandle _connnectionWaiter = new AutoResetEvent(false); static readonly MtApi5Client _mtapi = new MtApi5Client();

    public Form1()
    {
        // Init
        InitializeComponent();

        _mtapi.ConnectionStateChanged += _mtapi_ConnectionStateChanged;

        _mtapi.BeginConnect("127.0.0.1", 8228);
        _connnectionWaiter.WaitOne();
    }

    private void _mtapi_ConnectionStateChanged(object sender, Mt5ConnectionEventArgs e)
    {
        switch (e.Status)
        {
            case Mt5ConnectionState.Connecting:
                Console.WriteLine("Connnecting...");
                break;
            case Mt5ConnectionState.Connected:
                Console.WriteLine("Connnected.");
                _connnectionWaiter.Set();
                break;
            case Mt5ConnectionState.Disconnected:
                Console.WriteLine("Disconnected.");
                _connnectionWaiter.Set();
                break;
            case Mt5ConnectionState.Failed:
                Console.WriteLine("Connection failed.");
                _connnectionWaiter.Set();
                break;
        }
    }`
lazou commented 2 years ago

Hi @ljchuello ,

did you tried to connect to an expert of a chart or did you wanted to connect to a backtesting setup?