AutoFIB.efs

ICE Data Services -


AutoFIB.efs 
  

File Name: AutoFIB.efs


Description:
Displays Fibonacci levels automatically.


Formula Parameters:
NA

Notes:
** Please note this study requires a subscription to the Advanced Get Studies.

Download File:
AutoFIB.efs




EFS Code:
/************************Copyright � eSignal, 2003*************************Description: Displays Fibonacci levels automatically.** Please note this study requires a subscription to the Advanced Get Studies.*/var LINEMARGIN			= 5;var RIGHTTEXT			= true;function preMain() {    checkVersion(2, "http://share.esignal.com/ContentRoot/PowerStation/MAG-EFS/AutoFIB.efs");    addEntitlement("AGST", "Not entitled for Advanced GET Studies");	setStudyTitle("Auto FIB");	setPriceStudy(true);}var elliott = new GetElliottStudy(300, 0, 50, 5, 35, 0);var nLastMRW		= null; // Last Most Recent Wave (used for reloading)var nLastMRWIndex   = null;var dLastMRWHigh	= null;var dLastMRWLow		= null;var arWaves		= new Array();var arWaveBar		= new Array();var bFibDrawn		= false;function dumpWaves() {	debugPrintln("Dumping Waves");	var i;	for(i = 0; i < arWaveBar.length; i++) {		debugPrintln("    Wave[" + i + "]" + arWaves[i] + " Index: " + arWaveBar[i]);	}}var WAVE_A			= 7var WAVE_B			= 8var WAVE_C			= 9var WAVENOTFOUND		= 1; // this is a bar indexfunction isABC(nWave) {	nWave = Math.abs(nWave);	if(nWave == 7 || nWave == 8 || nWave == 9)		return true;	return false;}function findPriorWave(nWave) {	var i;	if(arWaves.length == 0)		return WAVENOTFOUND;	var nStart = arWaves.length-1;	nStart--;	for(i = nStart; i >= 0; i--) {		var nWaveBar = Math.abs(arWaves[i]);		// If a 4 stop searching		if(nWaveBar == 4 || nWaveBar == WAVE_A || nWaveBar == WAVE_B)			return WAVENOTFOUND;		if(nWaveBar == nWave)			return arWaveBar[i];	}		return WAVENOTFOUND;}function findWavePriorToWave5(nWave) {	var i;	if(arWaves.length == 0)		return WAVENOTFOUND;	var bTrigger = false;	var nStart = arWaves.length-1;	nStart--;	for(i = nStart; i >= 0; i--) {		var nWaveBar = Math.abs(arWaves[i]);				if(bTrigger == true)			break;		// If a 4 stop searching		if(nWaveBar == 5 || nWaveBar == WAVE_C)			bTrigger = true;		if(nWaveBar == nWave)			return arWaveBar[i];	}		return WAVENOTFOUND;}function findWaveBeforeABC() {	var i;	if(arWaves.length == 0)		return WAVENOTFOUND;	var nStart = arWaves.length-1;	nStart--;	var bTrigger = false;	for(i = nStart; i >= 0; i--) {		var nWaveBar = Math.abs(arWaves[i]);				if(bTrigger == true) {			return arWaveBar[i];				}		if(nWaveBar == WAVE_A) 			bTrigger = true;		else if(nWaveBar < WAVE_A)			return WAVENOTFOUND;	}		return WAVENOTFOUND;}function findPriorWaveABC(nWave) {	var i;	if(arWaves.length == 0)		return WAVENOTFOUND;	var nStart = arWaves.length-1;	nStart--;	for(i = nStart; i >= 0; i--) {		var nWaveBar = Math.abs(arWaves[i]);		// If a 4 stop searching		if(nWaveBar < WAVE_A)			return WAVENOTFOUND;		if(nWaveBar == nWave)			return arWaveBar[i];	}		return WAVENOTFOUND;}function findCurrentWave(nWave) {	if(arWaves.length == 0)		return WAVENOTFOUND;	var nStart = arWaves.length-1;	var nWaveBar = Math.abs(arWaves[nStart]);	if(nWaveBar == nWave)		return arWaveBar[nStart];	return WAVENOTFOUND;}function findOnePriorWave(nWave) {	if(arWaves.length < 2)		return WAVENOTFOUND;	var nStart = arWaves.length-1;	var nWaveBar = Math.abs(arWaves[nStart-1]);	if(nWaveBar == nWave)		return arWaveBar[nStart-1];	return WAVENOTFOUND;}function getRetracement(dH, dL, dPercent, nMRW) {	if(nMRW > 0) {		return dL - ((dL-dH) * dPercent);	} else if(nMRW < 0) {		return dL + ((dH-dL) * dPercent);	}	return null;}				function getExtension(dH, dL, dExt, dPercent, nMRW) {	if(nMRW > 0) {		return dExt + ((dL-dH) * dPercent);	} else if(nMRW < 0) {		return dExt - ((dH-dL) * dPercent);	}	return null;}function getHL(nBar, bFirst, nMRW) {	if(nMRW > 0) {		if(bFirst) {			return low(nBar);		} else {			return high(nBar);		}	} else if(nMRW < 0) {		if(bFirst) {			return high(nBar);		} else {			return low(nBar);		}	}		return null;}function addText(sText, nX, dY) {	if(RIGHTTEXT == true) {		drawTextAbsolute(LINEMARGIN, dY, sText, 			Color.blue, null,			Text.BOTTOM | Text.LEFT | Text.ONTOP | Text.BOLD, 			null, null, sText + "-" + getValue("rawtime"));	} else {		drawTextRelative(nX, dY, sText, 			Color.blue, null,			Text.BOTTOM | Text.RIGHT | Text.ONTOP | Text.BOLD, 			null, null, sText + "-" + getValue("rawtime"));	}}function getWaveColor(nWave) {	if(nWave < 0) {		return Color.red;	} else if(nWave > 0) {		return Color.lime;	} 		return Color.black;}function formatWave(nWave) {	var nRawWave = nWave;		nWave = Math.abs(nWave);	var vRet = "" + nWave;	if(nWave == WAVE_A) 		vRet = "A";	else if(nWave == WAVE_B)		vRet = "B";	else if(nWave == WAVE_C)		vRet = "C";			return vRet;}/****W2 Ret is measured from end of W5 to end of W1W3 Ext is based on measurement from end of W5 to end of W1 but starting the extension from end of W2W4 Ret is measured from end of W2 to end of W3W5 Ext is based on measurement from end of W5 to end of W3 but starting the extension from end of W4W2 is 0.50 to 0.75 retracement of W1 (up to 0.99)W3 is 1.618, 2.618, 4.25, 6.25 of W1 measured from end of W2W4 is 0.382 to 0.50 of W3 (up to 0.618)W5 is 0.618 of W1 to W3 measured from end of W4 (up to 1.00)Wave B is like W2Wave C is 1.00 of  WA measured from end of WB***/function main() {	// What's the most recent wave?  If it has changed since last remembered, reload the EFS.	var nMRW = elliott.getValue(GetElliottStudy.MOSTRECENTWAVE);	var nMRWIndex = elliott.getValue(GetElliottStudy.MOSTRECENTWAVEBARINDEX);		if(nMRWIndex == null)        return;        	if(getCurrentBarIndex() == 0) {		if(nLastMRW == null) {			nLastMRW = nMRW;			nLastMRWIndex = nMRWIndex;			dLastMRWHigh = high(nMRWIndex);			dLastMRWLow = low(nMRWIndex);		} else if(nLastMRW != nMRW || nMRWIndex > nLastMRWIndex || low(nMRWIndex) != dLastMRWLow || high(nMRWIndex) != dLastMRWHigh) {			nLastMRW = null;			nLastMRWIndex = null;			dLastMRWHigh = null;				dLastMRWLow = null;			reloadEFS();			return;		} else {			nLastMRWIndex = nMRWIndex;			dLastMRWHigh = high(nMRWIndex);			dLastMRWLow = low(nMRWIndex);		}	}	var nBarState = getBarState();	// If ALLBARS, init the wave arrays and vars.	// If newbar, shift the bar indexes	if(nBarState == BARSTATE_ALLBARS) {		clearText();		clearLineTool(LineTool.SEGMENT);		arWaves.length		= 0;		arWaveBar.length	= 0;		bFibDrawn		= false;	} else if(nBarState == BARSTATE_NEWBAR) {		// Get the current wave for a specific bar and add the wave and bar to the arrays		var nWave = elliott.getValue(GetElliottStudy.WAVE);		if(nWave != null) {			arWaves.push(nWave);			arWaveBar.push(getCurrentBarIndex());		}	}	// If on the most recent bar and the ellipses haven't been drawn, search for them	// and draw them.	// Should the MRW change, a reload will occur and this will re-execute.	if(bFibDrawn == false && getCurrentBarIndex() == 0) {		bFibDrawn = true;				// dumpWaves();		// Use nMRW to determine which way to draw wave.		drawTextAbsolute(1, 15, "CurWave: " + formatWave(nMRW),			Color.black, getWaveColor(nMRW), 			Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.FRAME | Text.BOLD, 			null, null, "OB");				if(Math.abs(nMRW) == 3) {			var nBar1 = findPriorWave(1);			var nBar2 = findPriorWave(2);			var nBar5 = findPriorWave(5);			var nBarC = findPriorWave(WAVE_C);						if(nBar5 == WAVENOTFOUND)				nBar5 = nBarC;							if(nBar1 != WAVENOTFOUND && nBar2 != WAVENOTFOUND && nBar5 != WAVENOTFOUND) {				var vH = getHL(nBar5, true, nMRW);				var vL = getHL(nBar1, false, nMRW);				var v2 = getHL(nBar2, true, nMRW);				addLineTool(LineTool.SEGMENT, nBar5, vH, 0, vH, 1, Color.black, "tag");				addLineTool(LineTool.SEGMENT, nBar5, vL, 0, vL, 1, Color.black, "tag");				addLineTool(LineTool.SEGMENT, nBar1, v2, 0, v2, 1, Color.black, "tag");								var v1618 = getExtension(vH, vL, v2, 1.618, nMRW);				var v2618 = getExtension(vH, vL, v2, 2.618, nMRW);				var v425  = getExtension(vH, vL, v2, 4.25,  nMRW);				var v625  = getExtension(vH, vL, v2, 6.25,  nMRW);				addLineTool(LineTool.SEGMENT, nBar2, v1618,  LINEMARGIN, v1618,  2, Color.blue, "tag");				addLineTool(LineTool.SEGMENT, nBar2, v2618,  LINEMARGIN, v2618,  2, Color.blue, "tag");				addLineTool(LineTool.SEGMENT, nBar2, v425,   LINEMARGIN, v425,   2, Color.blue, "tag");				addLineTool(LineTool.SEGMENT, nBar2, v625,   LINEMARGIN, v625,   2, Color.blue, "tag");				addText("1.618", nBar2, v1618);								addText("2.618", nBar2, v2618);								addText("4.25",  nBar2, v425);								addText("6.25",  nBar2, v625);																	}		} else if(Math.abs(nMRW) == 4) { // 			var nBar2 = findPriorWave(2);			var nBar3 = findPriorWave(3);						if(nBar2 != WAVENOTFOUND && nBar3 != WAVENOTFOUND) {				var vH = getHL(nBar2, true, nMRW);				var vL = getHL(nBar3, false, nMRW);								addLineTool(LineTool.SEGMENT, nBar2, vH, nBar3, vH, 1, Color.black, "tag");				addLineTool(LineTool.SEGMENT, nBar2, vL, nBar3, vL, 1, Color.black, "tag");				var v382 = getRetracement(vH, vL, 0.382, nMRW);				var v50  = getRetracement(vH, vL, 0.5, nMRW);				var v618 = getRetracement(vH, vL, 0.618, nMRW);								addLineTool(LineTool.SEGMENT, nBar3, v382, LINEMARGIN, v382, 2, Color.blue, "tag");				addLineTool(LineTool.SEGMENT, nBar3, v50,  LINEMARGIN, v50,  2, Color.blue, "tag");				addLineTool(LineTool.SEGMENT, nBar3, v618, LINEMARGIN, v618, 2, Color.blue, "tag");				addText("0.382", nBar3, v382);								addText("0.50",  nBar3, v50);								addText("0.618", nBar3, v618);										}					} else if(Math.abs(nMRW) == 5) {			var nBar3 = findWavePriorToWave5(3);			var nBar4 = findWavePriorToWave5(4);			var nBar5 = findWavePriorToWave5(5);			var nBarC = findWavePriorToWave5(WAVE_C);						if(nBar5 == WAVENOTFOUND)				nBar5 = nBarC;							if(nBar3 != WAVENOTFOUND && nBar4 != WAVENOTFOUND && nBar5 != WAVENOTFOUND) {				var vH = getHL(nBar5, true, nMRW);				var vL = getHL(nBar3, false, nMRW);				var v4 = getHL(nBar4, true, nMRW);												addLineTool(LineTool.SEGMENT, nBar5, vH, nBar3, vH, 1, Color.black, "tag");				addLineTool(LineTool.SEGMENT, nBar5, vL, nBar3, vL, 1, Color.black, "tag");				addLineTool(LineTool.SEGMENT, nBar3, v4, nBar4, v4, 1, Color.black, "tag");				var v618 = getExtension(vH, vL, v4, 0.618, nMRW);				var v100 = getExtension(vH, vL, v4, 1.0, nMRW);								addLineTool(LineTool.SEGMENT, nBar4, v100, LINEMARGIN, v100,  2, Color.blue, "tag");				addLineTool(LineTool.SEGMENT, nBar4, v618, LINEMARGIN, v618, 2, Color.blue, "tag");				addText("1.0", 	 nBar4, v100);				addText("0.618", nBar4, v618);											}					} else if(Math.abs(nMRW) == WAVE_C) {			var nBarA = findPriorWaveABC(WAVE_A);			var nBarB = findPriorWaveABC(WAVE_B);						if(nBarA != WAVENOTFOUND && nBarB != WAVENOTFOUND) {				var nBarX = findWaveBeforeABC();								if(nBarX != WAVENOTFOUND) {					var vH = getHL(nBarX, true, nMRW);					var vL = getHL(nBarA, false, nMRW);					var vB = getHL(nBarB, true, nMRW);					addLineTool(LineTool.SEGMENT, nBarX, vH, nBarA, vH, 1, Color.black, "tag");					addLineTool(LineTool.SEGMENT, nBarX, vL, nBarA, vL, 1, Color.black, "tag");					var v100 = getExtension(vH, vL, vB, 1.00, nMRW);										addLineTool(LineTool.SEGMENT, nBarB, v100, LINEMARGIN, v100,  2, Color.blue, "tag");					addText("1.0", 	 nBarB, v100);									}							}				} else if(Math.abs(nMRW) == WAVE_B) {		}	}	return;	}