Announcement

Collapse
No announcement yet.

Standard Deviation

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

  • Standard Deviation

    Hi Guys, I have the following indicator I hacked together from different bits and pieces. It doesnt look pretty but it almost does what I want. It currently uses Standard Deviation from the previous N bars of intraday data. I would like it to find the Standard Deviation of the previous N DAILY Bars, regardless of what time frame I apply it to. Im not sure how to call the DAILY data though.... Any help with this would be much appreciated.

    Thank you

    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, sPriceSource) {
    if (nLength == null) nLength = 100;
    if (sPriceSource == null) sPriceSource = "Close";

    var aSource = getValue(sPriceSource, 0, -nLength);
    if (aSource == null) return null;

    var sumX = 0;
    var sumX2 = 0;
    for (i = 0; i < nLength; ++i) {
    sumX += aSource[i];
    sumX2 += (aSource[i] * aSource[i])
    }
    var meanX = (sumX/nLength);
    var stdev = Math.sqrt((sumX2/nLength) - (meanX*meanX));
    var study = new BollingerStudy(10, "Close", 2.0);
    var MAV = study.getValue(BollingerStudy.BASIS);
    var StdUpper1 = MAV + (stdev*1.5)
    var StdMiddle = MAV
    var StdLower1 = MAV - (stdev*1.5)
    var StdUpper2 = MAV + (stdev*2)
    var StdLower2= MAV - (stdev*2)

    return new Array(StdUpper2,StdUpper1, StdMiddle, StdLower1, StdLower2);
    }

  • #2
    According the EFS definitions and examples...

    //create a study that uses the Daily bar interval, regardless of the bar

    //interval of the chart in which the script is loaded

    myStudy = lowerBB( 10, 1.5, inv("D") );

    Comment

    Working...
    X