.

Coding Help : telegram EA notification

#1
Hi ,

Sorry for my poor english .

I've got an error on this code when i compiled him an metaeditor and i d'ont find why.
Does anyone can help ?

Code: Select all

//+------------------------------------------------------------------+
//|                                        Telegram_Signal_EA_v1.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

//+------------------------------------------------------------------+
//|   Includes                                                       |
//+------------------------------------------------------------------+
#include <Telegram.mqh>

//--- Input parameters
input string InpChannelName="@Signaux Mt4";//Channel Name
input string InpToken="529620876:AAHKz0xg-K9mxvLLIhrZ7dXJAQ_iURTMHuY";//Token

//--- Global variables
CCustomBot bot;
int macd_handle;
datetime time_signal=0;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   time_signal=0;

//--- set token
   bot.Token(InpToken);

//--- get an indicator handle
   macd_handle=iMACD(NULL,0,12,26,9,PRICE_CLOSE);
   if(macd_handle==INVALID_HANDLE)
      return(INIT_FAILED);

//--- done
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {

//--- get time
   datetime time[1];
   if(CopyTime(NULL,0,0,1,time)!=1)
      return;

//--- check the signal on each bar
   if(time_signal!=time[0])
     {
      //--- first calc
      if(time_signal==0)
        {
         time_signal=time[0];
         return;
        }

      double macd[2]={0.0};
      double signal[2]={0.0};

      if(CopyBuffer(macd_handle,0,0,2,macd)!=2)
         return;
      if(CopyBuffer(macd_handle,1,0,2,signal)!=2)
         return;

      time_signal=time[0];

      //--- Send signal BUY
      if(macd[1]>signal[1] && 
         macd[0]<=signal[0])
        {
         string msg=StringFormat("Name: MACD Signal\nSymbol: %s\nTimeframe: %s\nType: Buy\nPrice: %s\nTime: %s",
                                 _Symbol,
                                 StringSubstr(EnumToString(_Period),7),
                                 DoubleToString(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits),
                                 TimeToString(time[0]));
         int res=bot.SendMessage(InpChannelName,msg);
         if(res!=0)
            Print("Error: ",GetErrorDescription(res));
        }

      //--- Send signal SELL
      if(macd[1]<signal[1] && 
         macd[0]>=signal[0])
        {
         string msg=StringFormat("Name: MACD Signal\nSymbol: %s\nTimeframe: %s\nType: Sell\nPrice: %s\nTime: %s",
                                 _Symbol,
                                 StringSubstr(EnumToString(_Period),7),
                                 DoubleToString(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits),
                                 TimeToString(time[0]));
         int res=bot.SendMessage(InpChannelName,msg);
         if(res!=0)
            Print("Error: ",GetErrorDescription(res));
        }
     }
  }
//+------------------------------------------------------------------+
thanks .

Best regards


Re: Coding Help : telegram EA notification

#2
redbulls60 wrote:
Sun Jan 21, 2018 9:45 pm
Hi ,

Sorry for my poor english .

I've got an error on this code when i compiled him an metaeditor and i d'ont find why.
Does anyone can help ?

Code: Select all

//+------------------------------------------------------------------+
//|                                        Telegram_Signal_EA_v1.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

//+------------------------------------------------------------------+
//|   Includes                                                       |
//+------------------------------------------------------------------+
#include <Telegram.mqh>

//--- Input parameters
input string InpChannelName="@Signaux Mt4";//Channel Name
input string InpToken="529620876:AAHKz0xg-K9mxvLLIhrZ7dXJAQ_iURTMHuY";//Token

//--- Global variables
CCustomBot bot;
int macd_handle;
datetime time_signal=0;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   time_signal=0;

//--- set token
   bot.Token(InpToken);

//--- get an indicator handle
   macd_handle=iMACD(NULL,0,12,26,9,PRICE_CLOSE);
   if(macd_handle==INVALID_HANDLE)
      return(INIT_FAILED);

//--- done
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {

//--- get time
   datetime time[1];
   if(CopyTime(NULL,0,0,1,time)!=1)
      return;

//--- check the signal on each bar
   if(time_signal!=time[0])
     {
      //--- first calc
      if(time_signal==0)
        {
         time_signal=time[0];
         return;
        }

      double macd[2]={0.0};
      double signal[2]={0.0};

      if(CopyBuffer(macd_handle,0,0,2,macd)!=2)
         return;
      if(CopyBuffer(macd_handle,1,0,2,signal)!=2)
         return;

      time_signal=time[0];

      //--- Send signal BUY
      if(macd[1]>signal[1] && 
         macd[0]<=signal[0])
        {
         string msg=StringFormat("Name: MACD Signal\nSymbol: %s\nTimeframe: %s\nType: Buy\nPrice: %s\nTime: %s",
                                 _Symbol,
                                 StringSubstr(EnumToString(_Period),7),
                                 DoubleToString(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits),
                                 TimeToString(time[0]));
         int res=bot.SendMessage(InpChannelName,msg);
         if(res!=0)
            Print("Error: ",GetErrorDescription(res));
        }

      //--- Send signal SELL
      if(macd[1]<signal[1] && 
         macd[0]>=signal[0])
        {
         string msg=StringFormat("Name: MACD Signal\nSymbol: %s\nTimeframe: %s\nType: Sell\nPrice: %s\nTime: %s",
                                 _Symbol,
                                 StringSubstr(EnumToString(_Period),7),
                                 DoubleToString(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits),
                                 TimeToString(time[0]));
         int res=bot.SendMessage(InpChannelName,msg);
         if(res!=0)
            Print("Error: ",GetErrorDescription(res));
        }
     }
  }
//+------------------------------------------------------------------+
thanks .

Best regards
Not sure but need the #include <Telegram.mqh> to tell for sure.


Re: Coding Help : telegram EA notification

#8
//+------------------------------------------------------------------+
//| Telegram_Signal_EA.mq5 |
//| Copyright 2014, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property version "1.00"
#property strict

#include <Telegram.mqh>

//--- input parameters
input long InpChannelName;//Channel Name
input string InpToken="";//Tokenz
string macd = "----- MACD Settings-----"; //---------------------------------------------------------
int FastPeriod = 12;
int SlowPeriod = 26;
int SignalPeriod = 9;

double MacdSignal;
double MacdMain;

//--- global variables
CCustomBot bot;
int macd_handle;
datetime time_signal=0;
bool checked;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
time_signal=0;
bot.Token(InpToken);

return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
if(reason==REASON_PARAMETERS ||
reason==REASON_RECOMPILE ||
reason==REASON_ACCOUNT)
{
checked=false;
}

//--- delete the indicator

}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{

if(!checked)
{
if(StringLen((string)InpChannelName)==0)
{
Print("Error: Channel name is empty");
Sleep(10000);
return;
}

int result=bot.GetMe();
if(result==0)
{
Print("Bot name: ",bot.Name());
checked=true;
}
else
{
Print("Error: ",GetErrorDescription(result));
Sleep(10000);
return;
}
}

//--- get time
datetime time[1];
if(CopyTime(NULL,0,0,1,time)!=1)
return;

//--- check the signal on each bar
if(time_signal!=time[0])
{
//--- first calc
if(time_signal==0)
{
time_signal=time[0];
return;
}


MacdMain = iMACD(NULL, 0, FastPeriod, SlowPeriod, SignalPeriod, PRICE_CLOSE, MODE_MAIN, 1);
MacdSignal = iMACD(NULL, 0, FastPeriod, SlowPeriod, SignalPeriod, PRICE_CLOSE, MODE_SIGNAL, 1);

int x = 1;

time_signal=time[0];

if(MacdMain > 0 && MacdSignal > MacdMain && x==1)
{
string msg=StringFormat("Name: MACD\nSymbol: %s\nTimeframe: %s\nType: Buy\nPrice: %s\nTime: %s",
_Symbol,
StringSubstr(EnumToString((ENUM_TIMEFRAMES)_Period),7),
DoubleToString(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits),
TimeToString(time[0]));
int res=bot.SendMessage(InpChannelName,msg);
if(res!=0)
Print("Error: ",GetErrorDescription(res));
Sleep(2000);
x--;
}

//--- Send signal SELL
if(MacdMain < 0 && MacdSignal < MacdMain && x==1)
{
string msg=StringFormat("Name: MACD\nSymbol: %s\nTimeframe: %s\nType: Sell\nPrice: %s\nTime: %s",
_Symbol,
StringSubstr(EnumToString((ENUM_TIMEFRAMES)_Period),7),
DoubleToString(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits),
TimeToString(time[0]));
int res=bot.SendMessage(InpChannelName,msg);
if(res!=0)
Print("Error: ",GetErrorDescription(res));
Sleep(2000);
x--;
}
}
}

//+------------------------------------------------------------------+



Who is online

Users browsing this forum: CommonCrawl [Bot] and 0 guests