Hi All
I'm struggling to get to grips with EFS (my only programming knowledge comes from BASIC and a bit of EasyLanguage) and I'd be grateful if someone could help me with a simple modification to zeroLag_EC.efs.
Quite simply, I'd like to plot a red point (circle, square, whatever) when zeroLag_EC > zeroLag_EMA and a green point when zeroLag__EC < zeroLag_EMA. Ideally on a sub chart.
I can follow small sections of the code but my lack of ability is shown when I can't even see the part where the lines are actually plotted!
Hope someone can help.
Many thanks,
Ian
I'm struggling to get to grips with EFS (my only programming knowledge comes from BASIC and a bit of EasyLanguage) and I'd be grateful if someone could help me with a simple modification to zeroLag_EC.efs.
Quite simply, I'd like to plot a red point (circle, square, whatever) when zeroLag_EC > zeroLag_EMA and a green point when zeroLag__EC < zeroLag_EMA. Ideally on a sub chart.
I can follow small sections of the code but my lack of ability is shown when I can't even see the part where the lines are actually plotted!
Hope someone can help.
Many thanks,
Ian
PHP Code:
/*********************************
Provided By:
Interactive Data Corporation (Copyright © 2010)
All rights reserved. This sample eSignal Formula Script (EFS)
is for educational purposes only. Interactive Data Corporation
reserves the right to modify and overwrite this EFS file with
each new release.
Description:
Zero Lag (Well, Almost) Indicator by John Ehlers and Ric Way
Version: 1.0 13/09/2010
Formula Parameters: Default:
Length 20
Gain Limit 50
Notes:
The related article is copyrighted material. If you are not
a subscriber of Stocks & Commodities, please visit [url]www.traders.com[/url].
**********************************/
var fpArray = new Array();
var bVersion = null;
function preMain()
{
setPriceStudy(true);
setStudyTitle("zeroLag_EC");
setCursorLabelName("zeroLag_EMA", 0);
setDefaultBarStyle(PS_SOLID, 0);
setDefaultBarFgColor(Color.red, 0);
setDefaultBarThickness(2, 0);
setPlotType(PLOTTYPE_LINE, 0);
setCursorLabelName("zeroLag_EC", 1);
setDefaultBarStyle(PS_SOLID, 1);
setDefaultBarFgColor(Color.blue, 1);
setDefaultBarThickness(2, 1);
setPlotType(PLOTTYPE_LINE, 1);
var x=0;
fpArray[x] = new FunctionParameter("gLength", FunctionParameter.NUMBER);
with(fpArray[x++]){
setName("Length");
setLowerLimit(1);
setDefault(20);
}
fpArray[x] = new FunctionParameter("gGainLimit", FunctionParameter.NUMBER);
with(fpArray[x++]){
setName("Gain Limit");
setLowerLimit(1);
setDefault(50);
}
}
var bMainInit = false;
var xEMA = null;
var xEC = null;
var nAlpha = 0;
function main(gLength, gGainLimit)
{
var nGain = 0;
var nBestGain = 0;
var nError = 0;
var nLeastError = 1000000;
if (bVersion == null) bVersion = verify();
if (bVersion == false) return;
var nBarState = getBarState();
if (nBarState == BARSTATE_ALLBARS) {
if (gLength == null) gLength = 20;
if (gGainLimit == null) gGainLimit = 50;
nAlpha = 2/(gLength+1);
}
if (!bMainInit)
{
xEMA = efsInternal("calcEMA",nAlpha);
xEC = efsInternal("calcEC",nAlpha,gGainLimit,xEMA);
}
var nEMA = xEMA.getValue(0);
var nEC = xEC.getValue(0);
if( nEMA == null || nEC == null) return ;
return new Array( nEMA, nEC) ;
}
function calcEMA(nAlpha)
{
if (getCurrentBarCount()==1) var nRefEMA = close(0)
else var nRefEMA = ref(-1);
var vEMA = nAlpha*close(0)+(1-nAlpha)*nRefEMA;
return vEMA;
}
var nBestGain = 0;
function calcEC(nAlpha,nGaintLimit, xEMA)
{
var nLeastError = 1000000;
if (getCurrentBarCount()==1) var nRefEC = close(0)
else var nRefEC = ref(-1);
var nClose = close(0);
var vEMA = xEMA.getValue(0);
var nCount = 0;
var nGain = 0;
var nError = 0;
var vEC = 0 ;
for (nCount=-nGaintLimit; nCount<=nGaintLimit; nCount++)
{
nGain = nCount/10;
vEC = nAlpha*(vEMA+nGain*(nClose-nRefEC))+(1-nAlpha)*nRefEC;
nError = nClose - vEC;
if (Math.abs(nError)<nLeastError)
{
nLeastError = Math.abs(nError);
nBestGain = nGain;
}
}
vEC = nAlpha * (vEMA + nBestGain*(nClose - nRefEC))+(1-nAlpha)*nRefEC;
return vEC;
}
function verify() {
var b = false;
if (getBuildNumber() < 779) {
drawTextAbsolute(5, 35, "This study requires version 8.0 or later.",
Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
null, 13, "error");
drawTextAbsolute(5, 20, "Click HERE to upgrade.@URL=http://www.esignal.com/download/default.asp",
Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
null, 13, "upgrade");
return b;
} else {
b = true;
}
return b;
}
Comment