Counting active Stocks within a Stock-Index on Norgate Data

Good day everyone,
i have following problem and i am hoping for some pointers in the right direction.

I am trying to count 'active' Stocks on Norgate Data because i would like to find out what percentage of Stocks closed positive within the Index.

To do this i open the Watchlist 'SP500 Current and Past' which currently contains 1229 Stocks, from these 1229 stocks it should contain a bit more than 720 Delisted stocks (Today).

This obviously does not work as said watchlist contains all of those stocks:

NoM = StrCount( MarketList, "," ) ;

I then try to count them inside a loop:

    Count = 0;

    for ( i = 0; ( symbol = StrExtract( marketlist, i ) )  != "";  i++ )
    {
        SetForeign ( symbol );
            
            Count += NOT IsNull(C);

        RestorePriceArrays();
   }

This also gives me 1229 Stocks. Now if i open a chart of one of the Delisted stocks from the backtest Report, it will have valid OHLCV values for example untill a certain Date in 2013, and then the Data just stops.

My Question, what am i doing wrong ? Should i be comparing the date of the Stock to the Date of the AFL to exlude those delisted Stocks, if so how could this be achieved ?

Don't you remember your previous thread and given response?

1 Like

Now for delisted stocks you may add date in Information window and then call that date.

36

dt = Datetime();

delisting_date = GetFnData("DelistingDate");
is_delisted = DateTimeDiff(dt, delisting_date) > 0;

Or using foreign one

dt = Datetime();

symbol = "AAPL";
delisting_date = GetFnDataForeign("DelistingDate", symbol);
is_delisted = DateTimeDiff(dt, delisting_date) > 0;

Then use StaticVarAdd to get number of stocks.

So no loop requried.

1 Like

Hello fxshrat.

Actually i do and i was certain to find the solution there, so i went over it again a few times.

In that thread i was looking to ignore symbols that had empty tickers, here i try to do the opposite and
exclude them. Nz converts null to zero and the below statement checks for valid prints if i am correct ? What are you saying, where am i going wrong here ?

count += NOT IsNull(C);

Above example which was the solution you gave me give me at that time, gives me all symbols including delisted ones. 58 symbols on the $DJI. Shouldnt it add 1 to every Closing print that contains a valid value ? There must be something i am missing.

My reply came in a bit late i see. I didnt think about using Norgate's function but that seems logical. Let me try that, i am not yet familiar with StaticVar Add/Get but i am sure with your information and after a bit of reading i can make this work.

Thank you.

I have been told i had an Error in my opening post as i wrote

SetForeign ( symbol );

which is wrong and should be

SetForeign ( symbol,0 );

i just wanted to correct that.

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