getWeeklyOHLC.efs

ICE Data Services -

 

getWeeklyOHLC.efs    

File Name: getWeeklyOHLC.efs


Description:
Returns the Weekly OHLC data with the use of callFunction() and may be used with any interval less than weekly.

 

Formula Parameters:
sPriceSource: No Default value. Pass "Open" /"High"/"Low"/"Close" to callFunction()

 

Notes:
Save this formula to /eSignal/Formulas/OHLC/ and use this formula through the callFunction() function from your custom formulas to get the current week's OHLC prices.

Code Example:

function main() {
var vData = callFunction("/OHLC/getWeeklyOHLC.efs", "main", "High");
if (vData == null) return;
return vData;
}

Download File:
getWeeklyOHLC.efs




EFS Code:

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

function preMain() {
}

/**
  sPriceSource will be "Open", "High", "Close", or "Low"
 
  This formula is for callFunction() calls from an 
    external formula.
    
    example:

    var vData = callFunction("/OHLC/getWeeklyOHLC.efs", "main", "High");    
    if (vData == null) return;
    return vData;

**/


var vSymbol;
var vInterval;
var msPerDay = 24*60*60*1000;

function main(sPriceSource) {
	if(sPriceSource == null) return;

  	var vBar;
	var vBarTime;
	var vAbsTime;
	var vIndex;

	var nState = getBarState();
	if(nState == BARSTATE_ALLBARS) {
		vSymbol = getSymbol();
		vInterval = getInterval();
		vSymbol += ",W";
	}

	if(vInterval == null) return;

	if(vInterval == "W" || vInterval == "M") return;
	
	vBarTime = getValue("time");
	if(vBarTime != null) {
        var vTime = new Date();
        vIndex = (Math.round(Math.round((vTime.getTime() - vBarTime.getTime()) / msPerDay) / 7) * -1);
	    if(vIndex != null) {
			vBar = getValueAbsolute(sPriceSource, vIndex, vSymbol);
			return vBar;
	    }
	}
	
	return;
}