Announcement

Collapse
No announcement yet.

Adding Bollinger Bands to DiNapoli Stochastic

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

  • Adding Bollinger Bands to DiNapoli Stochastic

    I am having problems adding Bollinger Bands to the DiNaploi Stochastic. It should be a simple addition but is giving me problems. I added the var BBu and BBl and made each one the result of their respective Bollinger Studies. Can someone please advise me what I am doing wrong.

    Thanks, Steven

    /************************************************** **************************************************
    Copyright © eSignal, a division of Interactive Data Corporation. 2003. All rights reserved.
    This sample eSignal Formula Script (EFS) may be modified and saved under a new
    filename; however, eSignal is no longer responsible for the functionality once modified.
    eSignal reserves the right to modify and overwrite this EFS file with each new release.
    ************************************************** ************************************************** */
    /*** 5/9/03 Corrected Version
    * Fixed flat-line bug for infrequently traded securities
    ***/

    addBand(80, PS_SOLID, 1, Color.grey, "Upper");
    addBand(20, PS_SOLID, 1, Color.black, "Lower");

    function preMain()
    {
    setStudyTitle("Preferred Stochastic");
    setCursorLabelName("percentK", 0);
    setCursorLabelName("percentD", 1);
    setDefaultBarFgColor(Color.blue, 0);
    setDefaultBarFgColor(Color.red, 1);
    setDefaultBarFgColor(Color.grey, 2);
    setDefaultBarFgColor(Color.grey, 3);

    }

    var MAVt = null;
    var MAVt1 = null;
    var MAVt_1 = 0;
    var MAVt1_1 = 0;
    var BBu = 0;
    var BBl = 0;

    function main(nLength, nSmoothing, nSmoothings) {
    if(nLength == null)
    nLength = 8;
    if(nSmoothing == null)
    nSmoothing = 3;
    if(nSmoothings == null)
    nSmoothings = 3;

    var percentK;
    var ll = 0, hh = 0;
    var sum = 0;
    var vHigh = getValue("High", 0, -nLength);
    var vLow = getValue("Low", 0, -nLength);
    var temp = 0;

    if(vHigh == null || vLow == null)
    return;


    for(j = 0; j < nLength; j++) {
    if(j == 0) {
    ll = vLow[j];
    hh = vHigh[j];
    } else {
    hh = Math.max(hh, vHigh[j]);
    ll = Math.min(ll, vLow[j]);
    }
    }
    percentK = ((close() - ll) / (hh - ll)) * 100;
    if (isNaN(percentK) == false) MAVt = MAVt_1 + (percentK - MAVt_1) / nSmoothing;
    if (getBarState() == BARSTATE_NEWBAR) MAVt_1 = MAVt;
    if (isNaN(percentK) == false) MAVt1 = MAVt1_1 + (MAVt - MAVt1_1) / nSmoothings;
    if (getBarState() == BARSTATE_NEWBAR) MAVt1_1 = MAVt1;

    BBu = upperBB(20, 2, MAVt);
    BBl = lowerBB(20, 2, MAVt);

    return new Array(MAVt,MAVt1,BBu,BBl);
    }

  • #2
    Is their anybody who can assist me with this problem?

    Comment


    • #3
      Steven
      The script will not function correctly because MAVt which you are using as a source for the Bollinger functions is not a series object (which the Bollinger functions require) but a value.
      This is the same issue I explained to you in this thread and the solution is similar.
      The only difference is that instead of creating a separate function within the same script which you would call using efsInternal() in this case you simply create a new efs and in it use efsExternal() to call the DiNapoli Stochastic efs. efsExternal() will create the required series object that you can then pass to the Bollinger functions which you will add to this new efs.
      For examples on how to use efsExternal() see this and this thread
      Alex

      Comment

      Working...
      X