getPrevDaysOHLC.efs

ICE Data Services -

getPrevDaysOHLC.efs    

File Name: getPrevDaysOHLC.efs


Description:
Utility formula that returns a single value or an array of values for previous days' Daily open, high, low and close data.

Formula Parameters:

  • nPriceSource: Default is Close (valid inputs: Open, High, Low or Close).
  • nOffset: Default is -1
  • nNumDays: Default is 1

Notes:
This formula is intended to be used by other custom formulas to access previous days' daily values that can then be used with formulas that need to plot the daily data on intra-day intervals. Save this formula to /eSignal/Formulas/OHLC/ and use the callFunction() function as follows from your custom formula.

 

var sPriceSource = "Close";
var nOffset = -5;
var nNumDays = 5;
var aHighs = callFunction("/OHLC/getPrevDaysOHLC.efs", "main", sPriceSource, nOffset, nNumDays);
if (aHighs == null) return;


The above example will return the previous five days' closing prices. For a working example, please see PrevHHLL.efs.

 

Download File:
getPrevDaysOHLC.efs

EFS Code:

/*****************************************************************
Provided By : eSignal. (c) Copyright 2003
*****************************************************************/

function preMain() {
    setPriceStudy(true);
    setStudyTitle("Get Previous Days OHLC");
}

var vSymbol = null;
var vReset = true;

function main(nPriceSource, nOffset, nNumDays) {
    if (nPriceSource == null) 
        nPriceSource = "Close";
    if (nOffset == null) {
        nOffset = -1;
    } else {
        nOffset = (Math.abs(nOffset) * -1);
    }
    if (nNumDays == null) {
        nNumDays = 1;
    } else {
        nNumDays = Math.abs(nNumDays);
    }

	var nState = getBarState();
	if(vReset == true) {
		vDay1 = null;
		vSymbol = (getSymbol() + ",D");
		vReset = false;
	}
    
	vBarTime = getValue("time");
	if(vBarTime != null) {
        var vDay = vBarTime.getDay();
        if (vDay == 0) {
            var vDate = vBarTime.getDate();
            vDate -= 2;
            vBarTime.setDate(vDate);
        }
  	    var vAbsTime = getPreviousTradingDay(vBarTime, vSymbol);
	    if(vAbsTime == null) {
	        return;
	    }
	    vIndex = getFirstBarIndexOfDay(vAbsTime, vSymbol);
	    if(vIndex != null) {
			var vValue = getValueAbsolute(nPriceSource, (vIndex + nOffset), -nNumDays, vSymbol);
			if(vValue == null) {
                return null;
			}
	    } 
	}

	return vValue;
}