find the code attached below, so the ReadCBOE function reads information from investing.com and saves it to string str, Update news function then analyzes the information obtained from ReadCBOE and stores it into relevant arrays, the code is running without any errors just cant figure out why information is not being stored correctly into the arrays. ps the same code works perfectly on mt4
//---------------------------------------------------------------------+
string ReadCBOE()
{
string cookie=NULL,headers;
char post[],result[]; string TXT="";
int res;
string str;
string google_url="http://ec.forexprostools.com/?columns=exc_currency,exc_importance&importance=1,2,3&calType=week&timeZone=15&lang=1";
ResetLastError();
int timeout=5000;
res=WebRequest("GET",google_url,cookie,NULL,timeout,post,0,result,headers);
if(res==-1)
{
Print("WebRequest error, err.code =",GetLastError());
MessageBox("You must add the address 'http://ec.forexprostools.com/' in the list of allowed URL tab 'Advisors' "," Error ",MB_ICONINFORMATION);
}
else
{
int filehandle=FileOpen("news-log.html",FILE_WRITE|FILE_BIN|FILE_ANSI);
if(filehandle!=INVALID_HANDLE)
{
FileWriteArray(filehandle,result,0,ArraySize(result));
FileClose(filehandle);
//------
int file_handle=FileOpen("news-log.html",FILE_READ|FILE_BIN|FILE_ANSI);
if(file_handle!=INVALID_HANDLE)
{
str=FileReadString(file_handle,int(FileSize(file_handle)));
FileClose(file_handle);
}
else PrintFormat("Failed to open %s file, Error code = %d","news-log.html",GetLastError());
}
}
return(str);
}
//-------------------------------------------------------+
void UpdateNews()
{
string TEXT=ReadCBOE();
int sh = StringFind(TEXT,"pageStartAt>")+12;
int sh2= StringFind(TEXT,"</tbody>");
TEXT=StringSubstr(TEXT,sh,sh2-sh);
sh=0;
while(!IsStopped())
{
sh = StringFind(TEXT,"event_timestamp",sh)+17;
sh2= StringFind(TEXT,"onclick",sh)-2;
if(sh<17 || sh2<0)break;
NewsArr[0][NomNews]=StringSubstr(TEXT,sh,sh2-sh);
sh = StringFind(TEXT,"flagCur",sh)+10;
sh2= sh+3;
if(sh<10 || sh2<3)break;
NewsArr[1][NomNews]=StringSubstr(TEXT,sh,sh2-sh);
sh = StringFind(TEXT,"title",sh)+7;
sh2= StringFind(TEXT,"Volatility",sh)-1;
if(sh<7 || sh2<0)break;
NewsArr[2][NomNews]=StringSubstr(TEXT,sh,sh2-sh);
if(StringFind(NewsArr[2][NomNews],"High")>=0 && !HighNews)continue;Print("Found");
if(StringFind(NewsArr[2][NomNews],"Moderate")>=0 && !MidleNews)continue;
if(StringFind(NewsArr[2][NomNews],"Low")>=0 && !LowNews)continue;
sh=StringFind(TEXT,"left event",sh)+12;
int sh1=StringFind(TEXT,"Speaks",sh);
sh2=StringFind(TEXT,"<",sh);
if(sh<12 || sh2<0)break;
if(sh1<0 || sh1>sh2)NewsArr[3][NomNews]=StringSubstr(TEXT,sh,sh2-sh);
else NewsArr[3][NomNews]=StringSubstr(TEXT,sh,sh1-sh);
NomNews++;
if(NomNews==300)break;
}
}
Try the following code which should work for larger strings.
string ReadCBOE()
{
string cookie=NULL,headers;
char post[],result[]; string TXT="";
int res;
string str;
string google_url="http://ec.forexprostools.com/?columns=exc_currency,exc_importance&importance=1,2,3&calType=week&timeZone=15&lang=1";
ResetLastError();
int timeout=5000;
res=WebRequest("GET",google_url,cookie,NULL,timeout,post,0,result,headers);
if(res==-1)
{
Print("WebRequest error, err.code =",GetLastError());
MessageBox("You must add the address 'http://ec.forexprostools.com/' in the list of allowed URL tab 'Advisors' "," Error ",MB_ICONINFORMATION);
}
else
{
int filehandle=FileOpen("news-log.html",FILE_WRITE|FILE_BIN|FILE_ANSI);
if(filehandle!=INVALID_HANDLE)
{
FileWriteArray(filehandle,result,0,ArraySize(result));
FileClose(filehandle);
//------
int file_handle=FileOpen("news-log.html",FILE_READ|FILE_BIN|FILE_ANSI);
if(file_handle!=INVALID_HANDLE)
{
do
{
ResetLastError();
string Largestr=FileReadString(file_handle,4000);
if(GetLastError()!=0) break;
StringConcatenate(str,str,Largestr);
}
while(GetLastError()==0 && !FileIsEnding(file_handle));
FileClose(file_handle);
}
else PrintFormat("Failed to open %s file, Error code = %d","news-log.html",GetLastError());
}
}
return(str);
}