Showing a News Window

I swing trade and spend a fair amount of time reading news and picking up comments from other people about stocks that I watch. I had been putting them into text boxes on charts but it's a very time consuming process, so instead I created a CSV file that I add to in excel with 3 columns: Ticker, date and the note and then I created a blank chart window on my screen and feed these in so I can see a listing of all the news and notes about these stocks from the excel/csv file. I have included a picture.

The code is working great ( I adapted it from code I use for something else) but I realized that it is continually scanning the CSV file in real time, which I don't need it to do. It would be fine if it just scanned the file once when I changed tickers. I don't think it's a big resource hog at this point but was wondering if there was a better way to do this and/or a way to just scan the file and populate the window once when I switch tickers rather than having it continually scanning in the background.
SNAG-6395

pathnews = "D:\\amibrokerinfo\\news.csv";
fh = fopen(pathnews, "r");
xspot = 4;
yspot = 30;
xwid = 800;
if(fh)
	{
		while( ! feof( fh ) ) 
		{ 
			line = fgets( fh ) ;    
			strSymbol = StrExtract(line, 0);
			strDate = StrExtract(line, 1);
			strnote = StrExtract(line,2);
			if(StrToUpper(strSymbol) == Name())
			{
				thisnote = strdate + " - " + Strnote;
				GfxDrawText(thisnote,xspot, yspot, xspot+xwid, yspot + 60,0);
				yspot = yspot + 25;
			}
		} 		
		
	
fclose(fh);
}
else
{
	Error("Could not find " + pathnews);

You can adapt from below KB.
Instead of storing DateTime() or symbol_DT, just store the current symbol in static variable( SV ).

// get ticker from SV
symbol_in_SV = ...

if( Name() != symbol_in_SV ) {
    // read csv
    // update SV with new symbol name
}
2 Likes

Thanks @nsm51 I'll take a look at this this weekend.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.