MT4 Java Market order

easy direct connection to any MT4 and MT5 server

MT4 Java Market order

Here we shows how to open and close market order.

 1 void market() throws InterruptedException {
 2     String symbol = "EURUSD";
 3     QuoteClient qc = new QuoteClient(2090221607, "OJgYhOfEF8", "demo.mt4tickmill.com", 443);
 4     qc.Connect();
 5     System.out.println("Connected. Balance = " + qc.AccountBalance());
 6     qc.Subscribe(symbol);
 7     while (qc.GetQuote(symbol) == null)
 8         Thread.sleep(1);
 9     OrderClient oc = new OrderClient(qc);
10     Order sell = oc.OrderSend(symbol, Op.Sell, 0.1, qc.GetQuote(symbol).Bid, 10, 0,0 );
11     System.out.println("sell ticket " + sell.Ticket);
12     Order close = oc.OrderClose(sell.Symbol, sell.Ticket, sell.Lots, qc.GetQuote(symbol).Ask, 10);
13     System.out.println("closed " + close.Profit);
14 }

Leave a Reply