Hi Guys, Ive had a go at the following code, the idea is to chart the Daily Std Dev on an intraday chart, but Im not having much luck with the following code. Im pretty sure it has something to do with the following line, because whe nI remove the inv("D") section, it charts the intraday StdDev ok.
function preMain() {
setPriceStudy(true);
setStudyTitle("Standard Deviation 2");
setCursorLabelName("StdUpper2",0);
setCursorLabelName("StdUpper1", 1);
setCursorLabelName("StdMiddle", 2);
setCursorLabelName("StdLower1", 3);
setCursorLabelName("StdLower2", 4);
setDefaultBarFgColor(Color.blue, 0);
setDefaultBarFgColor(Color.red, 1);
setDefaultBarFgColor(Color.green, 2);
setDefaultBarFgColor(Color.red, 3);
setDefaultBarFgColor(Color.blue, 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);
}
var bInit = false;
var vSymbol = null;
function main() {
if(bInit==false){
bInit = true;
}
var aSource = getValue( "close", 0, -30,inv("D"));
if (aSource == null) return null;
var sumX = 0;
var sumX2 = 0;
for (i = 0; i < 30; ++i) {
sumX += aSource[i];
sumX2 += (aSource[i] * aSource[i]);
}
var meanX = (sumX/30);
var stdev = Math.sqrt((sumX2/30) - (meanX*meanX));
var MAV = sma(20);
var StdUpper1 = MAV + (stdev*0.5);
var StdMiddle = MAV;
var StdLower1 = MAV - (stdev*0.5);
var StdUpper2 = MAV + (stdev*1);
var StdLower2= MAV - (stdev*1);
return new Array(StdUpper2,StdUpper1, StdMiddle, StdLower1, StdLower2);
}
PHP Code:
var aSource = getValue( "close", 0, -30,inv("D"));
setPriceStudy(true);
setStudyTitle("Standard Deviation 2");
setCursorLabelName("StdUpper2",0);
setCursorLabelName("StdUpper1", 1);
setCursorLabelName("StdMiddle", 2);
setCursorLabelName("StdLower1", 3);
setCursorLabelName("StdLower2", 4);
setDefaultBarFgColor(Color.blue, 0);
setDefaultBarFgColor(Color.red, 1);
setDefaultBarFgColor(Color.green, 2);
setDefaultBarFgColor(Color.red, 3);
setDefaultBarFgColor(Color.blue, 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);
}
var bInit = false;
var vSymbol = null;
function main() {
if(bInit==false){
bInit = true;
}
var aSource = getValue( "close", 0, -30,inv("D"));
if (aSource == null) return null;
var sumX = 0;
var sumX2 = 0;
for (i = 0; i < 30; ++i) {
sumX += aSource[i];
sumX2 += (aSource[i] * aSource[i]);
}
var meanX = (sumX/30);
var stdev = Math.sqrt((sumX2/30) - (meanX*meanX));
var MAV = sma(20);
var StdUpper1 = MAV + (stdev*0.5);
var StdMiddle = MAV;
var StdLower1 = MAV - (stdev*0.5);
var StdUpper2 = MAV + (stdev*1);
var StdLower2= MAV - (stdev*1);
return new Array(StdUpper2,StdUpper1, StdMiddle, StdLower1, StdLower2);
}
Comment