Announcement

Collapse
No announcement yet.

Standard Deviation Bands...Anybody have anything like this?

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Standard Deviation Bands...Anybody have anything like this?

    I spent the weekend looking over 100 some odd pages of posts but no luck.

    This is what I'm hoping somebody has (because quite frankly I'm incapable of doing it myself currently).

    The MEAN is a MA of MA of MA...this EFS is exactly like the EFS file found from ( Alexis' file I think) called Dema-Tema.efs. One can choose an exponential moving average, simple, etc. of either the close, HL/2 or HLC/3....etc.

    The Bands are based on standard deviations of points similiar to the mean (ie. either close to close...or HL/2 or HLC/3..etc.) There is a constant factor that is user supplied to adjust the width of the bands such as 2.5 or 3.5 for 'standard deviations. I currently use this in TS: (Highest 3 day high + Lowest 3 day low)/2 as the points in calculating the standard deviation. This appears to provide a very robust band relative to market action.

    I've attached the dema-tema.efs file for those interested.

    Thanks for looking,
    James
    Attached Files

  • #2
    The following script uses a Donchian Channel to calculate the HH and LL over the past three periods. The script then calculate the Standard Deviation about the (HH+LL)/2 using a Price defined by the user. Refer to the comments for an understanding of the parameters.




    //Please make any change that will increase the speed of the script

    function preMain() {
    setStudyTitle("St Dev Env");
    setDefaultBarFgColor(Color.red, 0);
    setDefaultBarFgColor(Color.red, 1);
    setDefaultBarFgColor(Color.red, 2);
    setCursorLabelName("High Band", 0);
    setCursorLabelName("Mean", 0);
    setCursorLabelName("Low Band", 2);
    setPriceStudy(true);

    var fp1 = new FunctionParameter("DCHLength", FunctionParameter.NUMBER);
    fp1.setName("DC Length "); // Picks HH and LL over the last three periods
    fp1.setLowerLimit(1);
    fp1.setDefault(3);

    var fp2 = new FunctionParameter("Price", FunctionParameter.STRING);
    fp2.setName("Price Source"); //This is the price used to calculate the Standard Dev about the HH and LL
    fp2.addOption("Open");
    fp2.addOption("High");
    fp2.addOption("Low");
    fp2.addOption("Close");
    fp2.addOption("HL/2");
    fp2.addOption("HLC/3");
    fp2.addOption("OHLC/4");
    fp2.setDefault("HL/2");

    var fp3 = new FunctionParameter("NSDEV", FunctionParameter.NUMBER);
    fp3.setName("St DEV"); //Number of Standard Deviations
    fp3.setLowerLimit(.00001);
    fp3.setDefault(2);

    var fp4 = new FunctionParameter("Period", FunctionParameter.NUMBER);
    fp4.setName("Lookback"); //This is the lookback period to calculate the Standard Deviation
    fp4.setLowerLimit(1);
    fp4.setDefault(9);
    }



    function main(Price, DCHLength, Period, NSDEV) {
    var vValue1, vValueH, vValueL, vValueC, vValueO, vStdDev, avg, vUB, vLB, vDCHIGH, vDCLOW, vDCMean, SumSqr;

    vValue1 = new Array(Period);
    vValueH = new Array(Period);
    vValueL = new Array(Period);
    vValueO = new Array(Period);
    vValueC = new Array(Period);

    if (getBarState() == BARSTATE_ALLBARS) {
    myDCHstudy1 = new DonchianStudy(DCHLength, 0);
    }

    vDCHIGH = myDCHstudy1.getValue(DonchianStudy.UPPER);
    vDCLOW = myDCHstudy1.getValue(DonchianStudy.LOWER);

    if (vDCHIGH == null || vDCLOW == null) return;

    if ( Price == "Open" || Price == "Close" || Price == "High" || Price == "Low" ){
    vValue1 = getValue(Price, 0, -Period);
    if (vValue1 == null ) return;
    }

    if ( Price == "HL/2" ){
    vValueH = getValue("High", 0, -Period);
    vValueL = getValue("Low" , 0, -Period);
    if (vValueH == null || vValueL == null) return;
    for(j = 0; j < Period; j++)
    vValue1[j] = (vValueH[j] + vValueL[j])/2;
    }

    if ( Price == "HLC/3" ){
    vValueH = getValue("High", 0, -Period);
    vValueL = getValue("Low" , 0, -Period);
    vValueC = getValue("Close" , 0, -Period);
    if (vValueH == null || vValueL == null || vValueC == null) return;
    for(j = 0; j < Period; j++)
    vValue1[j] = (vValueH[j] + vValueL[j] + vValueC[j])/3;
    }

    if ( Price == "OHLC/4" ){
    vValueH = getValue("High", 0, -Period);
    vValueL = getValue("Low" , 0, -Period);
    vValueC = getValue("Close" , 0, -Period);
    vValueO = getValue("Open" , 0, -Period);
    if (vValueH == null || vValueL == null || vValueC == null || vValueO == null) return;
    for(j = 0; j < Period; j++)
    vValue1[j] = (vValueH[j] + vValueL[j] + vValueC[j] + vValueO[j])/4;
    }

    vDCMean = (vDCHIGH+vDCLOW)/2

    SumSqr = 0;
    for(i = 0; i < Period; i++){
    SumSqr+= (vValue1[i] - vDCMean) * (vValue1[i] - vDCMean);
    }

    vStdDev = Math.sqrt(SumSqr / Period);

    vUB = vDCMean + NSDEV * vStdDev;
    vLB = vDCMean - NSDEV * vStdDev;

    return new Array(vUB, vDCMean, vLB);
    }
    Attached Files

    Comment


    • #3
      Thanks Whatever,

      the resulting bands have inputs close to what i was looking for, but i thought i would go ahead and post a graph of what i was looking for... as you can see these are a bit 'quieter' than the Donchian bands...looks like i might have to finally learn some javascript

      Comment


      • #4
        Can you post the TS script?

        Someone might be able to convert it or I might be able to see what they are doing.

        Comment


        • #5
          Yep...here they are...they are relatively straight forward...hope somone can help

          StdevEnvelope Indicator:


          Inputs: Price(c),Length(20),Constant(2),Lookback(50);
          Variables: StopDeviations(0),HighEnvelope(0),LowEnvelope(0);

          HighEnvelope = (Price+Price*StdDevX(c,length)*Constant/squareroot(261));
          LowEnvelope = (Price-Price*StdDevX(c,length)*Constant/squareroot(261));

          if (HighEnvelope <> 0) then Plot1(highenvelope);
          if (LowEnvelope <> 0) then Plot2(Lowenvelope);


          StdDevX Function:

          Inputs: Price(NumericSeries), Length(NumericSimple);
          Variables: LogReturns(0);

          LogReturns = absvalue(Log(Price/Price[1]));

          If Length <> 0 Then Begin
          if StdDevX[1] = 0 then StdDevX = Logreturns[1] else
          StdDevX = StdDevX[1] + ((2/(length+1))*(LogReturns*squareroot(261) - StdDevX[1]));
          End;


          On the graph below the Price input into the above equation is the following - not a simple close only:

          xaverage(xaverage(xaverage((highest(h,3)+
          lowest(low,3))/2,3),3),3)

          Edit: I should note that the price to calculate the StdDev is based on close only...but the mean is the above triple exponential average...sorry if there is confusion
          Last edited by arvane; 05-05-2004, 12:35 PM.

          Comment


          • #6
            What is Lookback(50) used for?
            Last edited by whatever; 05-05-2004, 04:01 PM.

            Comment


            • #7
              ahhh..that variable was used in a previous version of this band, but is irrelevent in this version....you can disregard it...

              Comment


              • #8
                Sorry it is a little to complicated for me. I would repost. Put in the "Post subject;" a request for Alex or Jason to help. They could do this script for you in their sleep.

                Good luck.

                Comment


                • #9
                  James
                  The attached efs will replicate the TradeStation code.
                  The default value for the Constant is 2 as in the posted code although the value that was used to create the chart you posted was 3.
                  FYI by what I understand of the code the Length setting has little impact on the plot as it does not modify any lookback window.
                  Here below are the resulting plots from the ela and the efs (showing also the mean)
                  Alex



                  Attached Files

                  Comment


                  • #10
                    WoW Alexis what can I say?

                    That's perfect and I really appreciate the work you put into this. You are such an asset to this community.

                    Drinks are on me...

                    James

                    Comment


                    • #11
                      James
                      Thank you for the compliments.
                      Attached you can find a new version of the efs which includes a couple of changes
                      The first one is a null check to avoid the ramping up of the indicator that can be seen at the beginning of the plot.
                      The second change is a selector for the input used in the calculation of the bands. The default is set to Close with options for Open, High, Low and (High+Low)/2. I have also added an empty parameter so that one can write their own equation using the OHLC values. The syntax needs to be the same as shown in the other available options ie current values/prior values. Also if someone were to inadvertently input this optional parameter while leaving it empty a null check in the efs will switch the input back to Close.
                      Alex
                      Attached Files

                      Comment


                      • #12
                        Alexis,

                        Thanks again. Now if you could only program it to refuse bad trades

                        Do you know if it is possible to return the Highest High over the last X days and the Lowest Low of the last X days in calculating the basis?

                        -james

                        Comment


                        • #13
                          James
                          Unless I am misunderstanding your question the basis line is already being computed on the triple exponential average of the highest High and lowest Low of 3 days.
                          Alex

                          Comment


                          • #14
                            Ahhhh....Light bulb goes off...

                            That would be the reason for this line:

                            if(vDonch==null) vDonch = new DonchianStudy(3, 0);

                            Thanks again Alexis

                            Comment


                            • #15
                              James
                              That is correct. If you wanted you could add a Function Parameter to pass a value to that study so that you can control the lookback window for the Basis line.
                              By the way the Basis line can be easily created using the study on study feature of the Formula Wizard
                              Alex

                              Comment

                              Working...
                              X