Announcement

Collapse
No announcement yet.

Bollinger Band width

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

  • #16
    customized BB width

    Alexis:

    I would really appreciate your help. I was reading your exchange with Bill and thought it would be great to be able to customize the BB width indicator with inputs on the BB parameters. I took my best shot at trying to do this using your Custom EFS 2 BB code plus the BB width code. Unfortunately, I cannot get it to plot anything for the BB width. Any thoughts?

    David

    var fpArray = new Array();

    function preMain() {

    setPriceStudy(false);
    setStudyTitle("Bollinger Band Width");
    setCursorLabelName("Bandwidth", 0)
    setDefaultBarFgColor(Color.blue, 0);
    askForInput();

    var x=0;
    fpArray[x] = new FunctionParameter("Length", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setLowerLimit(1);
    setDefault(20);
    }
    fpArray[x] = new FunctionParameter("StdDev", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setLowerLimit(0);
    setDefault(2);
    }
    fpArray[x] = new FunctionParameter("Source", FunctionParameter.STRING);
    with(fpArray[x++]){
    addOption("open");
    addOption("high");
    addOption("low");
    addOption("close");
    addOption("hl2");
    addOption("hlc3");
    addOption("ohlc4");
    setDefault("close");
    }
    fpArray[x] = new FunctionParameter("Symbol", FunctionParameter.STRING);
    with(fpArray[x++]){
    setDefault("");
    }
    fpArray[x] = new FunctionParameter("Interval", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setDefault("");
    }
    fpArray[x] = new FunctionParameter("Offset", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setDefault(0);
    }
    fpArray[x] = new FunctionParameter("Params", FunctionParameter.BOOLEAN);
    with(fpArray[x++]){
    setName("Show Parameters");
    setDefault(false);
    }
    }

    var bInit = false;
    var xUpBB = null;
    var xMidBB = null;
    var xLoBB = null;

    function main(Length,StdDev,Source,Symbol,Interval,Offset,P arams) {

    if(bInit == false){
    if(Symbol == null) Symbol = getSymbol();
    if(Interval == null) Interval = getInterval();
    var vSymbol = Symbol+","+Interval;
    xUpBB = offsetSeries(upperBB(Length,StdDev,eval(Source)(sy m(vSymbol))),Offset);
    xMidBB = offsetSeries(middleBB(Length,StdDev,eval(Source)(s ym(vSymbol))),Offset);
    xLoBB = offsetSeries(lowerBB(Length,StdDev,eval(Source)(sy m(vSymbol))),Offset);

    setShowTitleParameters(eval(Params));
    bInit = true;
    }

    return new Array ((xUpBB - xLoBB) / xMidBB * 100, 0.0));
    }

    Comment


    • #17
      David
      The first problem is a syntax error in your return statement (check the parenthesis).
      Then you need to return either a value or a series to be plotted. As of now the series for the studies are created once (inside your bInit statement) and their values are cached. So, in the return statement you need to add to each variable name either a .getValue(0) if you want to retrieve the single value or a getSeries() if you want to retrieve the series (which is how all the studies in the EFS2 Custom folder are set up)
      Alex

      PHP Code:
      //to return the values
      return new Array ((xUpBB.getValue(0) - xLoBB.getValue(0)) / xMidBB.getValue(0) * 1000.0);
      //or to return the series
      return new Array ((getSeries(xUpBB) - getSeries(xLoBB)) / getSeries(xMidBB) * 1000.0); 

      Comment


      • #18
        Alex,

        Thank you for your help. The edit worked (of course).

        David

        Comment


        • #19
          David
          You are welcome
          Alex


          Originally posted by dschram
          Alex,

          Thank you for your help. The edit worked (of course).

          David

          Comment

          Working...
          X