Restricting scans to young stocks

Over the past weeks, have managed to create rules using AFL code Wizard.
However, I'd like to narrow my scans to young stocks whose IPO was < 10 years ago.
How do I restrict to younger stocks.
Thank you for being gentle and not rude in your response ...
I'm a relative beginner, but so far have learned a lot.

yr = Year();
firstyear = yr[0];
youngstock = LastValue(yr)-firstyear <= 10;

or

yr = Year();
firstyear = yr[0];
youngstock = Now(8)-firstyear <= 10;

If you use Exploration than add youngstock variable to Filter

Filter = youngstock;

If you only want to output results of those stocks at last bar then add

Filter = youngstock AND Status( "lastbarinrange" );

Note: yr[0] is not really save method as it could be a stock just having missing historical data before yr[0].
So other method could be to have some external IPO data to read from.

5 Likes

Very helpful.
Thank you fxshrat.