Announcement

Collapse
No announcement yet.

MA of StochasticRSI

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

  • MA of StochasticRSI

    I am trying to create an MA of a StochasticRSI. The Formula Wizard does not contain the Stochastic RSI as a function. Any help would be appreciated.
    Last edited by linsar; 10-12-2003, 06:38 PM.

  • #2
    Dear Linsar,

    Please see the code below and let me know if you have any quetions or problems, I'll help you at once.

    Regards,
    Andy


    Code:
    /******************************************
    Provided By	: TS Support, LLC for eSignal  
    *****************************************/
    
    //////////////////////////////////// Inputs ///////////////////////////////////
    // nInputLength - number of bars to use in the StochRSI calculation          //
    // AverageLength - number of bars to use in the StochRSI average calculation //
    ///////////////////////////////////////////////////////////////////////////////
    
    function preMain() {
        setStudyTitle("StochasticRSI");
        setCursorLabelName("S-RSI",0);
        setCursorLabelName("Average",1);
        setDefaultBarFgColor(Color.blue, 0);
        setDefaultBarFgColor(Color.red, 1);
        setStudyMin(0);
        setStudyMax(100);
      
        addBand(20, PS_SOLID, 1, Color.black);
        addBand(80, PS_SOLID, 1, Color.black);
           
    }
    
    var aryRSI        = null;
    var nRsiCount     = 0;
    vStochRSI = new Array();
    
    function main(nInputLength,AverageLength) {
        if(nInputLength == null)
            nInputLength = 14;
            
        if(AverageLength == null)
            AverageLength = 3;    
        
        var Sum = 0;
        var nBarState = getBarState();
        if(nBarState == BARSTATE_ALLBARS) {
            aryRSI = null;
            nRsiCount = 0;
        }
    
        if(aryRSI == null) {
            aryRSI = new Array(nInputLength);
            nRsiCount = 0;
        }
        
        var vRSI = call("/Library/RSIEnhanced.efs", nInputLength);
        if(vRSI == null)
            return;
        
    
        if(nRsiCount < nInputLength) { // prime the array
            aryRSI[nRsiCount] = vRSI;
            nRsiCount++;
            return;
        } 
        
        
        if(nBarState == BARSTATE_NEWBAR) {
            aryRSI.shift();
            aryRSI.push(vRSI);
        } else if(nBarState == BARSTATE_CURRENTBAR) {
            aryRSI[nInputLength-1] = vRSI;
        }    
        var vRSIHH = aryRSI[0];
        var vRSILL = aryRSI[0];
        var i;
        
        for(i = 1; i < nInputLength; i++) {
            vRSIHH = Math.max(vRSIHH, aryRSI[i]);
            vRSILL = Math.min(vRSILL, aryRSI[i]);
        }
        
        var StochRSI = ((vRSI - vRSILL) / (vRSIHH - vRSILL)) * 100;
        
        for(i = AverageLength - 1; i > 0; i--)
    	 vStochRSI[i] = vStochRSI[i - 1];
         vStochRSI[0] = StochRSI;
    	
    	for(i = 0; i < AverageLength; i++)
    		Sum += vStochRSI[i];
    		
        return new Array(StochRSI,Sum / AverageLength);
    }

    Comment


    • #3
      Andy:

      Thank you for your help. Its appreciated. I am not able to download the code you created since it does not have a link (which I use to transfer to Downloads?). I need a little more assistance. Thanks again.

      Comment


      • #4
        Andy:

        Thank you for your help. Its appreciated. I am not able to download the code you created since it does not have a link (which I use to transfer to Downloads?). I need a little more assistance. Thanks again.

        Comment


        • #5
          linsar
          Attached is the efs containing Andy's code
          Alex
          Attached Files

          Comment


          • #6
            Alex
            Thank you. It works fine.

            Comment

            Working...
            X