ICE Data Services -

Description:
Keltner study with a 20 period exponential moving average of the basis line and bands based on 2.5 * Average True Range.

Formula Parameters:

• nInputLength: Default is 20 (number of periods for basis line)
• nRangeFactor: Default is 2.5 (multiplier for the bands)

Notes:
NA

EFS Code:

```/*****************************************************************
Provided By : eSignal. (c) Copyright 2003
*****************************************************************/

function preMain() {
setPriceStudy(true);

setStudyTitle("Keltner (ATR Bands) ");

setCursorLabelName("K-Upper", 0);
setCursorLabelName("K-Basis", 1);
setCursorLabelName("K-Lower", 2);

setDefaultBarFgColor(Color.blue, 0); // upper
setDefaultBarFgColor(Color.red, 1); // basis
setDefaultBarFgColor(Color.blue, 2); // lower
}

function ATR(nInputLength) {
var dSum = 0;
var dH = high(0, -nInputLength);
var dL = low(0, -nInputLength);
var dC = close(-1, -nInputLength);
if (dH == null || dL == null || dC == null) {
return;
}
for (i = 0; i < nInputLength; ++i) {
var vTrueHigh = Math.max(dH[i], dC[i]);
var vTrueLow = Math.min(dL[i], dC[i]);
var vTrueRange = (vTrueHigh - vTrueLow);
dSum += vTrueRange;
}
dSum /= nInputLength;
return dSum;
}

var BarCntr = 0;
function main(nInputLength, nRangeFactor) {
if(nInputLength == null)
nInputLength = 20;
if(nInputLength <= 0)
nInputLength = 20;

if(nRangeFactor == null)
nRangeFactor = 2.5;
if(nRangeFactor <= 0)
nRangeFactor = 2.5;

if (getBarState() == BARSTATE_NEWBAR)
BarCntr += 1;

if (BarCntr < nInputLength) {
return;
} else {
var dKeltnerBasis= call("/Library/KeltnerEMA.efs", nInputLength);
var dATR = ATR(nInputLength);
return new Array(dKeltnerBasis + (nRangeFactor * dATR), dKeltnerBasis, dKeltnerBasis - (nRangeFactor * dATR));
}
}
```