# Congestion Index by Katsanos

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.

10 Likes

There is a Chartered Market Technician course and in the text book for its third level, I found this description of the Congestion Index (freely available on the internet).

1 Like

I was not aware of it, but thanks to an online1 subscription I'm able to access it fully (actually (the vast majority of Wiley books on trading/investing are included!).

I see that in Appendix A there is a lot of MS code.

I wonder if @markos ever translated it and published a version for AmiBroker and/or if he will allow us to post here any other interesting formulas from this book.

By the way, the translation of the CI from that code sample in the Appendix should be as follow:

``````
// D1:=Input(â€śDAYS IN CONGESTIONâ€ť,1,500,15);
// CI:=ROC(C,D1-1,%)/((HHV(H,D1)-LLV(L,D1))/(LLV(L,D1)+.01)+.000001);
// Mov(CI,3,E)

D1 = Param( "Days in Congestion", 15, 2, 500, 1 ); // I changed the minimum to 2 since ROC does not work with a zero range
CI = ROC( C, D1 - 1 ) / ( ( HHV( H, D1 ) - LLV( L, D1 ) ) / ( LLV( L, D1 ) + .01 ) + .000001 );
Plot( EMA( CI, 3 ), "Congestion Index", colorOrange );

``````

The result is a bit different since the original code when calling the ROC function subtracts 1 from the period: as far as I understand, but I I may be wrong, the MS and the AB one calculations for the percentage rate of change are the same, so I translated the ROC call verbatim.
Maybe the original author will shed some light on this variation.

1) No affiliation, No endorsment. I'm just a normal subscriber.

7 Likes

@beppe thanks for the reminder, it had been a few years and I forgot there was an extensive Index in the back of the book with codes for many of his systems. He does run a commercial web page so I can't list it here but will PM you.

I feel that the indicator is interesting as basically the numerator measures the % change in price, while the denominator measures the % volatility of price. A point that I once read about comparing it to the Kaufman Efficiency Ratio, this formula ignores the details of what has occurred between the first and last price in the window. Was it a clean, steady trend or did price jump all over the place? So it may not be the perfect trend indicator, but it seems fairly interesting.

BTW the most recent edition of Technical Analysis of Stock and Commodities has yet another Katsanos original indicator, "the Stiffness Indicator". Now between the Congestion and Stiffness, I think we can come up with a joke but this is a family friendly forum so I'll let that slide.

6 Likes

Thank you all for your interest in my CI indicator. According to my original formula the ROC time span should be D1-1 and therefore the afl formula provided by @beppe is right. One day of course wonâ€™t make a lot of difference but the choice of the appropriate period will.

The 15 day indicator period (D1) is not written in stone but can vary according to a traderâ€™s time horizon and market volatility. Personally I use 15 days for fast trading and volatile markets and up to 40 days for slower markets.

Concerning the comparison between the CI and Kaufmanâ€™s efficiency ratio I would like to add the following remarks:

These indicators are not directly comparable as none of the above are true trend indicators . My CI indicator is a momentum and trend hybrid while the efficiency ratio, as the name suggests, measures the efficiency of markets in reaching the current price (zig zag or straight up). In a discussion about this with Mr. Kaufman he said that he only uses the ER as a variable for the exponential smoothing factor.

In any case my indicator, as I have pointed in Chapter 9 of my book, is much better in identifying a sudden or V shaped trend reversal from uptrend to downtrend or vice versa. In these cases the other trend indicators will show a loss of trend and would be quite late in identifying the new trend.

My web site mkatsanos.com already includes the afl code for a number of systems and my new article in the November 2018 issue of TASC includes the afl code for the Stiffness indicator and an Amibroker exploration.

Markos Katsanos

9 Likes

Just to let you know that I have translated all my intermarket formulas and strategies in my book " Intermarket Trading strategies" in Amibroker afl . You can find more details in my web site
Markos Katsanos

3 Likes

Dear Mr. Katsanos (@markos),

Earlier this year, I had studied your Congestion Index, thought of discussing about the variations with you. But somehow, new things and ideas kept me engrossed and the time never came.

Glad to be reminded by this post of yours!

The below is a modified version of the code generously shared by Larry (@portfoliobuilder ).

``````//Original code by Larry (portfoliobuilder)
_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", 24, 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
*/

//A method of smoothing using Linear Regression by Cougar
len = Param( "Length", 12, 1, 1440, 1 );
arr = ( HHV( colI, len ) + LLV( colI, len ) ) / 2 + Median( colI, len );
Osc = LinearReg( colI - arr / 2, len );
Plot( Osc, "Congestion Index Osc", colorAqua );

PlotGrid( 50, colorBlueGrey, 8 );
PlotGrid( 0, colorBlueGrey, 9 );
PlotGrid( -50, colorBlueGrey, 8 );

_SECTION_END();
``````

Thank you very much.

3 Likes

The default parameters (length, smoothing and congestion limits ) are not written in stone but will depend on the stock's volatility and market conditions. The best parameters can only be determined by testing.
After using the CI indicator for some of my systems I found that the best parameters to use are:
Length: 25-50 days
smoothing: 3-5 days
Upper and Lower limits : 25-30
Here is my original code:

``````D1 = Param( "Days in Congestion", 28, 2, 500, 1 );  /
UC=Param( "CONGESTION LIMIT", 25, 5, 60, 1 );
SMOOTH=Param( "SMOOTH EMA", 5, 1, 10, 1 );
CI = ROC( C, D1 - 1 ) / ( ( HHV( H, D1 ) - LLV( L, D1 ) ) / ( LLV( L, D1 ) + .01 ) + .000001 );
Plot( EMA( CI, SMOOTH), "Congestion Index", colorOrange );
PlotGrid( UC, colorGreen, 8, 2 );PlotGrid( 0, colorBlueGrey, 9 );
PlotGrid( -UC, colorRed, 8, 2 );

``````
5 Likes

Thank you for the insights!

Congestion Index is very good... I have long struggled to reduce the effect of whipsaw on my open positions... Your CI helps!

1 Like

Thank you very much for your code!
This is the best for me.
Best Regards!