mtapi
mtapi copied to clipboard
Help,no connection to Mt4 in VS Windows Forms.
you can show an example Mt4 with Windows Forms. Please.
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());
}
}
}
}
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" } } ]