Amibroker AFL code snippet for creating Keltner Channel volatility indicator



Keltner Channel is a volatility based indicator which has middle line , upper band and lower band. The concept is similar to Bollinger Bands, but varies in the way its calculated. Bollinger Bands are calculated using Standard Deviations, whereas Keltner Channel bands are usually calculated using Average True Range (ATR).

There are couple of ways of calculating Keltner Channel Bands and following is the popular one:

Keltner Upper Band = Middle Line + ( Multiplier X ATR(Period) )

Keltner Lower Band = Middle Line - ( Multiplier X ATR(Period) )

Middle Line usually is 20 period Moving Average.

Multiplier is used to control the width of the bands. Default value is usually 2

Period is the number of bars used to calculate the ATR. Default value is 10

Note: Play around with different values for your personal preference.

Some traders use Keltner Channels as trend following tool and some use it for exact opposite purpose for fading strategies. You need to identify the market conditions before using this for trend following or fading strategies. One of my personal preference is the usage of Keltner band along with Bollinger Band to identify the squeeze. For that I use multiplier of 1.5 instead of 2 and Bollinger Band standard deviation would be default 2 only.

The original way or the other way of calculating Keltner Channel is based on average price i.e (High + Low + Close ) / 3 for measuring volatility instead of ATR.

Amibroker AFL Code to calculate the Keltner Bands

//Keltner Band Code
MidLine = MA (Close, 20);	//Middle Line
ATRPeriod = 10; 		//ATR Period
KFactor = 2;			//Multiplier
KVal = ATR(ATRPeriod) * KFactor; 
KTop = MidLine + KVal;	//Upper Band
KBottom = MidLine - KVal;	//Lower Ban

Please note that above piece of AFL code is for only informational purpose and you need to personally validate and test it before using it


Follow Us