MQL5-Connector-Js
MQL5-connector-js is an interface between MT5 and nodeJS. All of the functionality of MT5 can be use on nodejs using ZeroMq. This library is created with javascript asynchronous technology. So, you have to use async
await
keywords to retrieve data from MT5.
1.First of all go to this link to install mql5-connector on MT5 and follow the github installation guides. 2.Install python 2.7 on your windows or linux machine. Or if you having trouble to install zeromq.js then follow the github guide to install zeromq.js 3.Install mql5-connector-js using npm
npm install mql5-connector-js
First you have to initialize mql5-connector-js.
const ConfigContext = ;// default config; // or you can change as your needs// input this config to mql5-connector on MT5 host_ip: "127.0.0.1" // server ip protocol: "tcp" // transfer protocol port1: 3033 // push socket port port2: 3034 // pull socket port port3: 3035 // publisher socket port timeout_ms: 1000 // wait for messages from server until timeout;
AccountInfo
class have the functions of Mql5 Account properties
const ConfigContext AccountInfo = ;// config context; //first init default or custom socket config as avobeAccountInfo;// orlet loginId = await AccountInfo;console; // explore AccountInfo for more functions
SymbolInfo
class have functions of Mql5 Symbol properties
const ConfigContext SymbolInfo = ;// config context; SymbolInfo;//orlet digits = await SymbolInfo;console; // explore SymbolInfo for more functions
Placing a buy trade on EURUSD
const ConfigContext Trade = ;// default config context;// you can change the model anytime if you want// or you can build multiple model to perform same tasklet buy_model = // you can define your price // or you can call latest price. Then this will get the // latest price from market and place a buy trade // only for buy and sell trade // you can define your custom price // 10 pips from defined price // you can define it with pips // 10 pips from current price // as same as take profit ;let ticket = await buy_model; // returns order ticketconsole;// sometimes it fails to retrieve order ticket. so, handle it your owns
Placing a buy stop order on AUDUSD
const ConfigContext Trade = ;// default config context; // you can build a model for placing stop or limit order for future workslet buy_stop_model = ;let ticket = await buy_stop_model; // returns order ticketconsole;// sometimes it fails to retrieve order ticket. so, handle it your owns
There are two types of event 1. onBar
event (which called after a new bar has formed) 2. onTick
event (which called after a new tick has found)
example of onBar
event for EURUSD with 1H timeframe & 100 history bars
// import typesconst ConfigContext Event Timeframe Bar = ;// default config context; let bar_event = ; bar_event; // unsubsribe it when not necessary
example of onTick
event for USDJPY with 100 history ticks
// import typesconst ConfigContext Event Tick = ;// default config context; let tick_event = ; tick_event; // unsubsribe when not necessary
You can get history data using Event
.
example of retrieving EURUSD 1H history bars from MT5
const ConfigContext Event Timeframe Bar = ;// default config context; let bars = await ; console;