//+------------------------------------------------------------------+ //| Forexnews.com.mq4 | //| Copyright © 2006, Abhi | //| http://www.megadelfi.com/experts/ | //| E-mail: grabwebexpert{Q)megadelfi.com | //| fix my e-mail address before mailing me ;) | //+------------------------------------------------------------------+ #property copyright "Copyright © 2006, Abhi" #property link "http://www.megadelfi.com/experts/" extern string sUrl = "http://www.forexnews.com/globalcalendar/default.asp"; extern string Outputfile = "Calendar.csv"; extern string Timezone = "EST"; extern string ConvertCanadato = "GBP"; // can change this to a full currency pair such as "GBPUSD" extern string ConvertAustraliato = "GBP"; extern string ConvertE12to = "GBP"; extern string ConvertUKto = "GBP"; extern string ConvertJapanto = "GBP"; extern string ConvertUSto = "GBP"; extern string ConvertEURto = "GBP"; extern string ConvertNZDto = "GBP"; int hSession_IEType; int hSession_Direct; int Internet_Open_Type_Preconfig = 0; int Internet_Open_Type_Direct = 1; int Internet_Open_Type_Proxy = 3; int Buffer_LEN = 13; #import "wininet.dll" int InternetOpenA( string sAgent, int lAccessType, string sProxyName="", string sProxyBypass="", int lFlags=0 ); int InternetOpenUrlA( int hInternetSession, string sUrl, string sHeaders="", int lHeadersLength=0, int lFlags=0, int lContext=0 ); int InternetReadFile( int hFile, string sBuffer, int lNumBytesToRead, int& lNumberOfBytesRead[] ); int InternetCloseHandle( int hInet ); int hSession(bool Direct) { string InternetAgent; if (hSession_IEType == 0) { InternetAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Q312461)"; hSession_IEType = InternetOpenA(InternetAgent, Internet_Open_Type_Preconfig, "0", "0", 0); hSession_Direct = InternetOpenA(InternetAgent, Internet_Open_Type_Direct, "0", "0", 0); } if (Direct) { return(hSession_Direct); } else { return(hSession_IEType); } } int start() { // Print("fake start"); } int init() { int hInternet; string iResult; int lReturn[]={1}; string sBuffer="x"; string sData, csvoutput; int handle; int bytes; int beginning, finalend,end,i; string aju, text, newsdatetime, country, news; hInternet = InternetOpenUrlA(hSession(FALSE), sUrl, "0", 0, 67108864, 0); Print("hInternet: " + hInternet); iResult = InternetReadFile(hInternet, sBuffer, Buffer_LEN, lReturn); Print("iResult: " + iResult); Print("lReturn: " + lReturn[0]); //iResult = InternetCloseHandle(hInternet); Print("iResult: " + iResult); Print("sBuffer: " + sBuffer); Comment("sBuffer: " + sBuffer); bytes = lReturn[0]; sData = StringSubstr(sBuffer, 0, lReturn[0]); //if there's more data then keep reading it into the buffer while (lReturn[0] != 0) { iResult = InternetReadFile(hInternet, sBuffer, Buffer_LEN, lReturn); if (lReturn[0]==0) break; bytes = bytes + lReturn[0]; sData = sData + StringSubstr(sBuffer, 0, lReturn[0]); } Print("sData: " + sData); iResult = InternetCloseHandle(hInternet); Print("iResult: " + iResult); handle=FileOpen(Day()+ "-"+ Month() +"-"+ Year() +"-"+ "grabweb.htm",FILE_BIN|FILE_READ|FILE_WRITE); if(handle<1) { Print("Can\'t open htm file, the last error is ", GetLastError()); return(false); } FileWriteString(handle,sData,StringLen(sData)); FileClose(handle); Print("bytes: "+bytes); // htm file is written, let's parse it now and write to csv file handle=FileOpen(Outputfile,FILE_CSV|FILE_WRITE,","); if(handle<1) { Print("Can\'t open csv file, the last error is ", GetLastError()); return(false); } FileWrite(handle,"Description","Currency","DateTime","TimeZone","Lots","PercentOfMargin","TrailingStop","SecondsBeforeEvent","StraddleDuration"); beginning = 1; beginning = StringFind(sData,"<div class=tti>Actual</div></td>",beginning)+32; finalend = StringFind(sData,"</table>",beginning)-835; while (beginning < finalend) { for (i=0; i <=0; i++) { beginning = StringFind(sData,"<td valign=top align=\"right\"",beginning)+28; beginning = StringFind(sData,"nowrap>",beginning)+7; end = StringFind(sData,"</td>",beginning)-0; if (end != beginning) { text = StringSubstr(sData, beginning, end-beginning); } else { text = ""; } if (i == 0) { if (text != "") { newsdatetime = text; } else { text = newsdatetime; } } } for (i=1; i <=1; i++) { beginning = StringFind(sData,"<td valign=top align=\"middle\"",beginning)+29; beginning = StringFind(sData,">",beginning)+1; end = StringFind(sData,"</td>",beginning)-0; if (end != beginning) { text = StringSubstr(sData, beginning, end-beginning); } else { text = ""; } if (i == 1) { if (text != "") { country = text; } else { text = country; } } } for (i=2; i <=2; i++) { beginning = StringFind(sData,"<td valign=top align=\"left\"",beginning)+27; beginning = StringFind(sData,">",beginning)+1; end = StringFind(sData,"</td>",beginning)-0; if (end != beginning) { text = StringSubstr(sData, beginning, end-beginning); } else { text = ""; } if (i == 2) { if (text != "") { news = text; } else { text = news; } } } if (country == "Canada") country = ConvertCanadato; if (country == "Australia") country = ConvertAustraliato; if (country == "E-12") country = ConvertE12to; if (country == "UK") country = ConvertUKto; if (country == "US") country = ConvertUSto; if (country == "Japan") country = ConvertJapanto; if (country == "EUR") country = ConvertEURto; if (country == "NZD") country = ConvertNZDto; csvoutput = StringConcatenate(news,",",country,",",newsdatetime,",",Timezone); Print("newslist: "+ csvoutput); FileWrite(handle,news,country,newsdatetime,Timezone); } FileClose(handle); return(0); } //+------------------------------------------------------------------+ --------------020207080700060909010908--
Sample
Analysis
Market Information Used:
Indicator Curves created:
Indicators Used:
Custom Indicators Used:
wininet
Order Management characteristics:
Other Features:
Uses files from the file system
It writes information to file