#property strict
#include <CDownloadFile.mqh>;
extern string __news__ = "--- FFCal News Filter --- ";
extern bool UseNewsFilter = true;
extern int MinsBeforeNews = 30;
extern int MinsAfterNews = 30;
extern bool IncludeHigh = true;
extern bool IncludeMedium = true;
extern bool IncludeLow = false;
extern int OffsetHoursGMT = 0;
extern bool CloseProfitableTradesBeforeNews = false;
enum NEWS_IMPACT
{
IMPACT_NONE = 0,
IMPACT_HIGH = 1,
IMPACT_MEDIUM = 2,
IMPACT_LOW = 3
};
class CNewsEvent
{
public:
string Title;
string Country;
datetime DateTime;
NEWS_IMPACT Impact;
string GetImpact()
{
if (Impact == IMPACT_HIGH) return "High ";
if (Impact == IMPACT_MEDIUM) return "Medium ";
if (Impact == IMPACT_LOW) return "Low ";
return "";
}
};
class CNewsFilter
{
private:
CNewsEvent* _newsEvents[];
int _maxEvents;
datetime _lastDownloaded;
datetime _lastDownloadRetry;
string MakeDateTime(string strDate, string strTime)
{
int n1stDash = StringFind(strDate, "-");
int n2ndDash = StringFind(strDate, "-", n1stDash+1);
string strMonth = StringSubstr(strDate, 0, 2);
string strDay = StringSubstr(strDate, 3, 2);
string strYear = StringSubstr(strDate, 6, 4);
int nTimeColonPos = StringFind(strTime, ":");
string strHour = StringSubstr(strTime, 0, nTimeColonPos);
string strMinute = StringSubstr(strTime, nTimeColonPos+1, 2);
string strAM_PM = StringSubstr(strTime, StringLen(strTime)-2);
int nHour24 = StrToInteger(strHour);
if ((strAM_PM == "pm" || strAM_PM == "PM") && nHour24 != 12)
{
nHour24 += 12;
}
if ((strAM_PM == "am" || strAM_PM == "AM") && nHour24 == 12)
{
nHour24 = 0;
}
string strHourPad = "";
if (nHour24 < 10)
strHourPad = "0";
return(StringConcatenate(strYear, ".", strMonth, ".", strDay, " ", strHourPad, nHour24, ":", strMinute));
}
datetime TimeGMTFIX()
{
return(TimeGMT()+(OffsetHoursGMT * 3600));
}
public:
CNewsFilter()
{
_maxEvents = 0;
_lastDownloaded = 0;
_lastDownloadRetry =0;
ArrayResize(_newsEvents, 500);
}
~CNewsFilter()
{
for (int i=0; i < _maxEvents;++i)
delete _newsEvents[i];
_maxEvents=0;
}
void DownloadNews()
{
if (!IsConnected())
{
return;
}
double timeSpanMins = (double)(TimeCurrent() - _lastDownloaded);
timeSpanMins /= 60.0;
if (_maxEvents == 0 || timeSpanMins >= (60*24) )
{
timeSpanMins = (double)(TimeCurrent() - _lastDownloadRetry);
timeSpanMins /= 60.0;
if (timeSpanMins < 5)
{
return;
}
_lastDownloadRetry = TimeCurrent();
string url= "";
string news="";
CDownloadFile* downloader = new CDownloadFile();
bool result = downloader.GrabWeb(url, news);
delete downloader;
int end = StringFind(news, "</weeklyevents>", 0);
if (end <= 0)
{
Print("-- unable to download news --");
return ;
}
else
{
_lastDownloaded = TimeCurrent();
Parse(news);
}
}
}
void Parse(string news)
{
for (int i=0; i < _maxEvents;++i)
delete _newsEvents[i];
_maxEvents=0;
int BoEvent = 0;
int end=0;
string sTags[7] = { "<title>", "<country>", "<date>", "<time>", "<impact>", "<forecast>", "<previous>" };
string eTags[7] = { "</title>", "</country>", "</date>", "</time>", "</impact>", "</forecast>", "</previous>" };
while (true)
{
BoEvent = StringFind(news, "<event>", BoEvent);
if (BoEvent == -1) break;
BoEvent += 7;
int next = StringFind(newsПоказано первые 50% кода (символов: 4908)
Введите ваш email и нажмите кнопку, чтобы перейти к оплате.