2004 Jun: VolumeCurtailment.efs

ICE Data Services -

VolumeCurtailment.efs   

File Name: VolumeCurtailment.efs

Description:

Based on Using Money Flow to Stay With the Trend by Markos Katsanos. This article appeared in the June 2004 issue of Stock & Commodities.

Formula Parameters:

  • Length - 30

Notes:
The related article is copyrighted material. If you are not a subscriber of Stocks & Commodities, please visit www.traders.com.Version 1.1This formula has been modified 5/4/2004. An input parameter for the Length was added and the MA length of volume for volume curtailment is set to the same length.

Download File:
VolumeCurtailment.efs


EFS Code:

/*****************************************************************
Provided By : eSignal. (c) Copyright 2004
Study:        Volume Curtailment by Markos Katsanos
Version:      1.1

4/8/2004

Notes: 1.1  5/4/2004
* Added input parameter for Length and set MA length of
  volume for volume curtailment to the same length.

Formula Parameters:                 Default:
    Length                          30  

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


function preMain() {
    setStudyTitle("Volume Curtailment ");
    setShowTitleParameters(false);
    setCursorLabelName("Volume", 0);
    setCursorLabelName("Vol Cutoff", 1);
    setDefaultBarFgColor(Color.green, 0);
    setDefaultBarFgColor(Color.black, 1);
    setDefaultBarThickness(3, 0);
    setDefaultBarThickness(1, 1);
    setPlotType(PLOTTYPE_HISTOGRAM, 0);

    var fp0 = new FunctionParameter("nLength", FunctionParameter.NUMBER);
    fp0.setName("Length");
    fp0.setLowerLimit(1);
    fp0.setDefault(26);
}


var nTyp = null;                // Current typical price
var nTyp1 = null;               // Previous typical price
var nTypChg = 0;                // Current typical price change
var vVol = null;                // Current volume
var nVolSum = 0;                // Cumulative volume sum
var nVolAdj = 0;                // Current adjusted volume
var nVolMA = null;              // Current Vol MA
var nVolMA1 = null;             // Previous Vol MA
//var aTypPrice = new Array(30);  // Array of changes in typical price
//var aVolume = new Array(50);    // Volume array
var aTypPrice = null;  // Array of changes in typical price
var aVolume = null;    // Volume array
var bEdit = false;

function main(nLength) {
    var nState = getBarState();
    var vInter = 0;
    var nCutoff = 0;
    var dSum = 0;
    var i = 0;
    var vColor = Color.blue;
    
    if (bEdit == false) {
        if (aTypPrice == null) aTypPrice = new Array(nLength);
        if (aVolume == null) aVolume = new Array(nLength);
        bEdit = true;
    }
    
    if (nState == BARSTATE_NEWBAR) {
        if (nTyp != null) {
            aTypPrice.pop();
            aTypPrice.unshift(nTypChg);
            nTyp1 = nTyp;
        }
        if (nVol != null) {
            aVolume.pop();
            aVolume.unshift(nVol);
        }
        nVolMA1 = nVolMA;
        nVolSum += nVolAdj;
    }
    
    nVol = volume();
    if (nVol == null) return;
    aVolume[0] = nVol;
    if (aVolume[nLength-1] != null) {
        for (i = 0; i < nLength; ++i) {
            dSum += aVolume[i];
        }
        nVolMA = dSum/nLength;
    }
    
    nTyp = (high() + low() + close()) / 3;
    if (nTyp1 != null) {
        nTypChg = (Math.log(nTyp) - Math.log(nTyp1));
        aTypPrice[0] = nTypChg;
    }
    
    if (nVolMA == null || nVolMA1 == null) return;
    
    if (aTypPrice[nLength-1] != null) {
        vInter = StDev(nLength);
        nCutoff = (.2 * vInter * close());
    } else {
        return;
    }

    nVolAdj = nVol;
    //Minimal Change Cutoff
    if ((nTyp - nTyp1) >= 0 && (nTyp - nTyp1) < nCutoff) nVolAdj = 0;
    if ((nTyp - nTyp1) < 0 && (nTyp - nTyp1) > -nCutoff) nVolAdj = 0;
    // Volume curtailment
    if (nVolAdj > (2.5*nVolMA1)) nVolAdj = (2.5*nVolMA1);
    
    if (nTyp - nTyp1 < 0) nVolAdj *= -1;
    
    if (nVolAdj > 0) vColor = Color.green;
    if (nVolAdj < 0) vColor = Color.red;
    setBarFgColor(vColor);
    
    return new Array(nVol, (2.5*nVolMA1).toFixed(0)*1);
}


/***** Functions *****/

function StDev(nLength) {
    //var nLength = 30;
    
    var sumX = 0;
    var sumX2 = 0;
    for (i = 0; i < nLength; ++i) {
        sumX += aTypPrice[i];
        sumX2 += (aTypPrice[i] * aTypPrice[i])
    }
    var meanX = (sumX/nLength);
    var stdev = Math.sqrt((sumX2/nLength) - (meanX*meanX));

    return stdev;
}