//+------------------------------------------------------------------+ //| Calendar_Investing_ind.mq4 | //| Vorese | //| vorese@yandex.ru | //+------------------------------------------------------------------+ #property copyright "Vorese" #property link "http://www.mql5.com" #property version "1.00" #property strict #property indicator_chart_window #property description "Необходимо добавить адрес ' http://ru.investing.com/economic-calendar/ '" #property description "в список разрешенных URL во вкладке ' Сервис / Настройки / Советники '" #property description "mck_local_times - разница во времени между Москвой и временем на компьютере" //+++++++++++++++++++++++++++++ input int mck_local_times=0; input color color_text=clrBlack; input color border=clrGreen; input color button_off=clrLimeGreen; input color button_on=clrGold; input color rect_label=clrBlack; input color Col_01=clrTurquoise; input color Col_02=clrAliceBlue; input color Col_03=clrDarkOrange; input color Col_04=clrLimeGreen; input int X_DISTANCE=5; input int Y_DISTANCE=15; //+++++++++++++++++++++++++++++ bool button_0=false; bool button_1=false; bool button_2=false; bool button_3=false; bool button_4=false; color col_but0=clrNONE; color col_but1=clrNONE; color col_but2=clrNONE; color col_but3=clrNONE; color col_but4=clrNONE; string symb=_Symbol; int r=0; int t=0; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { col_but0=button_off; col_but1=button_off; col_but2=button_off; col_but3=button_off; col_but4=button_off; ButtonCreate("table",X_DISTANCE+103,Y_DISTANCE,143,9,"предв. прогн. факт."+" ","Verdana",7,color_text,Col_01); ButtonCreate("time",X_DISTANCE,Y_DISTANCE,102,9,"Local","Verdana",7,color_text,Col_01); ButtonCreate("gmt",X_DISTANCE+475,Y_DISTANCE,152,9,"Terminal","Verdana",7,color_text,Col_01); //--проверим настройки календаря-------------------------------------- if(GlobalVariableCheck("text"+symb)) { button_0=true; col_but0=button_on; } if(GlobalVariableCheck("$$$"+symb)) { button_1=true; col_but1=button_on; } if(GlobalVariableCheck("$$"+symb)) { button_2=true; col_but2=button_on; } if(GlobalVariableCheck("$"+symb)) { button_3=true; col_but3=button_on; } //--- create timer EventSetTimer(1); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { f_Delete_object(r); ObjectDelete("table"); ObjectDelete("time"); ObjectDelete("gmt"); ObjectDelete("button0"); ObjectDelete("button1"); ObjectDelete("button2"); ObjectDelete("button3"); ObjectDelete("button4"); GlobalVariableDel("update"); // ObjectsDeleteAll(0,OBJ_BUTTON); // ObjectsDeleteAll(0,OBJ_LABEL); //--- destroy timer EventKillTimer(); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ 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[]) { //--- //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //| Timer function | //+------------------------------------------------------------------+ void OnTimer() { ObjectSetString(0,"time",OBJPROP_TEXT,TimeToString(TimeLocal(),TIME_SECONDS)); ObjectSetString(0,"gmt",OBJPROP_TEXT,"Terminal "+TimeToString(TimeCurrent(),TIME_SECONDS)); ButtonCreate("button0",X_DISTANCE+250,Y_DISTANCE,40,9,"текст","Verdana",6,color_text,col_but0,button_0); ButtonCreate("button1",X_DISTANCE+291,Y_DISTANCE,40,9,"$$$","Verdana",6,color_text,col_but1,button_1); ButtonCreate("button2",X_DISTANCE+332,Y_DISTANCE,40,9,"$$","Verdana",6,color_text,col_but2,button_2); ButtonCreate("button3",X_DISTANCE+373,Y_DISTANCE,40,9,"$","Verdana",6,color_text,col_but3,button_3); if(!GlobalVariableCheck("update")) { button_4=false;col_but4=button_off; } ButtonCreate("button4",X_DISTANCE+414,Y_DISTANCE,60,9,"обновить","Verdana",6,color_text,col_but4,button_4); //=====читаем файл , находим начало и конец таблицы=================== int handle; int string_counter=0; int begin_table=0; int end_table=0; string temp_array[6000]; handle=FileOpen("investing.html",FILE_CSV|FILE_READ|FILE_SHARE_READ,CP_ACP); if(handle<1)Print("Файл не прочитан ",handle); else while(!FileIsEnding(handle)) { temp_array[string_counter]=FileReadString(handle); if(f_Position(temp_array[string_counter],0)>=0 && string_counter>600) { begin_table=string_counter; } if(begin_table>0 && f_Position(temp_array[string_counter],1)>=0) { end_table=string_counter; break; } string_counter++; } FileClose(handle); //===============Вырезаем текст из тегов============================== string time_ind[70],//время currency[70],// валюта volatility[70],//волатильность text_ind[70],//текст previous[70],//предыдущий forecast[70],//прогноз fact[70],//факт compliance[70];//ожидания string array_table="", volatility_str="?", compliance_str="?", previous_str="", forecast_str="", fact_str=""; int sum_string=0, td_class=0, td=0, angle=0, span=0, span_1=0, pos_begin=0, pos_end=0, counter_news=0, counter_str=0, pos_t=0, i=begin_table; //------------------------------------------------------------------- while(i!=end_table && counter_news<70)// не более 70 строк { td_class=f_Position(temp_array[i],2); td=f_Position(temp_array[i],3); if(td_class<0 && td<0) // ищем строки новостей { sum_string=0; i++; continue; } else { if(td==0) { i++;continue;} else sum_string++; } angle=f_Position(temp_array[i],4); span=f_Position(temp_array[i],5); span_1=f_Position(temp_array[i],6); pos_t=f_Position(temp_array[i],14); if(sum_string==1) //время { if(pos_t<0) time_ind[counter_news]=StringSubstr(temp_array[i],angle+1,5); else time_ind[counter_news]=StringSubstr(temp_array[i],pos_t+13,5); } if(sum_string==2) //валюта { currency[counter_news]=StringSubstr(temp_array[i],span+8,3); } if(sum_string==3) //волатильность { array_table=StringSubstr(temp_array[i],0,angle); volatility_str=f_Cyrillic(array_table); if(f_Position(volatility_str,7)>0) volatility[counter_news]="$$$"; else { if(f_Position(volatility_str,8)>0) volatility[counter_news]="$$"; else { if(f_Position(volatility_str,9)>0) volatility[counter_news]="$"; else { volatility[counter_news]="?"; } } } } if(sum_string==4) //текст { if(span_1<0) array_table=StringSubstr(temp_array[i],angle+1,td-angle-1); else array_table=StringSubstr(temp_array[i],angle+1,span_1-angle-7); text_ind[counter_news]=StringTrimLeft(f_Cyrillic(array_table)); } if(sum_string==5) //результат ожиданий , факт { array_table=StringSubstr(temp_array[i],0,angle+1); compliance_str=f_Cyrillic(array_table); if(f_Position(compliance_str,10)>0) compliance[counter_news]="+"; else { if(f_Position(compliance_str,11)>0) compliance[counter_news]="="; else { if(f_Position(compliance_str,12)>0) compliance[counter_news]="-"; else { compliance[counter_news]="?"; } } } fact_str=StringSubstr(temp_array[i],angle+1,td-angle-1); if(f_Position(fact_str,13)>=0) fact[counter_news]="----"; else fact[counter_news]=fact_str; } if(sum_string==6) //прогноз forecast_str=StringSubstr(temp_array[i],angle+1,td-angle-1); if(f_Position(forecast_str,13)>=0) forecast[counter_news]="----"; else forecast[counter_news]=forecast_str; if(sum_string==7) //предыдущий previous_str=StringSubstr(temp_array[i],angle+1,td-angle-1); if(f_Position(previous_str,13)>=0) previous[counter_news]="----"; else previous[counter_news]=previous_str; if(sum_string==8) { counter_news++; counter_str++; } i++; } //=========формируем таблицу========================================== //удаляем все объекты после измен. в календаре if(counter_str!=r && r>0) f_Delete_object(r); //--------------------------------------------------------------------- r=0; t=0; color color_button=Col_04; color color_compliance=Col_04; while(r!=counter_str) //фильтруем по волатильности { if(volatility[r]=="$$$" && button_1) { r++;continue;} if(volatility[r]=="$$" && button_2) { r++;continue;} if(volatility[r]=="$" && button_3) { r++;continue;} //-------------------------------------------------------------------- //цвет прошедших и будущих новостей if((StrToTime(time_ind[r])>=(TimeLocal()+mck_local_times*3600)) || TimeDayOfWeek(TimeLocal())==0 || TimeDayOfWeek(TimeLocal())==6)color_button=Col_04; else color_button=Col_01; if(compliance[r]=="+")color_compliance=Col_02; else { if(compliance[r]=="-")color_compliance=Col_03; else { color_compliance=color_button; } } // создаем таблицу ButtonCreate("time"+(string)t,X_DISTANCE,Y_DISTANCE+13+11*t,40,9,TimeToString(StrToTime(time_ind[r])-mck_local_times*3600,TIME_MINUTES),"Verdana",6,color_text,color_button,false,border); ButtonCreate("currency"+(string)t,X_DISTANCE+41,Y_DISTANCE+13+11*t,30,9,currency[r],"Verdana",6,color_text,color_button,false,border); ButtonCreate("volatility"+(string)t,X_DISTANCE+72,Y_DISTANCE+13+11*t,30,9,volatility[r],"Verdana",6,color_text,color_button,false,border); ButtonCreate("previous"+(string)t,X_DISTANCE+103,Y_DISTANCE+13+11*t,40,9,previous[r],"Verdana",6,color_text,color_button,false,border); ButtonCreate("forecast"+(string)t,X_DISTANCE+144,Y_DISTANCE+13+11*t,40,9,forecast[r],"Verdana",6,color_text,color_button,false,border); ButtonCreate("fact"+(string)t,X_DISTANCE+185,Y_DISTANCE+13+11*t,40,9,fact[r],"Verdana",6,color_text,color_compliance,false,border); ButtonCreate("compliance"+(string)t,X_DISTANCE+226,Y_DISTANCE+13+11*t,20,9,compliance[r],"Verdana",6,color_text,color_compliance,false,border); if(!button_0) { RectLabelCreate("LabelCreate"+(string)t,X_DISTANCE+247,Y_DISTANCE+12+11*t,380,12,rect_label,rect_label); f_Label("text"+(string)t,X_DISTANCE+250,Y_DISTANCE+10+11*t,text_ind[r],7,"Verdana",color_button); } r++; t++; } ChartRedraw(); //==================================================================== } // конец OnTimer //==================================================================== void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam) { //--- сбросим значение ошибки ResetLastError(); //--- проверка события нажатия на кнопку мыши if(id==CHARTEVENT_OBJECT_CLICK) { //--------------кнопка "текст"---------------------------------- if(sparam=="button0" && !button_0) { button_0=true; GlobalVariableSet("text"+symb,0); // запомним , что кнопка нажата for(int v=0;v","",">","","