Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help,no connection to Mt4 in VS Windows Forms. #257

Open
nopsynops opened this issue Jun 20, 2021 · 2 comments
Open

Help,no connection to Mt4 in VS Windows Forms. #257

nopsynops opened this issue Jun 20, 2021 · 2 comments

Comments

@nopsynops
Copy link

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

@kenykau
Copy link

kenykau commented Jul 30, 2021

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());
            }
        }

    }
}

@nopsynops
Copy link
Author

nopsynops commented Jul 30, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants