I really like the zero lag ema and I'm trying to use it with some condition statements, but it doesn't follow the conditions. It just seems to randomly plot. I wrote a simple conditional statement to setBarBgcolor if the high(-3) < the zerolag && the current bar low(0) > the zerolag, but as I said, it seems to just plot randomly. Could someone take a look at this and tell me what I need to do, or point me in the right direction. Thanks!
/*********************************
Provided By:
eSignal (Copyright © eSignal), a division of Interactive Data
Corporation. 2007. All rights reserved. This sample eSignal
Formula Script (EFS) is for educational purposes only and may be
modified and saved under a new file name. eSignal is not responsible
for the functionality once modified. eSignal reserves the right
to modify and overwrite this EFS file with each new release.
Description: Trading Divergences
by Sylvain Vervoort
Version: 1.0 12/7/2007
Notes:
* February 2008 Issue of Stocks and Commodities Magazine
* Study requires version 8.0 or later.
Formula Parameters: Defaults:
Periods 20
**********************************/
function preMain() {
setPriceStudy(true);
setStudyTitle("Zero Lag EMA test");
setCursorLabelName("ZEMA", 0);
setDefaultBarFgColor(Color.white, 0);
setDefaultBarThickness(2, 0);
var fp1 = new FunctionParameter("nPeriods", FunctionParameter.NUMBER);
fp1.setName("Periods");
fp1.setLowerLimit(1);
fp1.setDefault(13);
}
// Global Variables
var bVersion = null; // Version flag
var bInit = false; // Initialization flag
var xEma1 = null;
var xEma2 = null;
function main(nPeriods) {
var nState = getBarState();
var nIndex = getCurrentBarIndex();
if (bVersion == null) bVersion = verify();
if (bVersion == false) return;
if (bInit == false) {
xEma1 = ema(nPeriods);
xEma2 = ema(nPeriods, xEma1);
bInit = true;
}
var nZEma = null;
var nEma1 = xEma1.getValue(0);
var nEma2 = xEma2.getValue(0);
if (nEma1 == null || nEma2 == null) return;
nZEma = nEma1 + (nEma1 - nEma2);
if(high(-3) < nZEma &&
low(0) > nZEma) {
setBarBgColor(Color.RGB(123,103,0));
}
return nZEma;
}
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.BOL D|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.BOL D|Text.LEFT,
null, 13, "upgrade");
return b;
} else {
b = true;
}
return b;
}
/*********************************
Provided By:
eSignal (Copyright © eSignal), a division of Interactive Data
Corporation. 2007. All rights reserved. This sample eSignal
Formula Script (EFS) is for educational purposes only and may be
modified and saved under a new file name. eSignal is not responsible
for the functionality once modified. eSignal reserves the right
to modify and overwrite this EFS file with each new release.
Description: Trading Divergences
by Sylvain Vervoort
Version: 1.0 12/7/2007
Notes:
* February 2008 Issue of Stocks and Commodities Magazine
* Study requires version 8.0 or later.
Formula Parameters: Defaults:
Periods 20
**********************************/
function preMain() {
setPriceStudy(true);
setStudyTitle("Zero Lag EMA test");
setCursorLabelName("ZEMA", 0);
setDefaultBarFgColor(Color.white, 0);
setDefaultBarThickness(2, 0);
var fp1 = new FunctionParameter("nPeriods", FunctionParameter.NUMBER);
fp1.setName("Periods");
fp1.setLowerLimit(1);
fp1.setDefault(13);
}
// Global Variables
var bVersion = null; // Version flag
var bInit = false; // Initialization flag
var xEma1 = null;
var xEma2 = null;
function main(nPeriods) {
var nState = getBarState();
var nIndex = getCurrentBarIndex();
if (bVersion == null) bVersion = verify();
if (bVersion == false) return;
if (bInit == false) {
xEma1 = ema(nPeriods);
xEma2 = ema(nPeriods, xEma1);
bInit = true;
}
var nZEma = null;
var nEma1 = xEma1.getValue(0);
var nEma2 = xEma2.getValue(0);
if (nEma1 == null || nEma2 == null) return;
nZEma = nEma1 + (nEma1 - nEma2);
if(high(-3) < nZEma &&
low(0) > nZEma) {
setBarBgColor(Color.RGB(123,103,0));
}
return nZEma;
}
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.BOL D|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.BOL D|Text.LEFT,
null, 13, "upgrade");
return b;
} else {
b = true;
}
return b;
}
Comment