Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sample implementation: How to send trading signals from Metatrader to Telegram channel/group/private chat with Telegram4MQL
//+------------------------------------------------------------------+
//| Signal2Channel.mq4 |
//| steven england |
//| https://Telegram4MQL.steven-england.info |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| !!! Please note that there is a successor project. !!! |
//| Visit https://mmm.steven-england.info or |
//| https://github.com/stevenengland/MMM for more information |
//+------------------------------------------------------------------+
#property copyright "steven england"
#property link "https://Telegram4MQL.steven-england.info"
#property version "1.00"
#import "Telegram4Mql.dll"
string TelegramSendTextAsync(string ApiKey, string ChatId, string ChatText);
string TelegramSendText(string ApiKey, string ChatId, string ChatText);
#import
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnInit()
{
sample();
}
void sample() // this entry point is only for testing
{
// Your config parameters here
// The api key of your telegram bot:
string apikey = "<YOUR API KEY>";
// The chat ID of your channel you want to post to:
string chatid = "<YOUR CHAT ID>";
/* Your incredible Expert Advisor logic here
...
Some (not meaningful) example values:
*/
int cmd = OP_SELL; // operation
double volume = 0.1; // volume
double price = 0.1; // price
int slippage = 1; // slippage
double stoploss = 0.1; // stop loss
double takeprofit = 0.1; // take profit
string comment = "a comment";// comment
int magic = 0; // magic number
datetime expiration = 0; // pending order expiration
color arrow_color = clrRed; // color
// Ready to send an order
string text2send = "";
int ordersend = OrderSend(Symbol(), cmd, volume, price, slippage, stoploss, takeprofit, comment, magic, expiration, arrow_color);
if(ordersend < 0)
{
HandleSendError(GetLastError()); // implement this custom functon on your own.
return;
}
// Describe your order for the others
if(OrderSelect(ordersend, SELECT_BY_TICKET, MODE_TRADES) == true)
{
text2send = "MyIncredibleSignal\n" +
"Symbol: " + Symbol() + "\n" +
"Type: " + OrderType() + "\n" +
"Open Time: " + OrderOpenTime() + "\n" +
"Open Price: " + OrderOpenPrice() + "\n";
//
}
else
{
HandleSelectError(GetLastError()); // implement this custom functon on your own.
return;
}
// Send a text message to a channel either blocking or non blocking
// Non blocking if Expert Advisor must immediatly return -> you cannot say if the message was really sent
TelegramSendTextAsync(apikey, chatid, text2send);
// Blocking if your Expert Advisor must not immediatly return -> you can check if sending was successful
string telegramresult = TelegramSendText(apikey, chatid, text2send);
if (telegramresult != "0")
{
HandleTelegramError(telegramresult); // implement this custom functon on your own.
}
}
@rosspfc

This comment has been minimized.

Copy link

@rosspfc rosspfc commented Aug 25, 2018

Hello don’t know how old this thread is but did this work? Thanks

@EVOJUAN

This comment has been minimized.

Copy link

@EVOJUAN EVOJUAN commented Nov 7, 2018

I don't know anything about coding, but I did a EA on FXdreema that send me notification of bolinger and EMA direct to my mt4 terminal on my cellphone.
Now I like send that already done EA to send that notification to a TElegram channel , but im trying all a see but somehow nothing work, I have my channel and my bot is the adm. and I did a test on the web browser to send direct message to the channel and it did perfect, but no signal or notification has send from mt4 to telegram.

what I can do ? or is a video tutorial that I can learn ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.