Announcement

Collapse
No announcement yet.

BB and Keltner Channel

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • BB and Keltner Channel

    I am combining Keltner channels with BB. If I add the condition at the end to play a sound each time the BB is inside the Keltner Channel it does not work. I am missing something and I do not know what. I am relatively new at this. I am just good at combing/editing 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(13);
    }
    fpArray[x] = new FunctionParameter("ATRMult", FunctionParameter.NUMBER);
    with(fpArray[x++]) {
    setLowerLimit(1);
    setDefault(1.3);
    }
    }

    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.1;
    }
    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;
    }
Working...
X