PivotPointAllweekly.efs

ICE Data Services -

PivotPointAllweekly.efs  

File Name: PivotPointAllweekly.efs

Description:
Plots Weekly Pivot Points and may be used with intra-day or Daily intervals.

Formula Parameters:
NA

Notes:
NA

Download File:
PivotPointAllweekly.efs



EFS Code:

/****************************************************************************************************
Copyright © eSignal, a division of Interactive Data Corporation. 2003. All rights reserved. 
This sample eSignal Formula Script (EFS) may be modified and saved under a new 
filename; however, eSignal is no longer responsible for the functionality once modified.
eSignal reserves the right to modify and overwrite this EFS file with each new release.
****************************************************************************************************/

/* Updated 4/14/03 */
/* Updated 9/16/05
    -- fix for Monday Holidays (vIndex) */

function preMain() {
	setPriceStudy(true);
	setStudyTitle("Weekly Pivot Points");
	setCursorLabelName("PP-R2", 0);
	setCursorLabelName("PP-R1", 1);
	setCursorLabelName("PP", 2);
	setCursorLabelName("PP-S1", 3);
	setCursorLabelName("PP-S2", 4);
	
	// R2
	setDefaultBarStyle(PS_DASH, 0);
	setDefaultBarFgColor(Color.RGB(255,0,0), 0);
	setDefaultBarThickness(2, 0);

	// R1
	setDefaultBarStyle(PS_DOT, 1);
	setDefaultBarFgColor(Color.RGB(0,0,255), 1);
	setDefaultBarThickness(2, 1); 

    // Pivot  Point
	setDefaultBarStyle(PS_SOLID, 2);
	setDefaultBarFgColor(Color.RGB(0,0,0), 2);
	setDefaultBarThickness(2, 2);

    // S1
	setDefaultBarStyle(PS_DOT, 3);
	setDefaultBarFgColor(Color.RGB(0,0,255), 3);
	setDefaultBarThickness(2, 3);

	// S2
	setDefaultBarStyle(PS_DASH, 4);
	setDefaultBarFgColor(Color.RGB(255,0,0), 4);
	setDefaultBarThickness(2, 4);
}

var vLastPP = null;
var vLastPPR1 = null;
var vLastPPR2 = null;
var vLastPPS1 = null;
var vLastPPS2 = null;
var vLastArray = null;
var vSymbol = null;
var vInterval = null;
var vReset = true;
var msPerDay = 24*60*60*1000;
var vIndex = null;
var vBarTime = null;
var vPrevBarTime = null;
var vNew = false;

function main() {   
    var vH;
    var vL;
    var vC;

	var nState = getBarState();
	if(vReset == true) {
		vLastArray = null;
		vLastPP = null;
		vLastPPR1 = null;
		vLastPPR2 = null;
		vLastPPS1 = null;
		vLastPPS2 = null;
		vInterval = getInterval();
		vSymbol = getSymbol();
		vSymbol += ",W";
		vReset = false;
	}
	
	if(vInterval == null)
	    return null;
  
	if(vInterval == "W")
	    return null;
	    
	if(vInterval == "M")
	    return null;
	    
	if(vInterval == "T")
	    return null;

    if (nState == BARSTATE_NEWBAR) {
        vPrevBarTime = vBarTime;
    }
	vBarTime = getValue("time");
	if(vBarTime != null && vPrevBarTime != null && nState == BARSTATE_NEWBAR) {
        if (vNew == false) {
            if (vPrevBarTime.getDay() - vBarTime.getDay() > 1) vNew = true;
        }
        if (vNew == true) {
            var vTime = new Date();
            vIndex = (Math.round(Math.round((vTime.getTime() - vBarTime.getTime()) / msPerDay) / 7) * -1) -1;
            if (vBarTime.getDay() == 2) vIndex--;  // fix for Monday Holidays.
            vNew = false;
        }
	    if(vIndex != null) {
			vH = getValueAbsolute("High", vIndex, vSymbol);
			vL = getValueAbsolute("Low",  vIndex, vSymbol);
			vC = getValueAbsolute("Close", vIndex, vSymbol);
			if(vH != null && vL != null && vC != null) {
				vLastPP = (vH + vL + vC) / 3;
				vLastPPR1 = 2 * vLastPP - vL;
				vLastPPS1 = 2 * vLastPP - vH;
				vLastPPR2 = (vLastPP - vLastPPS1) + vLastPPR1;
				vLastPPS2 = vLastPP - (vLastPPR1 - vLastPPS1);
				vLastArray = new Array(vLastPPR2, vLastPPR1, vLastPP, vLastPPS1, vLastPPS2);

				return vLastArray;
			}
	    } 
	}

	return vLastArray;
}