113 lines
No EOL
7.2 KiB
MQL4
113 lines
No EOL
7.2 KiB
MQL4
//+------------------------------------------------------------------+
|
|
//| telegram.mq4 |
|
|
//| Copyright 2018, MetaQuotes Software Corp. |
|
|
//| https://www.mql5.com |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "Copyright 2018, MetaQuotes Software Corp."
|
|
#property link "https://www.mql5.com"
|
|
#property version "1.00"
|
|
#property strict
|
|
//+------------------------------------------------------------------+
|
|
//| Expert initialization function |
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
|
extern int timer=30;
|
|
|
|
int OnInit()
|
|
{
|
|
//---
|
|
EventSetTimer(timer);
|
|
send(Symbol());
|
|
|
|
//---
|
|
return(INIT_SUCCEEDED);
|
|
}
|
|
|
|
void OnTimer(){
|
|
string str=openlink("http://wlink.ru/fx/out.txt");
|
|
if(StringLen(str)>0){
|
|
|
|
send(str);
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
string send(string out){
|
|
int arr[4]={1,5,15,30,60,240};
|
|
int i;
|
|
//string out=Symbol();
|
|
|
|
for(i=0;i<6;i++){
|
|
out=StringConcatenate(out,arr[i],"-",ao_trend(arr[i],out),";");
|
|
}
|
|
|
|
string res= openlink("http://wlink.ru/fx/to_telegram.php?q="+out);
|
|
return res;
|
|
}
|
|
|
|
string ao_trend(int frame=1, string sim="eurusd"){
|
|
string out="null";
|
|
if(iAO(sim,frame,0)>0)out="b";
|
|
else out="s";
|
|
return out;
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Expert deinitialization function |
|
|
//+------------------------------------------------------------------+
|
|
void OnDeinit(const int reason)
|
|
{
|
|
//---
|
|
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Expert tick function |
|
|
//+------------------------------------------------------------------+
|
|
void OnTick()
|
|
{
|
|
//---
|
|
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
string openlink(string url) {
|
|
string cookie=NULL,headers;
|
|
char post[],result[];
|
|
//string url="https://finance.yahoo.com";
|
|
//--- для работы с сервером необходимо добавить URL "https://finance.yahoo.com"
|
|
//--- в список разрешенных URL (Главное меню->Сервис->Настройки, вкладка "Советники"):
|
|
//--- обнуляем код последней ошибки
|
|
ResetLastError();
|
|
//--- загрузка html-страницы с Yahoo Finance
|
|
int res=WebRequest("GET",url,cookie,NULL,500,post,0,result,headers);
|
|
if(res==-1)
|
|
{
|
|
Print("Ошибка в WebRequest. Код ошибки =",GetLastError());
|
|
//--- возможно, URL отсутствует в списке, выводим сообщение о необходимости его добавления
|
|
MessageBox("Необходимо добавить адрес '"+url+"' в список разрешенных URL во вкладке 'Советники'","Ошибка",MB_ICONINFORMATION);
|
|
}
|
|
else
|
|
{
|
|
if(res==200)
|
|
{
|
|
//--- успешная загрузка
|
|
PrintFormat("Файл успешно загружен, размер %d байт.",ArraySize(result));
|
|
//PrintFormat("Заголовки сервера: %s",headers);
|
|
//--- сохраняем данные в файл
|
|
int filehandle=FileOpen("in.txt",FILE_WRITE|FILE_BIN);
|
|
if(filehandle!=INVALID_HANDLE)
|
|
{
|
|
//--- сохраняем содержимое массива result[] в файл
|
|
FileWriteArray(filehandle,result,0,ArraySize(result));
|
|
//--- закрываем файл
|
|
FileClose(filehandle);
|
|
}
|
|
else
|
|
Print("Ошибка в FileOpen. Код ошибки =",GetLastError());
|
|
}
|
|
else
|
|
PrintFormat("Ошибка загрузки '%s', код %d",url,res);
|
|
}
|
|
return CharArrayToString(result);
|
|
} |