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);
}
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);
}
Comment