Thanks for looking into my requirement and sharing your thoughts.
Please find below my attempt at doing the above. As this is my first AFL in the forum, could you please review if I am doing it correctly and also please advise how to add columns (Q1, Q2, etc) to this result?
_SECTION_BEGIN( "how-to-get-each-quarter-closing-price-per-year-with-in-the-date-range" );
tradingDays = 252; // trading days in a year
bi = BarIndex();
fbr = Status( "firstbarinrange" );
lbr = Status( "lastbarinrange" );
dt = DateTime();
startDate = ValueWhen( fbr, dt );
endDate = ValueWhen( lbr, dt );
high1Y = HHV( H, 1 * tradingDays );
high1YDate = ValueWhen( H == high1Y, DateTime(), 1 );
high2Y = HHV( H, 2 * tradingDays );
high2YDate = ValueWhen( H == high2Y, DateTime(), 1 );
low1Y = LLV( L, 1 * tradingDays );
low1YDate = ValueWhen( L == low1Y, DateTime(), 1 );
low2Y = LLV( L, 2 * tradingDays );
low2YDate = ValueWhen( L == low2Y, DateTime(), 1 );
currentY = Year();
lookBackY1 = Year() - 1 ;
monthEnd = Month() != Ref( Month(), 1 );
quarterEnd = Month()%3 == 0 AND MonthEnd;
_SECTION_END();
///////////////////////////////////////////////////////////////////////////////////////////
// EXPLORATION CODE //
///////////////////////////////////////////////////////////////////////////////////////////
if( Status( "action" ) == actionExplore )
{
filterCondition = lbr;
Filter = filterCondition; //Filter equals 1 entry per ticker/symbol
AddColumn( Close, "Close", format = 1.2 );
AddColumn( IIf( filterCondition, 'T', 'F' ), "FilterCondition", formatChar, IIf( filterCondition, colorGreen, colorOrange ) );
AddColumn( high1Y, NumToStr(currentY,1)+"-52WH" );
AddColumn( high1YDate, NumToStr(currentY,1)+"-52WH Date", formatdateTime );
AddColumn( low1Y,NumToStr(currentY,1)+"-52WL" ); //YYYY-52WL
AddColumn( low1YDate, NumToStr(currentY,1)+"-52WL Date", formatdateTime );
AddColumn( high2Y, NumToStr(lookBackY1,1)+"-52WH" );
AddColumn( high2YDate, NumToStr(lookBackY1,1)+"-52WH Date", formatdateTime );
AddColumn( low2Y, NumToStr(lookBackY1,1)+"-52WL" );
AddColumn( low2YDate, NumToStr(lookBackY1,1)+"-52WL Date", formatdateTime );
AddColumn( startDate, "startDate", formatdateTime );
AddColumn( endDate, "endDate", formatdateTime );
}
Cheers
Bobby