MT4 Java Price history

easy direct connection to any MT4 and MT5 server

MT4 Java Price history

Here we show how to get OHLC history with using MT4 Java API.

 1 void historyQuotes() throws Exception {
 2     QuoteClient qc = new QuoteClient(2090221607, "OJgYhOfEF8", "demo.mt4tickmill.com", 443);
 3     qc.Connect();
 4     System.out.println("Connected. Balance = " + qc.AccountBalance());
 5     qc.OnQuoteHistory.addListener(new OnQuoteHist());
 6     qc.DownloadQuoteHistory("EURUSD", Timeframe.H1, LocalDateTime.now(), (short)100);
 7 }
 8 
 9 class OnQuoteHist implements QuoteHistoryEventHandler {
10     @Override
11     public void invoke(Object o, QuoteHistoryEventArgs args) {
12         System.out.println(args.Symbol + " " + args.TimeFrame);
13         for(Bar bar : args.Bars)
14             System.out.println(bar.Time + " " + bar.Open + " " + bar.Close);
15     }
16 }

Leave a Reply