Establishing last data date

I want to establish the last date for which data exists, in order to do some data processing and creating custom watchlists.

Getting the last data date is of course easy by using datenum() or date() functions. My problem comes when an issue that may be thinly traded may not have recent data... and I want to avoid that issue in the new watchlist.

I was thinking of establishing such reference date from a well established issue, such as "SPY" and comparing other issues to that reference date before accepting the issue. Problem I ran into is that SetForeign(xxx) and Foreign(xxx,"C") functions do not affect the date fields so I can not access the date for such a reference symbol.

Anyone has aides on how to manage this? Thanks

Have you explored the use of Pad & Align?

See this page to get started:

If you P&A to a well known symbol, for example SPY in the US Markets, then any "holes" in the data for your current symbol will be filled in with data from the previous bar. To determine whether the current symbol has been trading recently, make sure that the OHLC values are changing.

dt = DateTime();
lastdatadate = LastValue(ValueWhen(C, dt));
printf("Last Data Date: " + DateTimeToStr(lastdatadate));

@ara1, would it be possible for you to "reverse" your testing? My thought is that you could code up a test on the SPY to get the most recent date (set a variable or Global, or a persistent variable), then instead of using the Foreign function, load up the items individually from a "master" or "Full" watchlist, and then check if the date on the current item matches to what the SPY gave you.

@ara1, not sure if it fits your needs, but you may take a look at this thred for a similar problem.

Thanks all for responding ... I ended up implementing snoopy's suggestion .... it does exactly what I wanted