Announcement

Collapse
No announcement yet.

StochRSI Histogram with color slope

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

  • StochRSI Histogram with color slope

    I am hoping you can help me with the following efs. I was able to convert the StochRSI to a histogram without trouble. However, adding the positive and negative color slope has not worked out as well . Here it is :
    addBand(90, PS_DASH, 2, Color.red, "Upper");
    addBand(10, PS_DASH, 2, Color.lime, "Lower");
    addBand(50, PS_DASH,2,Color.yellow,1);
    function preMain() {
    setStudyTitle("Stochastic of RSI ");
    setCursorLabelName("\%K of RSI", 0);
    setCursorLabelName("\%D of RSI", 1);
    setDefaultBarFgColor(Color.blue, 0);
    setDefaultBarFgColor(Color.red, 1);
    setDefaultBarThickness(3,0);
    setDefaultBarThickness(2,1);
    setStudyMax(105);

    setStudyMin(-5);
    setPlotType(PLOTTYPE_HISTOGRAM);



    var fp1 = new FunctionParameter("PriceSource", FunctionParameter.STRING);
    fp1.setName("RSI Price Source");
    fp1.addOption("Open");
    fp1.addOption("High");
    fp1.addOption("Low");
    fp1.addOption("Close");
    fp1.addOption("HL/2");
    fp1.addOption("HLC/3");
    fp1.addOption("OHLC/4");
    fp1.setDefault("HLC/3");

    var fp2 = new FunctionParameter("rsiLength", FunctionParameter.NUMBER);
    fp2.setName("RSI Length");
    fp2.setLowerLimit(1);
    fp2.setDefault(36);

    var fp3 = new FunctionParameter("Klength", FunctionParameter.NUMBER);
    fp3.setName("\%K Length");
    fp3.setLowerLimit(1);
    fp3.setDefault(18);

    var fp4 = new FunctionParameter("Ksmooth", FunctionParameter.NUMBER);
    fp4.setName("\%K Smoothing");
    fp4.setLowerLimit(1);
    fp4.setDefault(6);

    var fp5 = new FunctionParameter("Dlength", FunctionParameter.NUMBER);
    fp5.setName("\%D Length");
    fp5.setLowerLimit(1);
    fp5.setDefault(3);

    var fp6 = new FunctionParameter("SmoothKline", FunctionParameter.BOOLEAN);
    fp6.setName("Smooth \%K");
    fp6.setDefault(true);

    var fp7 = new FunctionParameter("cPos", FunctionParameter.COLOR);
    fp7.setName("Positive Slope");
    fp7.setDefault(Color.green);

    var fp8 = new FunctionParameter("cNeg", FunctionParameter.COLOR);
    fp8.setName("Negative Slope");
    fp8.setDefault(Color.red);

    }
    var vOsc = null;
    var vOsc_ret = 0;
    var vOsc_ret1 = null;






    function HHrsi(nLength) {
    var hh = null;
    hh = aRSI[0];
    for(i = 0; i < nLength; i++) {
    hh = Math.max(hh, aRSI[i]);
    }
    return hh;
    }

    function LLrsi(nLength) {
    var ll = null;
    ll = aRSI[0];;
    for(i = 0; i < nLength; i++) {
    ll = Math.min(ll, aRSI[i]);
    }
    return ll;
    }

    var vStochRSI = null;

    function StochK(inputrsiLength, nLength, nSmoothing) {
    var nState = getBarState();
    var percentK;
    var vValue;
    var ll, hh;
    var sum = 0;

    ll = LLrsi(inputrsiLength)
    hh = HHrsi(inputrsiLength);

    if (nState == BARSTATE_NEWBAR && vStochRSI != null) {
    aStoch.pop();
    aStoch.unshift(vStochRSI);
    }

    vStochRSI = ((vRSI - ll) / (hh - ll)) * 100; // no smoothing
    aStoch[0] = vStochRSI;

    if (vSmooth == "true") {
    for(i = 0; i < nSmoothing; i++) { // for smoothing
    sum += aStoch[i];
    }
    sum /= nSmoothing;
    return sum;
    } else {
    return vStochRSI;
    }
    }

    function StochD(nSmoothing) {
    var sum = 0;
    for(i = 0; i < nSmoothing; i++) {
    sum += aStochb[i];
    }
    sum = sum / nSmoothing;
    return sum;
    }

    var RSIstudy = null;
    var aRSI = null;
    var vRSI = null;
    var aStoch = null;
    var aStochb = null;
    var vSmooth = "false";
    var bEdit = true;
    var vK = null;
    var vD = null;

    function main(PriceSource, rsiLength, Klength, Ksmooth, Dlength, SmoothKline) {
    var nState = getBarState();

    if (bEdit == true || RSIstudy == null || aRSI == null || aStoch == null) {
    RSIstudy = new RSIStudy(rsiLength, PriceSource);
    aStoch = new Array(Math.max(Ksmooth, Klength));
    aStochb = new Array(Dlength);
    aRSI = new Array(Math.max(Klength, Ksmooth));
    if (SmoothKline != null) vSmooth = SmoothKline;
    bEdit = false;
    }

    if (nState == BARSTATE_NEWBAR && vRSI != null) {
    aRSI.pop();
    aRSI.unshift(vRSI);
    aStochb.pop();
    aStochb.unshift(vK);
    }


    if(vOsc_ret > vOsc_ret1) setBarFgColor(cPos);
    if(vOsc_ret< vOsc_ret1) setBarFgColor(cNeg);

    return vOsc_ret;
    }







    vRSI = RSIstudy.getValue(RSIStudy.RSI);
    if (vRSI == null) ;
    aRSI[0] = vRSI;







    vK = null;
    vD = null;

    var vLen = Math.max(Klength, Ksmooth);
    if (aRSI[vLen-1] != null) {
    vK = StochK(Klength, Klength, Ksmooth);
    aStochb[0] = vK;
    vD = StochD(Dlength);
    } else {

    }


    return new Array(vK, vD);
    }

    }
    Last edited by colours; 01-02-2005, 11:33 AM.

  • #2
    colours
    The attached revision of your efs will now color the %K histogram depending if it is rising or falling.
    All changes are marked in the efs.
    Alex

    Attached Files

    Comment


    • #3
      That is great . Thanks Alex.It is exactly what i needed.

      Comment


      • #4
        RSI Histogram Colors?

        Alex: Would it be possible to color the RSI Histogram with the bars being Red below 50, and Blue above 50 - such as you did with the CCI Histogram? The RSI Histogram is called basicrsi(hist) I believe. Thanks for the great work...

        Comment


        • #5
          jones24621
          Post the efs or a link to it
          Alex

          Comment


          • #6
            Here is the link...

            Alex - Here is the link. You created basicrsi(hist) on 3-20-2004:

            Comment


            • #7
              jones24621
              Open the efs with the Editor and add the lines enclosed below just before the return statement
              Alex

              PHP Code:
              if(vRSI.getValue(RSIStudy.RSI)<50)
                      
              setBarFgColor(Color.red); 

              Comment


              • #8
                Perfect - Thank you...

                Alex - works perfectly...thank you!!

                Comment


                • #9
                  jones24621
                  My pleasure
                  Alex

                  Comment

                  Working...
                  X