mtapi icon indicating copy to clipboard operation
mtapi copied to clipboard

Help,no connection to Mt4 in VS Windows Forms.

Open nopsynops opened this issue 3 years ago • 2 comments

you can show an example Mt4 with Windows Forms. Please.

nopsynops avatar Jun 20 '21 17:06 nopsynops

Hi nopsynops, The following is the basic example, please take a look.

using System.Collections.Generic;
using System.Threading;
using System.Windows.Forms;
using MtApi;
namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        private MtApiClient client;        
        private string symbol = "USDJPY";
        public Form1()
        {
            InitializeComponent();
            client = new MtApiClient();    //Initialize client
            
            /*You need to add the event handler here for detecting connection*/
            client.ConnectionStateChanged += Client_ConnectionStateChanged;

            client.BeginConnect(8222);    //Begin Connection! Remark-> The port should be same as your EA input in MT4

        }

        private void Client_ConnectionStateChanged(object sender, MtConnectionEventArgs e)
        {
            /*Once connection established, your EA logic can be implement*/
            if(e.Status== MtConnectionState.Connected)
            {
                MessageBox.Show(client.iClose(symbol, ChartPeriod.PERIOD_MN1, 0).ToString());
            }
        }

    }
}

kenykau avatar Jul 30 '21 05:07 kenykau

Thanks a lot

Hi nopsynops, The following is the basic example, please take a look. using System.Collections.Generic; using System.Threading; using System.Windows.Forms; using MtApi; namespace WindowsFormsApp1 { public partial class Form1 : Form { private MtApiClient client;
private string symbol = "USDJPY"; public Form1() { InitializeComponent(); client = new MtApiClient(); //Initialize client

        /*You need to add the event handler here for detecting connection*/
        client.ConnectionStateChanged += Client_ConnectionStateChanged;
        client.BeginConnect(8222);    //Begin Connection! Remark-> The port should be same as your EA input in MT4
    }
    private void Client_ConnectionStateChanged(object sender, MtConnectionEventArgs e)
    {
        /*Once connection established, your EA logic can be implement*/
        if(e.Status== MtConnectionState.Connected)
        {
            MessageBox.Show(client.iClose(symbol, ChartPeriod.PERIOD_MN1, 0).ToString());
        }
    }
}

}

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe. [ { @.": "http://schema.org", @.": "EmailMessage", "potentialAction": { @.": "ViewAction", "target": "https://github.com/vdemydiuk/mtapi/issues/257#issuecomment-889632113", "url": "https://github.com/vdemydiuk/mtapi/issues/257#issuecomment-889632113", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { @.": "Organization", "name": "GitHub", "url": "https://github.com" } } ]

nopsynops avatar Jul 30 '21 09:07 nopsynops