2003 Jul: RelativeVolume.efs

ICE Data Services -

RelativeVolume.efs  

EFSLibrary - Discussion Board

File Name: RelativeVolume.efs

Description:
This formula is based on Relative Volume Analysis by Thom Hartle, which appeared in the July 2003 issue of Active Trader Magazine.

Formula Parameters:

  • Symbol: NYSE [NASDAQ, NYSE]

Notes:
The related article is copyrighted material. If you are not a subscriber of Active Trader Magazine, please visit www. activetradermag.com.

Updated Version 1.1 7/13/2004
vRelVol was corrected to be the maximum of vUpVol/vTotVol or vDnVol/vTotVol per instructions from Thom Hartle.

Download File:
RelativeVolume.efs



EFS Code:

/*********************************
Provided By:  
    Interactive Data Corporation (Copyright В© 2014) 
    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:        
    RelativeVolume by Melvin E. Dickover: 
    finds spikes of volume above numStDevs standard
    deviations of the average volume of the lookback period.

Formula Parameters:                     Default:
Period                                  60
StDevs                                  2 

Version:            1.00  14/05/2014

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("RelativeVolume");
    setPlotType(PLOTTYPE_HISTOGRAM);
  
    var x = 0;

    fpArray[x] = new FunctionParameter("fpPeriod", FunctionParameter.NUMBER);
    with(fpArray[x++])
    {
        setName("Period");
        setDefault(60);
        setLowerLimit(1);
    }

    fpArray[x] = new FunctionParameter("fpNumStDevs", FunctionParameter.NUMBER);
    with(fpArray[x++])
    {
        setName("StDevs");
        setDefault(2);
    }
}

var bInit = false;
var bVersion = null;

var x_Volume = null;
var x_av = null;
var x_sd = null;
var x_relVol = null;

function main(fpPeriod, fpNumStDevs) 
{
    if (bVersion == null) bVersion = verify();
    if (bVersion == false) return;
    
    if (!bInit)
    {   
        x_Volume = volume();

        x_av = sma(fpPeriod, x_Volume);
        x_sd = efsInternal("Calc_Std", fpPeriod, x_Volume);
        x_relVol = efsInternal("Calc_Rel", x_Volume, x_av, x_sd);
     
        bInit = true;
    }

    var n_RelVol = x_relVol.getValue(0);

    if (n_RelVol == null)
        return;

    if (n_RelVol > fpNumStDevs)
        setBarFgColor(Color.blue)
    else
        setBarFgColor(Color.grey);
  
    return n_RelVol;
}

var xSMA = null;

function Calc_Std(nPeriod, xSourse)
{
    if (getBarState() == BARSTATE_ALLBARS)
    {
        xSMA = sma(nPeriod, xSourse);
    } 

    var nSMA = xSMA.getValue(0);

    if (nSMA == null)
        return;

    var nSum = 0;

    for (var i = 0; i < nPeriod; i++)
    {
       var nSource = xSourse.getValue(-i);
       
       if (nSource == null)
           return;

       var nVal = Math.pow((nSource - nSMA), 2);
       
       nSum += nVal; 
    }

    var nReturnValue = Math.sqrt(nSum / nPeriod);
          
    return nReturnValue;
}

function Calc_Rel(xSourse, xSourseAV, xSourseSD)
{
    var nSourse = xSourse.getValue(0);
    var nSourseAV = xSourseAV.getValue(0);
    var nSourseSD = xSourseSD.getValue(0);

    if(nSourse == null || nSourseAV == null || nSourseSD == null)
        return; 

    var nReturnValue = (nSourse - nSourseAV) / nSourseSD;          
          
    return nReturnValue;
}

function verify() 
{
    var b = false;
    if (getBuildNumber() < 779) 
    {
        drawTextAbsolute(5, 35, "This study requires version 8.0 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;
}