// empty-scan-broken.afl
// Part 12 - Challenge: The Scan That Returns Nothing
//
// This is the formula as its author wrote it. Do not fix it yet.
//
// The author's stated intent, in their own words:
//
//   "Liquid stocks that are above their 200-day average, that made a new
//    50-day high today on at least twice their normal volume, and that are
//    not already overbought. I get maybe twenty or thirty of these a week.
//    Yesterday it returned forty rows. Today it returns nothing at all and I
//    have not touched the code."
//
// The database is a broad equity universe of about 1,900 symbols with daily
// bars going back roughly fifteen years. Several hundred of the symbols were
// added to the database in the last few months and have short histories.

_SECTION_BEGIN( "Momentum screen" );

MinTurnover  = 20000000;
TrendPeriod  = 200;
BreakPeriod  = 50;
VolPeriod    = 50;
VolMultiple  = 2;
RsiCeiling   = 70;

AvgTurnover = MA( Close * Volume, 200 );
RelVolume   = Volume / MA( Volume, VolPeriod );

Liquid      = AvgTurnover > MinTurnover;
UpTrend     = Close > MA( Close, TrendPeriod );
NewHigh     = Close > HHV( High, BreakPeriod );
HeavyVolume = RelVolume > VolMultiple;
NotExtended = RSI( 14 ) < RsiCeiling;

Buy = Liquid AND UpTrend AND NewHigh AND HeavyVolume AND NotExtended;

Filter = Buy AND Status( "lastbarinrange" );

AddColumn( Close, "Close", 1.2 );
AddColumn( RelVolume, "Rel volume", 1.2 );
AddColumn( AvgTurnover, "Turnover", 1.0 );
AddColumn( RSI( 14 ), "RSI(14)", 1.0 );

_SECTION_END();
