//+------------------------------------------------------------------+
//| FF CAL XML Reader V003.mq4 |
//| Shoofra |
//| |
//+------------------------------------------------------------------+
#property copyright "Shoofra"
#property link ""
#property indicator_chart_window
#define _EVENT 0
#define _COUNTRY 1
#define _DATE 2
#define _TIME 3
#define _IMPACT 4
#define _DATETIME 5
extern int GMT_OFFSET = 2;
extern bool SHOW_CAL =false;
extern string _news = "=========NEWS PARAMETERS=========";
extern string news_csv_file_name = "ffcal_week_this.xml";
extern int min_stop_before_news = 30;
extern int min_resume_after_news= 8;
extern string _colors = "===========Alert Colors==========";
extern color High_Impact_Color = Red;
extern color Medium_Impact_Color = Orange;
extern color Low_Impact_Color = Yellow;
extern color Over_Due_Color = Green;
extern string _INSTRUCTIONS_START = "============INSTRUCTIONS============";
extern string _istructions_L1 = "1) Load Forex Factory Calendar XML from:";
extern string _istructions_L2 = "http://www.forexfactory.com/ffcal_week_this.xml";
extern string _istructions_L3 = "2) Save the XML file to:";
extern string _istructions_L4 = "C:\Program Files\~MT4 dir~\experts\files";
extern string _istructions_L5 = "Load XML every Sunday for the folowing Week";
extern string _INSTRUCTIONS_END = "========END of INSTRUCTIONS=========";
extern string _s = "";
extern string _tags = "========XML TAGS========";
extern string evnet_start = "",
event_end = "",
title_start = "
",
title_end = "",
country_start = "",
country_end = "",
date_start = "",
time_start = "",
impact_start = "";
string ver = "FF CAL XML Reader V003 by Shoofra";
string prefix = "FF_XML_CAL_";
string event_line[300][6];
int eventsCount =0;
int start()
{
int eline=0;
string p;
int handle;
string str;
eventsCount=0;
handle=FileOpen(news_csv_file_name, FILE_CSV|FILE_READ);
while(!FileIsEnding(handle))
{
if(handle>0)
{
str=FileReadString(handle);
}
parseStr(str,title_start,title_end,_EVENT);
parseStr(str,country_start,country_end,_COUNTRY);
parseStr(str,date_start,date_end,_DATE);
parseStr(str,time_start,time_end,_TIME);
parseStr(str,impact_start,impact_end,_IMPACT);
event_line[eventsCount][_DATETIME]=StringConcatenate(event_line[eventsCount][_DATE]," ",event_line[eventsCount][_TIME]);
if(StringFind(str,event_end)>-1) eventsCount++; //new Calender Item
}
FileClose(handle);
if(SHOW_CAL) show_cal();
checkTime();
write("ver",ver, 7, Orange,20,20,2);
return(0);
}
void checkTime()
{
int countAlerts=0;
deleteNewsAlerts("news_");
for(int cal_item=0;cal_item<200;cal_item++)
{
datetime preNews=StrToTime(event_line[cal_item][_DATETIME])-(min_stop_before_news*60);
datetime postNews=StrToTime(event_line[cal_item][_DATETIME])+(min_resume_after_news*60);
if(TimeCurrent()>preNews && TimeCurrent()=0; i--)
{
obj = ObjectName(i);
if(StringFind(obj,include,0)>=0) ObjectDelete(obj);
}
}
string parseStr(string str, string startTag, string endTag, int tagCount)
{
string txt;
int spos=-1,epos=-1;
if(StringFind(str,startTag)>-1)
{
if(StringFind(str,endTag)>-1)
{
spos=StringFind(str,startTag)+StringLen(startTag);
epos=StringLen(str)-StringLen(endTag)-StringLen(startTag)-2;
event_line[eventsCount][tagCount]=StringSubstr(str,spos,epos);
}
txt=event_line[eventsCount][tagCount];
if(tagCount==_TIME)
{
int h;
if(StringFind(txt,"pm")>-1)
{
txt=StringSubstr(txt,0,StringLen(txt)-2);
h=StrToInteger(StringSubstr(txt,0,2));
if(h==12) h=-12;
txt=(h+12+GMT_OFFSET)+StringSubstr(txt,StringFind(txt,":",0),StringLen(txt));
}
if(StringFind(txt,"am")>-1)
{
txt=StringSubstr(txt,0,StringLen(txt)-2);
h=StrToInteger(StringSubstr(txt,0,2));
if(h==12) h=0;
txt=(h+GMT_OFFSET)+StringSubstr(txt,StringFind(txt,":",0),StringLen(txt));
}
}
if(tagCount==_DATE)
{
txt=StringSubstr(txt,StringLen(txt)-4)+"."+StringSubstr(txt,0,StringLen(txt)-5);
txt=StringSubstr(txt,0,StringLen(txt)-3)+"."+StringSubstr(txt,StringLen(txt)-2,2);
}
event_line[eventsCount][tagCount]=txt;
return(txt);
}
else
return("");
}
void show_cal()
{
string p="\nTime="+TimeToStr(TimeCurrent())+" GMT-OFFSET="+GMT_OFFSET+" GMT-Time="+TimeToStr(TimeCurrent()-(3600*GMT_OFFSET))+"\n=============================================\n";
for(int e=0;e<100;e++)
{
datetime time=StrToTime(StringConcatenate(event_line[e][_DATE]," ",event_line[e][_TIME]));
p=p+e+") "+event_line[e][_COUNTRY]+" "+event_line[e][_DATE]+" "+event_line[e][_TIME]+" time="+event_line[e][_DATETIME]+"\n";
}
Comment(p);
}
void write(string name, string txt, int font_size, color col, int xpos, int ypos, int corner)
{
if(true)
{
name=prefix+name;
if(ObjectFind(name)==true) ObjectDelete(name);
ObjectCreate(name,OBJ_LABEL,0,0,0);
ObjectSetText(name,txt, font_size, "Arial", col);
ObjectSet(name, OBJPROP_CORNER, corner);
ObjectSet(name, OBJPROP_XDISTANCE, xpos);
ObjectSet(name, OBJPROP_YDISTANCE, ypos);
}
//write("o4",currOrder4, 9, White,20,120,1);
}
int deinit()
{
deleteNewsAlerts(prefix);
return(0);
}
int init()
{
start();
return(0);
}