plot and study news on chart

 


My goal was to plot previous news on the chart for unlimited period, as well as the current week's news. Indicator forex_ news_market_clock.mq4 ( https://www.mql5.com/en/code/10459 ) only plots news for limited current week, because dailyFX has only current week file in the url directory http://www.dailyfx.com/files/; changing the url from where the indicator will download the file (modified file, with more of previous data news, and not only current week's news) didn't work - the indicator managed to download the file, but not to read it and plot the news...my knowledge is very limited to understand why... (I have just b asics is html 4, css, sql, php,...it's way not enough)

So I indulged myself to tinker with the code and got what I want with the following :

I want that the indicator doesn't download updates every time and read only from the saved csv file. I'll just have to update manualy the downloaded news.csv from dailyFX in the directory terminal_directory\experts\files to get previews news, as well with current week's news.

So to prevent the indicator to update the csv file I change int update_interval =15; to int update_interval =0; (the question if 0 will change something?)

Then to prevent the indicator to download a csv every time I reboot MT4 of refresh the chart

void InitNews(string& news[][],int timeZone, string newsUrl)

{

if(DoFileDownLoad()) //Added to check if the CSV file already exists

{

DownLoadWebPageToFile(newsUrl); //downloading the CSV file

I just erase this line (sure there is a better way to do it )

lastUpdate=TimeCurrent();

}

if(CsvNewsFileToArray(news) == 0)

return(0);

NormalizeNewsData(news,timeZone);

}

Then I have all news as plotted in the attached screen capture. I update manually the csv file ...

An idea just popped up in my head - have the possibility to choose what kind of lines I want to plot. Let's say Non farm payroll ( actual figure is < then the forecasted) will have a code NFPR0, and Non farm payroll ( actual figure is > then the forecasted) will have a code NFPR1, in the csv file, then I can choose to plot only NFPR0 and NFPR1 from one csv file. NFPR0 line will be in red and NFPR1 will be in blue etc...but how to get this result ? Any hint, and what part in the code needs to be changed are welcomed in this forum.

There is another little obstacle for my goal : In the code it was set int update_interval =15; so I changed to let's say 480, int update_interval =480; (setting to 1000 make windows 8 to crash...). But this means that I'll need to restart MT4 every 8 hours ? What change in the code do i need to do in order to cancel the updates from dailyFX ?

ps - as attached the slightly modified mq4 and a screen shot of news plotted (from june 24th to july 19th) instead of just july 15th to 19th...

I'll appreciate your help

Kind Regards,

 

I want that the indicator doesn't download updates every time and read only from the saved csv file. I'll just have to update manualy the downloaded news.csv from dailyFX in the directory terminal_directory\experts\files to get previews news, as well with current week's news.

// ----------------------------------------------------------------------------------------------------------------------------- 
void InitNews(string& news[][],int timeZone, string newsUrl)
{
   if(DoFileDownLoad()) //Added to check if the CSV file already exists
         {
          DownLoadWebPageToFile(newsUrl); //downloading the CSV file
          lastUpdate=TimeCurrent();
         } 
     if(CsvNewsFileToArray(news) == 0) 
         return(0);
     
     NormalizeNewsData(news,timeZone);
}

// -----------------------------------------------------------------------------------------------------------------------------
bool DoFileDownLoad() // If we have recent file don't download again
{
 int handle;
 datetime time = TimeCurrent();
 handle=FileOpen(NewsFileName(), FILE_READ);  //commando to open the file
 if(handle>0)//when the file exists we read data
 {
   FileClose(handle);//close it again check is done
   if(time >= lastUpdate+update_interval*60)return(true); 
   return(false);//file exists no need to download again
 }
 // File does not exist if FileOpen return -1 or if GetLastError = ERR_CANNOT_OPEN_FILE (4103)
 return(true); //commando true to download CSV file
}

to cancel the updates from dailyFX ? blue line has not to become true

not that difficult i think for you to do

have done before searching specific news but have to search for it.....

so that clue i'm not gonna give this moment

 

Well thanks, doing this way at lease it doesn't say "Function "DownLoadWebPageToFile" is not referenced and will be removed from exp-file", it should have been obvious to me !

I have 0 knowledge in javascript, would you be so kind to explain in english what does mean if (time >= lastUpdate+update_interval* 60 ) ? Approximately for my understanding, it is smth like, if the last update time is > then assigned (means recorded last update time) + the update interval but why *60 ? Wy *60 ? What does this means ?

Kind Regards,

 
Now we are saturday 20th and it doesn't plot any news at all. I can't find the code where it says not to plot news when markets are closed !
 
samuel2013 :

Well thanks, doing this way at lease it doesn't say "Function "DownLoadWebPageToFile" is not referenced and will be removed from exp-file", it should have been obvious to me !

I have 0 knowledge in javascript, would you be so kind to explain in english what does mean if (time >= lastUpdate+update_interval* 60 ) ? Approximately for my understanding, it is smth like, if the last update time is > then assigned (means recorded last update time) + the update interval but why *60 ? Wy *60 ? What does this means ?

Kind Regards,

datetime time = TimeCurrent();
   if(DoFileDownLoad()) //Added to check if the CSV file already exists
         {
          DownLoadWebPageToFile(newsUrl); //downloading the CSV file
          lastUpdate=TimeCurrent();
         } 
int        update_interval =15;

Wy *60 ? Check what datetime means

https://docs.mql4.com/basis/types/datetime

Time of News can change and number of newsitems can change

so the indicator was made to upload the file for checking the latest changes

 
Actually it plots news at day -1, and the time is not correct any more. I think because indicator thinks that friday is saturday and offsets the lines to day-1. Then when I set PC date to friday instead of saturday, the lines gets to right position, almost excet the time is not correct. Anyways, I don't understand the logic of plotting the lines ...
 
samuel2013 :
Actually it plots news at day -1, and the time is not correct any more. I think because indicator thinks that friday is saturday and offsets the lines to day-1. Then when I set PC date to friday instead of saturday, the lines gets to right position, almost excet the time is not correct. Anyways, I don't understand the logic of plotting the lines ...


your brokers is not updating while your pcclock is still running

also i noticed you have used the version from codebase but if you read the comments you can find there also

there is a version to find that is calculating the time more accurate ....

What is it doing it is using your pctime and gets with it also GMT-time no matter DST

now it can calculate the GMT shift of your broker..... that is when the markets are open

according to the outcome of GMT shift it place the Line Objects on your broker charts

 
the weekend is now done so it will now get the right GMT-shift and the lines will become at the correct place of your chart
 

Yep you are right when the broker time works it pots news at "almost" the right time. But I have an issue with "almost". For 5M, 15M, 30M, it plots the line one bar behind when we have the news. For example the news are anounced at 13:30 it will plot the line at 13:00 broker time on 30M TF, 13:25 on the M5 TF... The news in the excel spreadsheet are all GMT; the broker time is GMT+1. I've set the GMT shift to 1 so logically it has to offset all data by one hour, but instead it plots the line one bar ahead. So My guess is that somewhere in this code it is said to do so. Where it can be ? I can't find it.

Also I declared bool so that it can read good/bad news for USD, EUR, GBP and plot different colors lines,

extern bool   show_goodusd_news    = true;
extern bool   show_badusd_news    = true;
extern bool   show_goodeur_news    = true;
extern bool   show_badeur_news    = true;
extern bool   show_goodgbp_news    = true;
extern bool   show_badgbp_news    = true;

and

 for(int i = 0 ; i <10; i++)
                     {          
                        lineData = FileReadString(handle);              
                        if(lineData == "Low" || lineData == "Medium" || lineData == "LOW" || lineData == "High" || lineData == "HIGH" || lineData == "Goodeur" || lineData == "Badeur" || lineData == "Goodgbp" || lineData == "Badgbp"|| lineData == "Goodusd" || lineData == "Badusd")
                        {    
                          lines[lineNumber][freeTextCol+1] = lineData;
                          itemCount = freeTextCol+1;           
                          break;
                        } 

then I'm lost don't know what to do.

 
I meant one bar behind
 
And new line that I wanted to add are below, but I'm lost don't know what to do next...
lineData == "Goodeur" || lineData == "Badeur" || lineData == "Goodgbp" || lineData == "Badgbp"|| lineData == "Goodusd" || lineData == "Badusd")
Reason: