- ECN and liquidity providers for the MetaTrader 5 platform
- Instant notifications and alerts in MetaTrader 5
- MetaTrader 5 for your investors
Hello guys, may I ask you a little question: Is it possible to send a webrequest to a specific port? (MQL4) And how can I set up metatrader 4 to communicate with a localhost? Is it possible to send a request to a "http://localhost:10000/" ?
Please read the documentation :
Server port is automatically selected on the basis of the specified protocol - 80 for "http://" and 443 for "https://".
Yes, this is a very serious limitation and should be solved. Sometimes another webserver is already
on 80 port. so it takes, port forwarding on routers, vpn and virtual hosts and other workarounds to make it work.
Joined the party late - but there *is* a solution to this quandary.
Port forwarding works very well.
https://www.baeldung.com/linux/mapping-hostnames-ports
https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/
https://docs.nginx.com/nginx/admin-guide/basic-functionality/runtime-control/
#property strict #include <Class/JAson.mqh> enum TimeFrames { CURRENT = 0, M1 = 1, M5 = 5, M15 = 15, M30 = 30, H1 = 60, H4 = 240, D1 = 1440, W1 = 10080, MN1 = 43200 }; void Post(string json) { int res; // To receive the operation execution result char data[]; // Data array to send POST requests char result[]; string sep="-------Jyecslin9mp8RdKV"; // multipart data separator string auth = NULL; string headers = "application/json"; string url = StringConcatenate("http://mt4dev01.com/.json"); int timeout=1000; //--- Timeout below 1000 (1 sec.) is not enough for slow Internet connection string strResult; string result_header; //--- Reset the last error code ResetLastError(); StringToCharArray(json,data,0,WHOLE_ARRAY); res=WebRequest("POST",url,headers,timeout,data,result,result_header); //--- Checking errors if(res==-1) { Print("Error in WebRequest. Error code =",GetLastError()); //--- Perhaps the URL is not listed, display a message about the necessity to add the address Print("Add the address '"+url+"' in the list of allowed URLs on tab 'Expert Advisors'"); } else { for(int i=0;i<ArraySize(result);i++) { if( (result[i] == 10) || (result[i] == 13)) { continue; } else { strResult += CharToStr(result[i]); } } // ArrayCopy(strResult,result,0,0,WHOLE_ARRAY); } // Print(strResult); }; void OnStart() { CJAVal strPost; //Example of json String : //EURUSD,M15: PARSED:{"bid" : 1.1152,"ask" : 1.1154,"spread" : 13,"ticktime" : "2016.10.10 16:24:01","currency" : "EURUSD","timeframe" : "15"} //2023.12.21 12:09:27.638 MT4Post EURUSD,H1: {"Currency":"EURUSD","TimeFrame":"H1","TickTime":"2023.12.21 22:09:27","Bid":1.09929000,"Ask":1.09942000,"Spread":0.00013000} strPost["Currency"] = Symbol(); strPost["TimeFrame"] = EnumToString((TimeFrames)Period()); strPost["TickTime"] = TimeToString(TimeCurrent(),TIME_DATE|TIME_SECONDS); strPost["Bid"] = Bid; strPost["Ask"] = Ask; strPost["Spread"] = Ask-Bid; Post(strPost.Serialize()); }
** Sample nginx conf, /etc/hosts file and process start:
Took a minute or two to figure out - but, it totally works.

- 2021.01.31
- Rens Verhage
- www.baeldung.com

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use