I am trying to place a condition that will fire each time BB is within the Keltner Channel. I am combining a script for Keltner Channel (which is working) with the conditions, however, the script with the conditions does not work. What am I missing? I am not good at writing scripts, but I am quite good at modifying existing scripts. Thank you kindly.
var fpArray = new Array();
var bInit = false;
function preMain(){
setPriceStudy(true);
setShowCursorLabel(true);
setShowTitleParameters(false);
setStudyTitle("Keltner ATR Band & BB");
setCursorLabelName("Up Band", 0);
setPlotType(PLOTTYPE_LINE, 0);
setDefaultBarFgColor(Color.red, 0);
setCursorLabelName("Dn Band", 1);
setPlotType(PLOTTYPE_LINE, 1);
setColorPriceBars(true);
setDefaultBarFgColor(Color.red, 1);
var x = 0;
fpArray[x] = new FunctionParameter("Length", FunctionParameter.NUMBER);
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(20);
}
fpArray[x] = new FunctionParameter("ATRMult", FunctionParameter.NUMBER);
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(2);
}
}
var xKUp = null;
var xKDn = null;
function main(Length, ATRMult) {
var nBarState = getBarState();
var nKU = 0;
var nKL = 0;
if (nBarState == BARSTATE_ALLBARS) {
if(Length == null) Length = 20;
if(ATRMult == null) ATRMult = 2;
}
if (bInit == false) {
xKUp = efsInternal("Calc_KeltnerBand", Length, ATRMult);
xKDn = getSeries(xKUp, 1);
bInit = true;
}
nKU = xKUp.getValue(0);
nKL = xKDn.getValue(0);
if (nKU == null || nKL == null) return;
return new Array(nKU, nKL);
}
var bSecondInit = false;
var xMA = null;
var xATR = null;
function Calc_KeltnerBand(Length, ATRMult) {
var nResUp = 0;
var nResDn = 0;
var nMA = 0;
var nATR = 0;
if (bSecondInit == false) {
xMA = sma(Length);
xATR = atr(Length);
bSecondInit = true;
}
nMA = xMA.getValue(0);
nATR = xATR.getValue(0);
if (nMA == null || nATR == null) return;
nResUp = nMA + ATRMult * nATR;
nResDn = nMA - ATRMult * nATR;
return new Array(nResUp, nResDn);
}
function calculate() {
var nResDn;
var nResUp;
If ((nResUp < upperBB(20,2)) && (nResDn > lowerBB(20,2))); {
drawShape(Shape.DIAMOND, AboveBar1, Color.blue);
Alert.playSound("buzz.wav");
}
return;
}
var fpArray = new Array();
var bInit = false;
function preMain(){
setPriceStudy(true);
setShowCursorLabel(true);
setShowTitleParameters(false);
setStudyTitle("Keltner ATR Band & BB");
setCursorLabelName("Up Band", 0);
setPlotType(PLOTTYPE_LINE, 0);
setDefaultBarFgColor(Color.red, 0);
setCursorLabelName("Dn Band", 1);
setPlotType(PLOTTYPE_LINE, 1);
setColorPriceBars(true);
setDefaultBarFgColor(Color.red, 1);
var x = 0;
fpArray[x] = new FunctionParameter("Length", FunctionParameter.NUMBER);
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(20);
}
fpArray[x] = new FunctionParameter("ATRMult", FunctionParameter.NUMBER);
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(2);
}
}
var xKUp = null;
var xKDn = null;
function main(Length, ATRMult) {
var nBarState = getBarState();
var nKU = 0;
var nKL = 0;
if (nBarState == BARSTATE_ALLBARS) {
if(Length == null) Length = 20;
if(ATRMult == null) ATRMult = 2;
}
if (bInit == false) {
xKUp = efsInternal("Calc_KeltnerBand", Length, ATRMult);
xKDn = getSeries(xKUp, 1);
bInit = true;
}
nKU = xKUp.getValue(0);
nKL = xKDn.getValue(0);
if (nKU == null || nKL == null) return;
return new Array(nKU, nKL);
}
var bSecondInit = false;
var xMA = null;
var xATR = null;
function Calc_KeltnerBand(Length, ATRMult) {
var nResUp = 0;
var nResDn = 0;
var nMA = 0;
var nATR = 0;
if (bSecondInit == false) {
xMA = sma(Length);
xATR = atr(Length);
bSecondInit = true;
}
nMA = xMA.getValue(0);
nATR = xATR.getValue(0);
if (nMA == null || nATR == null) return;
nResUp = nMA + ATRMult * nATR;
nResDn = nMA - ATRMult * nATR;
return new Array(nResUp, nResDn);
}
function calculate() {
var nResDn;
var nResUp;
If ((nResUp < upperBB(20,2)) && (nResDn > lowerBB(20,2))); {
drawShape(Shape.DIAMOND, AboveBar1, Color.blue);
Alert.playSound("buzz.wav");
}
return;
}
Comment