I tried to add xDel=pDMI-nDMI within one of Alexis's custom formulas (attached). I cannot get any output for this new variable while everything else works when tried. I suspect something is wrong with the variable definition. Can anyone tell me what is wrong?
Announcement
Collapse
No announcement yet.
Arithmetic within ADX-DMI study
Collapse
X
-
Here is one way to do it using efsInternal.
PHP Code:http://forum.esignal.com/showthread.php?s=&postid=143164#post143164
/*********************************************************
By Alexis C. Montenegro for eSignal © December 2004
Use and/or modify this code freely. If you redistribute it
please include this and/or any other comment blocks and a
description of any changes you make.
**********************************************************/
//20120427 - added efsInternal to calculate PDI-NDI difference
function preMain() {
var fpArray = new Array();
setPriceStudy(false);
setStudyTitle("ADXdelta_sh1");
// setCursorLabelName("+DI", 0);
// setCursorLabelName("-DI", 1);
// setCursorLabelName("ADX", 2);
setCursorLabelName("Delta");
// setPlotType(PLOTTYPE_LINE,0);
// setPlotType(PLOTTYPE_LINE,1);
// setPlotType(PLOTTYPE_LINE,2);
setPlotType(PLOTTYPE_LINE);
// setDefaultBarFgColor(Color.blue,0);
// setDefaultBarFgColor(Color.red,1);
// setDefaultBarFgColor(Color.magenta,2);
setDefaultBarFgColor(Color.green);
// setDefaultBarThickness(1,0);
// setDefaultBarThickness(1,1);
// setDefaultBarThickness(2,2);
setDefaultBarThickness(2);
// askForInput();
var x=0;
fpArray[x] = new FunctionParameter("Length", FunctionParameter.NUMBER);
with(fpArray[x++]){
setLowerLimit(1);
setDefault(14);
}
fpArray[x] = new FunctionParameter("Smoothing", FunctionParameter.NUMBER);
with(fpArray[x++]){
setLowerLimit(1);
setDefault(14);
}
fpArray[x] = new FunctionParameter("Symbol", FunctionParameter.STRING);
with(fpArray[x++]){
setDefault();
}
fpArray[x] = new FunctionParameter("Interval", FunctionParameter.STRING);
with(fpArray[x++]){
setDefault();
}
fpArray[x] = new FunctionParameter("Params", FunctionParameter.BOOLEAN);
with(fpArray[x++]){
setName("Show Parameters");
setDefault(false);
}
}
var bInit = false;
//var xADX = null;//not used in script
var xPDI = null;
var xNDI = null;
var xDel = null;//must be a global variable so it is available outside of bInit
function main(Length,Smoothing,Symbol,Interval,Params) {
var vSymbol;
if(bInit == false){
setShowTitleParameters(eval(Params));
if(Symbol == null) Symbol = getSymbol();
if(Interval == null) Interval = getInterval();
vSymbol = Symbol+","+Interval;
//xADX = getSeries(adx(Length,Smoothing,sym(vSymbol)));
xPDI = getSeries(pdi(Length,Smoothing,sym(vSymbol)));
xNDI = getSeries(ndi(Length,Smoothing,sym(vSymbol)));
xDEL = getSeries(efsInternal("fDiff",xPDI,xNDI));//efsInternal() calls function fDiff() & creates a series from it
//"sym(vSymbol)" isn't needed for the efsInternal because xPDI & xNDI individual values
//are already set via vSymbol. It would otherwise be needed for xDEL
bInit = true;
}
return xDEL;//plots the series
}
function fDiff(nPDI,nNDI){
return (nPDI - nNDI);//creates a series when called via efsInternal
}
PHP Code:http://forum.esignal.com/showthread.php?s=&postid=143164#post143164
/*********************************************************
By Alexis C. Montenegro for eSignal © December 2004
Use and/or modify this code freely. If you redistribute it
please include this and/or any other comment blocks and a
description of any changes you make.
**********************************************************/
//20120427 - added PDI-NDI difference calculation
function preMain() {
var fpArray = new Array();
setPriceStudy(false);
setStudyTitle("ADXdelta_sh1");
// setCursorLabelName("+DI", 0);
// setCursorLabelName("-DI", 1);
// setCursorLabelName("ADX", 2);
setCursorLabelName("Delta");
// setPlotType(PLOTTYPE_LINE,0);
// setPlotType(PLOTTYPE_LINE,1);
// setPlotType(PLOTTYPE_LINE,2);
setPlotType(PLOTTYPE_LINE);
// setDefaultBarFgColor(Color.blue,0);
// setDefaultBarFgColor(Color.red,1);
// setDefaultBarFgColor(Color.magenta,2);
setDefaultBarFgColor(Color.green);
// setDefaultBarThickness(1,0);
// setDefaultBarThickness(1,1);
// setDefaultBarThickness(2,2);
setDefaultBarThickness(2);
// askForInput();
var x=0;
fpArray[x] = new FunctionParameter("Length", FunctionParameter.NUMBER);
with(fpArray[x++]){
setLowerLimit(1);
setDefault(14);
}
fpArray[x] = new FunctionParameter("Smoothing", FunctionParameter.NUMBER);
with(fpArray[x++]){
setLowerLimit(1);
setDefault(14);
}
fpArray[x] = new FunctionParameter("Symbol", FunctionParameter.STRING);
with(fpArray[x++]){
setDefault();
}
fpArray[x] = new FunctionParameter("Interval", FunctionParameter.STRING);
with(fpArray[x++]){
setDefault();
}
fpArray[x] = new FunctionParameter("Params", FunctionParameter.BOOLEAN);
with(fpArray[x++]){
setName("Show Parameters");
setDefault(false);
}
}
var bInit = false;
//var xADX = null;//not used in script
var xPDI = null;
var xNDI = null;
function main(Length,Smoothing,Symbol,Interval,Params) {
var vSymbol;
var xDel = null;//use as a local variable since it is calculated on every tick
if(bInit == false){
setShowTitleParameters(eval(Params));
if(Symbol == null) Symbol = getSymbol();
if(Interval == null) Interval = getInterval();
vSymbol = Symbol+","+Interval;
//xADX = getSeries(adx(Length,Smoothing,sym(vSymbol)));
xPDI = getSeries(pdi(Length,Smoothing,sym(vSymbol)));
xNDI = getSeries(ndi(Length,Smoothing,sym(vSymbol)));
bInit = true;
}
xDEL = xPDI.getValue(0) - xNDI.getValue(0);//calculates the current bar's difference for xPDI & xNDI
//must be outside the bInit routine so it calculates on every tick
return xDEL;//plots individual values
}
WayneLast edited by waynecd; 04-27-2012, 08:02 PM.
-
An efficiency improvement over the second script I posted below is to remove the getSeries(...). It is not required because individual values are obtained via xPDI.getValue(0) so the series is not needed.
Use the attached script instead of the one in the previous post under:
A second way (more efficient in my view) uses individual values outside of the bInit routine:Attached Files
Comment
-
Thanks waynecd,
I had a computer crash and lost everything so I was busy re-installing and re-building my regular tools and did not visit the forum for a while. Both your versions work fine.
I am new to EFS (but an old hand to Basic and Fortran) so I will need some time to digest all the required terms and understand why my original did not print correctly. Prior to this, I had another modification that worked fine. I don't remember on what formula it was based.
During my re-building process, I had another try at it, starting from the Built-in formula "Basic ADXDM". That produced a very compact script that worked at first trial (see attachment)Attached Files
Comment
-
Glad it worked.
Your version works well if you only intend to use it with the charts interval and symbol.
As I understand it,
PHP Code:xDel = (pdi(14,14) - ndi(14,14));
It is more efficient to create the series once (inside the bInit) and retrieve the values you need evaluated on every tick within the body of "function main()".
Also, If you wish to plot the values from another symbol and/or interval than the one on the chart you need to define them for each study.
Wayne
Comment
Comment