Hi Guys, back again with another Standard Deviation Dillemma....
The Following Code's Syntax seems to check out ok, but when I apply it to a chart, I get nothing. No errors, just no indicators....
Anyidea where I went wrong?
The Following Code's Syntax seems to check out ok, but when I apply it to a chart, I get nothing. No errors, just no indicators....
Anyidea where I went wrong?
PHP Code:
function preMain() {
setPriceStudy(true);
setStudyTitle("Standard Deviation ");
setCursorLabelName("UpperStdDev2", 0);
setCursorLabelName("UpperStdDev1", 1);
setCursorLabelName("MovAv", 2);
setCursorLabelName("LowerStdDev1", 3);
setCursorLabelName("LowerStdDev2", 4);
setDefaultBarFgColor(Color.green, 0);
setDefaultBarFgColor(Color.blue, 1);
setDefaultBarFgColor(Color.red, 2);
setDefaultBarFgColor(Color.blue, 3);
setDefaultBarFgColor(Color.green, 4);
setPlotType(PLOTTYPE_LINE,0);
setPlotType(PLOTTYPE_LINE,1);
setPlotType(PLOTTYPE_LINE,2);
setPlotType(PLOTTYPE_LINE,3);
setPlotType(PLOTTYPE_LINE,4);
setDefaultBarThickness(1,0);
setDefaultBarThickness(1,1);
setDefaultBarThickness(1,2);
setDefaultBarThickness(1,3);
setDefaultBarThickness(1,4);
}
function main(nLength, sLength,sPriceSource) {
var vRange ="close";
if (nLength == null) nLength = 1000;
if (sLength == null) sLength = 100;
if (sPriceSource == null) sPriceSource = vRange;
var aSource = getValue(sPriceSource, 0, -nLength);
if (aSource == null) return null;
var bSource = getValue(sPriceSource, 0, -sLength);
if (bSource == null) return null;
var sumX = 0;
var sumX2 = 0;
var sumY = 0;
var sumY2 = 0;
for (i = 0; i < nLength; ++i) {
sumX += aSource[i];
sumX2 += (aSource[i] * aSource[i])
}
for (j = 0; j < nLength; ++j) {
sumY += bSource[j];
sumY2 += (bSource[j] * bSource[j])
}
var meanX = (sumX/nLength);
var stdev = Math.sqrt((sumX2/nLength) - (meanX*meanX));
var meanY = (sumY/sLength);
var stdevY = Math.sqrt((sumY2/sLength) - (meanY*meanY));
var MAV = sma(20)
var UpperStdDev1 = MAV + (((stdev*0.8)+(stdevY*0.2))*0.8);
var MovAv = MAV
var LowerStdDev1 = MAV - (((stdev*0.8)+(stdevY*0.2))*0.8);
var UpperStdDev2 = MAV + (((stdev*0.8)+(stdevY*0.2))*1.2);
var LowerStdDev2= MAV - (((stdev*0.8)+(stdevY*0.2))*1.2);
return new Array(UpperStdDev2,UpperStdDev1, MovAv, LowerStdDev1, LowerStdDev2);
}
Comment