Diskussion zum Artikel "Die Erstellung des Bots für Telegram in der Sprache MQL5" - Seite 30

 
Andrey Voytenko:

Ich möchte diejenigen, die nicht in der Lage sind, Telegram über WebRequest zu starten, bitten, dieses Skript auszuführen und hier die Zeile aus der Registerkarte Experten mit dem Ergebnis zu kopieren. Dies wird helfen, das Problem schnell zu identifizieren.

2020.06.10 10:16:02.090    TestWebRequest (EURUSD,M15)    Build=2485 
WebRequest=200 GetLastError=0 
strData={"ok":true,"result":{"id":177791741,"is_bot":true,"first_name":"ForexSignal","username":"ForexSignalBot","can_join_groups":true,"can_read_all_group_messages":true,"supports_inline_queries":true}}
 
Ilyas:

Von Windows 10 Pro und Server 2016 werden die Anfragen ohne Probleme gesendet.

 
GedThey MaThey:

Ich bin bereits testen Sie Ihr Skript in zwei System

Erstens in Windows 7 7601 SP1, läuft Fehler wie Ihr Fehler
Zweitens in Windows 10 Pro 64 Bit Build 18363 läuft gut kein Fehler


Ich habe meine Skripte arbeiten mit den gleichen Ergebnissen, so kann ich dies jetzt bestätigen:

- Windows 7: Funktioniert NICHT ❌.

- Windows 10: Funktioniert gut ✅

@Andrey Voytenko

 

Hallo Leute, ich brauche Hilfe



wenn ich eine Bestellung aufgebe, sendet der Bot mehrmals die gleiche Nachricht,

Hier ist der Code!


Danke im Voraus

#include <Telegram.mqh>


input string InpChannelName="@signal";//Kanalname
input string InpToken="1049045330:AxxxxxxbFxxx0-IxwKXyxxxxxxxx";//Bot Token


CCustomBot bot;

datetime time_signal=0;
//int SendMessage(const string channel_name,
                //const string text);




//+------------------------------------------------------------------+
//| Experten-Initialisierungsfunktion|
//+------------------------------------------------------------------+
int OnInit()
  {
   time_signal=0;

//--- Token setzen
   bot.Token(InpToken);


//--- erledigt
   return(INIT_SUCCEEDED);
  }
 
  datetime _opened_last_time = TimeCurrent() ;
  datetime _closed_last_time = TimeCurrent()  ;
  
 

//+------------------------------------------------------------------+
//| Experten-Deinitialisierungsfunktion|
//+------------------------------------------------------------------+
void OnDeinit(const int reason)

{

}
     
  
//+------------------------------------------------------------------+
//| Experten-Tick-Funktion|
//+------------------------------------------------------------------+
void OnTick()
  {
  

   string message = "";
   int total=OrdersTotal();
  
        
   for(int pos=0;pos<total;pos++){  // Aktuelle Aufträge -----------------------
     if(OrderSelect(pos,SELECT_BY_POS)==false) continue;
     if(OrderOpenTime() <= _opened_last_time) continue;
     
     message += StringFormat("Order opened!\r\nType: %s\r\nSymbol: %s\r\nPrice: %s\r\nSL: %s\r\nTP: %s\r\nTime: %s\r\nTicket:.%s ",
     order_type(),
     OrderSymbol(),
     DoubleToStr(OrderOpenPrice(),MarketInfo(OrderSymbol(),MODE_DIGITS)),
     DoubleToStr(OrderStopLoss(),MarketInfo(OrderSymbol(),MODE_DIGITS)),
     DoubleToStr(OrderTakeProfit(),MarketInfo(OrderSymbol(),MODE_DIGITS)),
     TimeToStr(OrderOpenTime(),TIME_MINUTES),
     IntegerToString(OrderTicket())
          
      );
      
     int res=bot.SendMessage(InpChannelName,message);
     if(res!=0)
         Print("Error: ",GetErrorDescription(res));
     
     }
     
      bool is_closed = false;

  
  total = OrdersHistoryTotal();
      
   for(int pos=0;pos<total;pos++){  // Geschichte Bestellungen-----------------------
      if(OrderSelect(pos,SELECT_BY_POS,MODE_HISTORY)==false) continue;
      if(OrderCloseTime() <= _closed_last_time) continue;
     printf(OrderCloseTime());
     is_closed = true;
     
     message += StringFormat("Order closed!\r\nTicket: %s\r\nSymbol: %s\r\nClosing Price: %s\r\nTime: %s",
     IntegerToString(OrderTicket()),
     OrderSymbol(),
     DoubleToStr(OrderClosePrice(),MarketInfo(OrderSymbol(),MODE_DIGITS)),
     TimeToStr(OrderCloseTime(),TIME_MINUTES),
     DoubleToStr(order_pips(),1)
     
     
     );
      
      int res=bot.SendMessage(InpChannelName,message);
     if(res!=0)
         Print("Error: ",GetErrorDescription(res));
      
     }
 
   }
   
   
double order_pips() {
   double pips;
   
   if(OrderType() == OP_BUY) {
      pips =  (OrderClosePrice()-OrderOpenPrice())/MarketInfo(OrderSymbol(),MODE_POINT);
   } else {
      pips =  (OrderOpenPrice()-OrderClosePrice())/MarketInfo(OrderSymbol(),MODE_POINT);
   }
   return pips/10;
}

string order_type_to_str(int type)
{
   return StringSubstr(EnumToString((ENUM_ORDER_TYPE)type), 11);
}
string order_type () {
   return order_type_to_str(OrderType());
   
   if(OrderType() == OP_BUY)        return "BUY";
   if(OrderType() == OP_SELL)       return "SELL";
   if(OrderType() == OP_BUYLIMIT)   return "BUY LIMIT";
   if(OrderType() == OP_SELLLIMIT)  return "SELL LIMIT";
   if(OrderType() == OP_BUYSTOP)    return "BUYSTOP";
   if(OrderType() == OP_SELLSTOP)   return "SELLSTOP";
   
   return "{err}";
}
   

   
//---
 

Hallo Herr!! Vielen Dank für dieses schöne Tool!


Ich frage mich, wenn ich bereits meine Alarme Presets auf verschiedenen Indikatoren Setup für E-Mail-Benachrichtigungen haben, kann ich wissen, welche Zeilen, die ich brauche, um auf meinem Kanal über Ihr Telegramm mql erhalten hinzufügen.


Ich habe bereits alle Dateien im Include-Ordner.


Vielen Dank im Voraus



//+------------------------------------------------------------------+
//|Indikator: Alert.mq5 ||
//||
//||
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""
#property version   "1.00"
#property description ""

//--- Indikatoreinstellungen
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 2

#property indicator_type1 DRAW_ARROW
#property indicator_width1 4
#property indicator_color1 0xFFFFFF
#property indicator_label1 "Buy"

#property indicator_type2 DRAW_ARROW
#property indicator_width2 4
#property indicator_color2 0xC437C4
#property indicator_label2 "Sell"

#include <Telegram.mqh>


input string InpChannelName="@xxxxx";//Kanalname
input string InpToken="xxxxxxx:AxxxxxxbFxxx0-IxwKXyxxxxxxxx";//Bot Token


CCustomBot bot;

datetime time_signal=0;
//int SendMessage(const string channel_name,
                //const string text);



//--- Indikatorpuffer
double Buffer1[];
double Buffer2[];

datetime time_alert; //bei der Versendung der Meldung verwendet
bool Send_Email = true;
double myPoint; //initialisiert in OnInit
int MACD_handle;
double MACD_Main[];
double MACD_Signal[];
double Low[];
double High[];
double Ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
double Bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
double Last = SymbolInfoDouble(_Symbol, SYMBOL_LAST);

void myAlert(string type, string message)
  {
   if(type == "print")
      Print(message);
   else if(type == "error")
     {
      Print(type+" DAILY ALERT "+Symbol()+message);
     }
   else if(type == "order")
     {
     }
   else if(type == "modify")
     {
     }
   else if(type == "")
     {
      if(Send_Email) SendMail("DAILY ALERT",">Symbol : "+Symbol()+
      "\n"
      "\n" + "Price : "+ DoubleToString(Last) +  
      "\n" + "Date : "+TimeToString(TimeLocal(),TIME_DATE )+
      "\n" + "Time : "+TimeToString(TimeLocal(),TIME_MINUTES)+
      "\n" + "Time Frame : "+EnumToString((ENUM_TIMEFRAMES)Period())+message);
     }
  }

//+------------------------------------------------------------------+
//| Benutzerdefinierte Initialisierungsfunktion für Indikatoren |
//+------------------------------------------------------------------+
int OnInit()
  {   
   SetIndexBuffer(0, Buffer1);
   PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, EMPTY_VALUE);
   PlotIndexSetInteger(0, PLOT_ARROW, 241);
   SetIndexBuffer(1, Buffer2);
   PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, EMPTY_VALUE);
   PlotIndexSetInteger(1, PLOT_ARROW, 242);
   
   
   //myPoint initialisieren
   myPoint = Point();
   if(Digits() == 5 || Digits() == 3)
     {
      myPoint *= 10;
     }
   MACD_handle = iMACD(NULL, PERIOD_D1, 12, 26, 9, PRICE_CLOSE);
   if(MACD_handle < 0)
     {
      Print("The creation of iMACD has failed: MACD_handle=", INVALID_HANDLE);
      Print("Runtime error = ", GetLastError());
      return(INIT_FAILED);
     }
   
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Benutzerdefinierte Indikator-Iterationsfunktion|
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime& time[],
                const double& open[],
                const double& high[],
                const double& low[],
                const double& close[],
                const long& tick_volume[],
                const long& volume[],
                const int& spread[])
  {
   int limit = rates_total - prev_calculated;
   //--- Zählung von 0 bis rates_total
   ArraySetAsSeries(Buffer1, true);
   ArraySetAsSeries(Buffer2, true);
   //--- anfänglicher Nullpunkt
   if(prev_calculated < 1)
     {
      ArrayInitialize(Buffer1, 0);
      ArrayInitialize(Buffer2, 0);
     }
   else
      limit++;
   datetime TimeShift[];
   datetime Time[];
   
   if(BarsCalculated(MACD_handle) <= 0) 
      return(0);
   if(CopyBuffer(MACD_handle, MAIN_LINE, 0, rates_total, MACD_Main) <= 0) return(rates_total);
   ArraySetAsSeries(MACD_Main, true);
   if(CopyTime(Symbol(), PERIOD_CURRENT, 0, rates_total, TimeShift) <= 0) return(rates_total);
   ArraySetAsSeries(TimeShift, true);
   if(BarsCalculated(MACD_handle) <= 0) 
      return(0);
   if(CopyBuffer(MACD_handle, SIGNAL_LINE, 0, rates_total, MACD_Signal) <= 0) return(rates_total);
   ArraySetAsSeries(MACD_Signal, true);
   if(CopyLow(Symbol(), PERIOD_CURRENT, 0, rates_total, Low) <= 0) return(rates_total);
   ArraySetAsSeries(Low, true);
   if(CopyHigh(Symbol(), PERIOD_CURRENT, 0, rates_total, High) <= 0) return(rates_total);
   ArraySetAsSeries(High, true);
   if(CopyTime(Symbol(), Period(), 0, rates_total, Time) <= 0) return(rates_total);
   ArraySetAsSeries(Time, true);
   //--- Hauptschleife
   for(int i = limit-1; i >= 0; i--)
     {
      if (i >= MathMin(5000-1, rates_total-1-50)) continue; //Einige alte Raten anpassen, um "Array out of range" oder langsame Berechnungen zu verhindern 
      
      int barshift_D1 = iBarShift(Symbol(), PERIOD_D1, TimeShift[i]);
      if(barshift_D1 < 0) continue;
      
      //Anzeigepuffer 1
      if(MACD_Main[barshift_D1] > MACD_Signal[barshift_D1]
      && MACD_Main[barshift_D1+1] < MACD_Signal[barshift_D1+1] //MACD kreuzt über MACD
      )
        {
         Buffer1[i] = Low[i]; //Indikatorwert bei Candlestick Low setzen
         if(i == 0 && Time[0] != time_alert)
         { myAlert("",
        "\n"
        "\n" + ">Direction : " " UP"); time_alert = Time[0]; } //Instant alert, nur einmal pro Takt
        }
      else
        {
         Buffer1[i] = EMPTY_VALUE;
        }
      //Anzeigepuffer 2
      if(MACD_Main[barshift_D1] < MACD_Signal[barshift_D1]
      && MACD_Main[barshift_D1+1] > MACD_Signal[barshift_D1+1] //MACD kreuzt unter MACD
      )
        {
         Buffer2[i] = High[4+i]; //Indikatorwert bei Candlestick High setzen
         if(i == 0 && Time[0] != time_alert) 
         { myAlert(" ",
         "\n"
         "\n" + ">Direction : " " DOWN"); time_alert = Time[0]; } //Instant alert, nur einmal pro Takt
        }
      else
        {
         Buffer2[i] = EMPTY_VALUE;
        }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
OrelMely:



Funktioniert die Bibliothek mit Indikatoren?
 
Jefferson Metha:
Funktioniert die Bibliothek in Indikatoren

Ja, er hat eine Signaldatei vordefiniert, die bereits mit MACD arbeitet...


Aber ich habe nur begrenzte Code-Fähigkeiten, so kann ich nicht laufen es atm

 

Hallo,

Mt4 zeigt einen Fehler an, wenn ich versuche, ein Foto zu senden:


  • EURUSD,H1: {"ok":false, "error_code":400, "description": "Bad Request: wrong HTTP URL specified"}


Es scheint, als ob er denkt, dass ich versuche, EURUSD.gif von einem Server aus zu erreichen, während es sich auf "MQL4/Files" befindet.

Ich habe es mit einem direkten Pfad von Windows-Dateien versucht, aber das Problem bleibt bestehen. Ich hänge jetzt schon seit Stunden an diesem Problem fest, hat jemand einen Hinweis?

Hier ist mein Code

      bot.Token(token);
      
      string photo_id;
      int result=bot.SendPhoto(-1001098781629,"EURUSD.gif",photo_id);
      if(result==0)
         Print("Photo ID: ",photo_id);
      else
         Print("Error: ",GetErrorDescription(result));
 
Telegram Bot API
  • core.telegram.org
The Bot API is an HTTP-based interface created for developers keen on building bots for Telegram. To learn how to create and set up a bot, please consult our Introduction to Bots and Bot FAQ . Recent changes June 4, 2020 Added the new field via_bot to the Message object. You can now know which bot was used to send a message. Supported video...
 
Es tut mir leid, aber ich bin mir nicht sicher, was ich falsch mache. Meinen Sie, dass ich ein Foto nicht lokal senden kann, sondern es erst auf einen Server hochladen muss?