#include <#_lib_news.mq4>
...
extern bool UseWorkNewsHigh = false;
extern int HighBefore = 30;
extern int HighAfter = 30;
extern bool UseWorkNewsMedium = false;
extern int MediumBefore = 15;
extern int MediumAfter = 15;
extern bool UseWorkNewsLow = false;
extern int LowBefore = 5;
extern int LowAfter = 5;
int prevstatus, prevtime;
string FileNamePrev;
...
int start()
{
if (Urdala_News() == 0) открываем ордер
}
...
int Urdala_News() {
GlobalVariableSet("TimeZone", TimeZone);
GlobalVariableSet("HighBefore", HighBefore);
GlobalVariableSet("HighAfter", HighAfter);
GlobalVariableSet("MediumBefore", MediumBefore);
GlobalVariableSet("MediumAfter", MediumAfter);
GlobalVariableSet("LowBefore", LowBefore);
GlobalVariableSet("LowAfter", LowAfter);
int UNs = 0;
if (UseWorkNewsHigh == false || UseWorkNewsMedium == false || UseWorkNewsLow == false) {
// работаем на открытии М1 баров
if (prevtime == iTime(NULL, PERIOD_M1, 0)) return;
prevtime = iTime(NULL, PERIOD_M1, 0);
// имя файла календаря
int DayFile = TimeDay(TimeCurrent() - TimeDayOfWeek(TimeCurrent()) * 86400);
if (DayFile < 10) string DF = "0" + DayFile;
else DF = DayFile;
int MonthFile = TimeMonth(TimeCurrent() - TimeDayOfWeek(TimeCurrent()) * 86400);
if (MonthFile < 10) string MF = "0" + MonthFile;
else MF = MonthFile;
int YearFile = TimeYear(TimeCurrent() - TimeDayOfWeek(TimeCurrent()) * 86400);
string DateFile = MF + "-" + DF + "-" + YearFile;
string FileName = DateFile + ".csv";
if (FileName != FileNamePrev) {
Print("Reading the next news calendar file: " + FileName);
FileNamePrev = FileName;
// открываем или закачиваем файл
int handle = GetHandle(FileName);
if (handle < 0) {
if (prevstatus > 0) {
Print ("Error opening file " + FileName);
prevstatus = -1;
}
return;
}
prevstatus = 0;
// загружаем данные
FillData(handle);
Print("OK");
}
// устанавливаем флаги
SetNextNews();
// используем фильтр для ограничения торговли
if (UseWorkNewsHigh == false) {
if (GlobalVariableGet("NewsAlertFlag" + StringSubstr(Symbol(), 0, 3)) == 3 && GlobalVariableGet("NewsAlertFlag" + StringSubstr(Symbol(), 3, 3)) == 3) {
UNs = 1;
}
}
if (UseWorkNewsMedium == false) {
if (GlobalVariableGet("NewsAlertFlag" + StringSubstr(Symbol(), 0, 3)) == 2 && GlobalVariableGet("NewsAlertFlag" + StringSubstr(Symbol(), 3, 3)) == 2) {
UNs = 1;
}
}
if (UseWorkNewsLow == false) {
if (GlobalVariableGet("NewsAlertFlag" + StringSubstr(Symbol(), 0, 3)) == 1 && GlobalVariableGet("NewsAlertFlag" + StringSubstr(Symbol(), 3, 3)) == 1) {
UNs = 1;
}
}
}
return(UNs);
}