Announcement

Collapse
No announcement yet.

CCI Smoothed using Rafters Least Square

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

  • CCI Smoothed using Rafters Least Square

    I have managed to create efs files of ADX and RSI which are smoothed using Rafter's Least Square Method, but am unable to figure out how to do it with the CCI function since I can't access prior bar data easily. I assume I would have to build an array of CCI data and then continually update it for each bar, shifting the prior information back as a new bar of data is inserted, but I have been unable to do this effectively. The CCI period is not important as I can change that anytime....I am merely interested in how to build this kind of efs from a builtin function which doesn't give prior bar data like RSI.

    Here is what I've got for the Rafter Smoothed RSI.

    // Smoothing RSI using Rafter's Least Square Method
    // First input is length of the Least Square, the second input is the smoothing factor

    var study = new RSIStudy(17, "HLC/3");
    function preMain()
    {
    setPriceStudy(false);
    setStudyTitle("T_RSI(17)");
    setCursorLabelName("T_RSI");

    setDefaultBarFgColor(Color.RGB(111,200,100),0);
    setDefaultBarThickness(2,0)
    addBand(10, PS_DOT, 2, Color.RGB(111,200,100));
    addBand(90, PS_DOT, 2, Color.RGB(111,200,100));
    addBand(50, PS_DASH, 3, Color.black)
    }



    function main(nInputLength,nInputBarPlus)
    {
    var len = 1;
    var BarPlus = 1;
    if (nInputLength != null) len = nInputLength;
    if (nInputBarPlus != null) BarPlus = nInputBarPlus;

    var i = 0;
    var vPrice;
    var joy = new Array(len);

    //---Generate RSI Values
    for(i = 0; i < len; i++) {
    if (i==0)
    vPrice = study.getValue(RSIStudy.RSI, i);
    else vPrice = study.getValue(RSIStudy.RSI,-i);
    joy[i] = vPrice;
    }

    //---Smooth using Rafters Technique
    var Num1 = 0.0;
    var Num2 = 0.0;
    var SumBars = len * (len - 1) * 0.5;
    var SumSqrBars = (len - 1) * len * (2 * len - 1) / 6;
    var SumY = 0.0;
    var Sum1 = 0.0;
    var Sum2 = 0.0;
    var Slope = 0.0;
    var Intercept = 0.0;


    var i = 0;
    for (i = 0; i < len; i++)
    {
    SumY += joy[i];
    Sum1 += i * joy[i];
    }

    Sum2 = SumBars * SumY;
    Num1 = len * Sum1 - Sum2;
    Num2 = SumBars * SumBars - len * SumSqrBars;

    if (Num2 != 0) Slope = Num1 / Num2;
    Intercept = (SumY - Slope * SumBars) / len;
    var Sm_RSI = Intercept + Slope * (len - 1 - BarPlus);

    return (Sm_RSI);
    }

  • #2
    whizz

    Couldn't you substitute

    var study = new CCIStudy(20, "Close");

    then calculate

    vPrice = study.getValue(CCIStudy.CCI) and
    vPrice = study.getValue(CCIStudy.CCI, -1)

    in the FOR loop

    Comment


    • #3
      dloomis,

      Thank you, that worked.
      I didn't realize that one could index into the CCI function just like for the RSI. Thanks again.

      Cheers.

      Comment


      • #4
        whizz,

        could you post that efs, thx

        Comment


        • #5
          Attached is a revision of whizz' efs rearranged with EFS2 syntax that can now be used with multiple intervals or symbols.
          The new script makes use of the EFS2 builtin rsi() study which is then passed as a series to the Rafter Smoothing function via efsInternal(). Because the rsi series also includes the symbol/interval series efsInternal() now controls the context in which the Rafter Smoothing function will be executed even if the latter does not contain any EFS2 specific code.
          As an aside this efs also illustrates how easy it will be in many cases to convert existing EFS1 scripts to full EFS2 functionality.
          In the top chart in the following image you can see the new version of the study running on a 1 minute chart and computing the indicator on 5 minute data, while the bottom chart shows both the new version and the original study on a 5 minute chart for comparison purpose.
          To change the study to use the CCI study replace the rsi with cci in the efsInternal() call.
          Alex

          Attached Files

          Comment


          • #6
            efs

            Alex...i tried to download this to test on my charts and received an error about efs ..do i need something diff or wait till efs2 out?

            woodie

            Comment


            • #7
              woodie
              You need version 7.9 beta 1 or later to run the efs as it is using the new EFS2 engine
              Alex

              Comment


              • #8
                Dloomis,

                Sorry about the late reply.
                Do you still want me to post the CCI version or is did the RSI version (which is much fancier) do the trick for you?

                Comment

                Working...
                X