I've found a way to send out trade details from MT5 to telegra using the following function (Sorry I can't find where I got this from!):
void telegram_send(string token, string chat_id, string message)
{
string cookie=NULL,headers;
char post[],result[];
int res;
string base_url="https://api.telegram.org";
string url=base_url+"/bot"+token+"/sendMessage?chat_id="+chat_id+"&text="+message;
ResetLastError();
int timeout=2000;
res=WebRequest("GET",url,cookie,NULL,timeout,post,0,result,headers);
if(res==-1)
{
int error_code = GetLastError();
Print("Error in WebRequest. Error code: ",error_code);
if(error_code==4060)
{
MessageBox("Add the address '"+base_url+"' in the list of allowed URLs on tab 'Expert Advisors'","Error",MB_ICONERROR);
}
else
{
MessageBox("Access to the server is not possible.\nCode: "+IntegerToString(error_code),"Error",MB_ICONERROR);
}
}
else
{
MessageBox("The message sent successfully.\nResult: "+CharArrayToString(result),"Success",MB_ICONINFORMATION);
}
}
This works abolutely fine.
The problem however is that "\n" seems to not work when sending to telegram, but works fine with the Send Notification Function;
Since you are sending the message as part of the url, you will need to encode the message in base64. At least that's what I would expect. Else you'll need to send it as payload (post data) with the get request.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hello guys,
I've found a way to send out trade details from MT5 to telegra using the following function (Sorry I can't find where I got this from!):
This works abolutely fine.
The problem however is that "\n" seems to not work when sending to telegram, but works fine with the Send Notification Function;
Any ideas why this doesnt work with the telegram function? It is just the "\n" that stops the telegram_send from working