2015 July (Apr): The Slow Relative Strength Index by Vitali Apirine

ICE Data Services -

SRSI.efs  

EFS Library - Discussion Board  

File Name: SRSI.efs

Description:
The Slow Relative Strength Index by Vitali Apirine

Formula Parameters:

SRSI.efs

  • Length EMA: 6
  • Length Average Differences: 14
  • Upper Bound: 80
  • Lower Bound: 20

Notes:
The related article is copyrighted material. If you are not a subscriber of Stocks & Commodities, please visit www.traders.com.

Download File:
SRSI.efs

SRSI.efs

EFS Code:
SRSI.efs

/*********************************
Provided By:  
    Interactive Data Corporation (Copyright В© 2015) 
    All rights reserved. This sample eSignal Formula Script (EFS)
    is for educational purposes only. Interactive Data Corporation
    reserves the right to modify and overwrite this EFS file with 
    each new release. 

Description:        
    The Slow Relative Strength Index by Vitali Apirine

Formula Parameters:                     Default:
Length EMA                              6
Length Average Differences              14 
Upper Bound                             80
Lower Bound                             20

Version:            1.00  05/05/2015

Notes:
    The related article is copyrighted material. If you are not a subscriber
    of Stocks & Commodities, please visit www.traders.com.

**********************************/

var fpArray = new Array(); 

function preMain(){

    setStudyTitle("SRSI");
    
    setCursorLabelName("Upper Bound", 0);
    setCursorLabelName("Lower Bound", 1);
    setCursorLabelName("Center Line", 2);
    setCursorLabelName("SRSI", 3);
    
    setDefaultBarFgColor(Color.grey, 0);
    setDefaultBarFgColor(Color.grey, 1);
    setDefaultBarFgColor(Color.grey, 2);
        
    setShowCursorLabel(false, 0);
    setShowCursorLabel(false, 1);
    setShowCursorLabel(false, 2);
    setShowCursorLabel(true, 3);
    
    setDefaultBarStyle(PS_SOLID, 0);
    setDefaultBarStyle(PS_SOLID, 1);
    setDefaultBarStyle(PS_DASHDOT, 2);
    setDefaultBarStyle(PS_SOLID, 3);

    var x = 0;

    fpArray[x] = new FunctionParameter("fpLengthEMA", FunctionParameter.NUMBER);
    with(fpArray[x++]){
        setName("Length EMA");
        setLowerLimit(1); 
        setDefault(6);
    };

    fpArray[x] = new FunctionParameter("fpLengthAvgDiff", FunctionParameter.NUMBER);
    with(fpArray[x++]){
        setName("Length Average Differences");
        setLowerLimit(1);
        setDefault(14);
    };

    fpArray[x] = new FunctionParameter("fpSRSIHighBorder", FunctionParameter.NUMBER);
    with(fpArray[x++]){
        setName("Upper Bound");    
        setLowerLimit(0);
        setUpperLimit(100); 
        setDefault(80);
    };
    
    fpArray[x] = new FunctionParameter("fpSRSILowBorder", FunctionParameter.NUMBER);
    with(fpArray[x++]){
        setName("Lower Bound");    
        setLowerLimit(0);
        setUpperLimit(100); 
        setDefault(20);
    };
}

var bInit = false;
var bVersion = null;

var xDifferences = null;
var xPositiveDiff = null;
var xNegativeDiff = null;
var xPositiveDiffAvg = null;
var xNegativeDiffAvg = null;

function main(fpLengthEMA, fpLengthAvgDiff, fpSRSIHighBorder, fpSRSILowBorder){

    if (bVersion == null) bVersion = verify();
    if (bVersion == false) return;

    if (!bInit){

        xDifferences = efsInternal('Calc_Differences', fpLengthEMA);
        xPositiveDiff = getSeries(xDifferences, 0);
        xNegativeDiff = getSeries(xDifferences, 1);
        
        xPositiveDiffAvg = smma(fpLengthAvgDiff, xPositiveDiff);
        xNegativeDiffAvg = smma(fpLengthAvgDiff, xNegativeDiff);
                      
        bInit = true; 
    };

    var nPositiveDiffAvg = xPositiveDiffAvg.getValue(0);
    var nNegativeDiffAvg = xNegativeDiffAvg.getValue(0);

    if (nPositiveDiffAvg == null || nNegativeDiffAvg == null)
        return;
    
    var nSRSI = (nNegativeDiffAvg == 0) ? 100 : 100 - (100 / (1 + (nPositiveDiffAvg / nNegativeDiffAvg)));
    
    return [fpSRSIHighBorder, fpSRSILowBorder, 50, nSRSI];
}

var xClose = null;
var xEMA = null;

function Calc_Differences(nLength){
    
    if (getBarState() == BARSTATE_ALLBARS){
        xClose = close();
        xEMA = ema(nLength);
    }
    
    var nClose = xClose.getValue(0);
    var nEMA = xEMA.getValue(0);
    
    if (nClose == null || nEMA == null)
        return;
    
    var nPositiveDiff = nClose > nEMA ? nClose - nEMA : 0;
    var nNegativeDiff = nClose < nEMA ? nEMA - nClose : 0;
    
    return [nPositiveDiff, nNegativeDiff];
}

function verify(){
    var b = false;
    if (getBuildNumber() < 3742){
        
        drawTextAbsolute(5, 35, "This study requires version 12.1 or later.", 
            Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
            null, 13, "error");
        drawTextAbsolute(5, 20, "Click HERE to upgrade.@URL=http://www.esignal.com/download/default.asp", 
            Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
            null, 13, "upgrade");
        return b;
    } 
    else
        b = true;
    
    return b;
}