In his 2009 book, "Intermarket Trading Strategies", @markos, Markos Katsanos introduces a trend indicator that he calls the Congestion Index. Although most of the book details inter-market strategies (no surprise if you read the title) I thought it would be worth a shot at coding his indicator into afl.
I used a picture of a spreadsheet in the book to derive the indicator so my variables are referring to columns in the spreadsheet. Of course there is room for improvement but I thought the group of forward thinkers here on the forum might experiment with the idea and share their findings with us.
At some point I will post another quant blog trend indicator for comparison.
_SECTION_BEGIN( "Congestion Index" );
// From book, "Intermarket Trading Strategies" by Markos Katsanos
// The Congestion Index
// although he writes "last 28 days"
// my output matches his Table 9.8 if I use 27 days
periods = Param( "LB periods", 27, 5, 100, 1 );
colE = HHV( High, periods );
colF = LLV( Low, periods );
//colG = (Close - Ref(Close, -periods))/Ref(Close, -periods) *100;
colG = ROC( C, periods );
colH = ( colE - colF ) / ( colF + 0.0001 );
colI = colG / colH ;
colJ = EMA( colI, 3 ); // in book he recommends a 3 day ema smoothing
// Charting //
dynamic_color = IIf( colJ > 20, colorGreen, IIf( colJ < -20, colorRed, colorWhite ) );
Plot( colJ, "Congestion Index(" + periods + ")", dynamic_color, styleHistogram, Null, Null, 0, 1, 4 );
Plot( colJ, "", dynamic_color, styleLine, Null, Null, 0, 1, 2 );
PlotGrid( 20, colorGreen, 8, 2 );
PlotGrid( -20, colorRed, 8, 2 );
// I assume that if we use a longer time frame (i.e. more than 27 bars) that
// the levels of "significance" for up/down trend may differ from +20 and -20
_SECTION_END
Now a cherry-picked example of how it is better than the ADX.