I'm trying to develop an ADX study that shows an up arrow when the +DI crosses the -DI and the ADX is above or equal to a certain value (18 for example) or a down arrow when the reverse is true. As an example, at the last bar the +DI is less than the -DI and on the current bar the +DI is greater than the -DI, all while being above or equal to an ADX value of 18. Any help would be greatly appreciated.
//{{EFSWizard_Description
//
// This formula was generated by the Alert Wizard
//
//}}EFSWizard_Description
//{{EFSWizard_Declarations
var vADXDM14_14 = new ADXDMStudy(14, 14);
var vLastAlert = -1;
//}}EFSWizard_Declarations
function preMain() {
/**
* This function is called only once, before any of the bars are loaded.
* Place any study or EFS configuration commands here.
*/
//{{EFSWizard_PreMain
setPriceStudy(false);
setStudyTitle("ADX Crossover");
setCursorLabelName("ADX", 0);
setCursorLabelName("PDI", 1);
setCursorLabelName("NDI", 2);
setDefaultBarStyle(PS_SOLID, 0);
setDefaultBarStyle(PS_SOLID, 1);
setDefaultBarStyle(PS_SOLID, 2);
setDefaultBarFgColor(Color.green, 0);
setDefaultBarFgColor(Color.blue, 1);
setDefaultBarFgColor(Color.red, 2);
setDefaultBarThickness(2, 0);
setDefaultBarThickness(1, 1);
setDefaultBarThickness(1, 2);
setPlotType(PLOTTYPE_LINE, 0);
setPlotType(PLOTTYPE_LINE, 1);
setPlotType(PLOTTYPE_LINE, 2);
//}}EFSWizard_PreMain
}
function main() {
/**
* The main() function is called once per bar on all previous bars, once per
* each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
* in your preMain(), it is also called on every tick.
*/
//{{EFSWizard_Expressions
//{{EFSWizard_Expression_1
if (
vADXDM14_14.getValue(ADXDMStudy.PDI) > vADXDM14_14.getValue(ADXDMStudy.NDI) &&
vADXDM14_14.getValue(ADXDMStudy.PDI, -1) < vADXDM14_14.getValue(ADXDMStudy.NDI, -1) &&
vADXDM14_14.getValue(ADXDMStudy.PDI) >= vADXDM14_14.getValue(ADXDMStudy.ADX) &&
vADXDM14_14.getValue(ADXDMStudy.ADX) >= 18
) onAction1()
//}}EFSWizard_Expression_1
//{{EFSWizard_Expression_2
else if (
vADXDM14_14.getValue(ADXDMStudy.NDI) > vADXDM14_14.getValue(ADXDMStudy.PDI) &&
vADXDM14_14.getValue(ADXDMStudy.NDI, -1) < vADXDM14_14.getValue(ADXDMStudy.PDI, -1) &&
vADXDM14_14.getValue(ADXDMStudy.NDI) >= vADXDM14_14.getValue(ADXDMStudy.ADX) &&
vADXDM14_14.getValue(ADXDMStudy.ADX) >= 18
) onAction2();
//}}EFSWizard_Expression_2
//}}EFSWizard_Expressions
//{{EFSWizard_Return
return new Array(
vADXDM14_14.getValue(ADXDMStudy.ADX),
vADXDM14_14.getValue(ADXDMStudy.PDI),
vADXDM14_14.getValue(ADXDMStudy.NDI)
);
//}}EFSWizard_Return
}
function postMain() {
/**
* The postMain() function is called only once, when the EFS is no longer used for
* the current symbol (ie, symbol change, chart closing, or application shutdown).
*/
}
//{{EFSWizard_Actions
//{{EFSWizard_Action_1
function onAction1() {
drawShapeRelative(0, close(), Shape.UPARROW, "", Color.RGB(0,128,0), Shape.TOP);
vLastAlert = 1;
}
//}}EFSWizard_Action_1
//{{EFSWizard_Action_2
function onAction2() {
drawShapeAbsolute(0, close(), Shape.DOWNARROW, "", Color.RGB(255,0,0), Shape.TOP);
vLastAlert = 2;
}
//}}EFSWizard_Action_2
//}}EFSWizard_Actions
//{{EFSWizard_Description
//
// This formula was generated by the Alert Wizard
//
//}}EFSWizard_Description
//{{EFSWizard_Declarations
var vADXDM14_14 = new ADXDMStudy(14, 14);
var vLastAlert = -1;
//}}EFSWizard_Declarations
function preMain() {
/**
* This function is called only once, before any of the bars are loaded.
* Place any study or EFS configuration commands here.
*/
//{{EFSWizard_PreMain
setPriceStudy(false);
setStudyTitle("ADX Crossover");
setCursorLabelName("ADX", 0);
setCursorLabelName("PDI", 1);
setCursorLabelName("NDI", 2);
setDefaultBarStyle(PS_SOLID, 0);
setDefaultBarStyle(PS_SOLID, 1);
setDefaultBarStyle(PS_SOLID, 2);
setDefaultBarFgColor(Color.green, 0);
setDefaultBarFgColor(Color.blue, 1);
setDefaultBarFgColor(Color.red, 2);
setDefaultBarThickness(2, 0);
setDefaultBarThickness(1, 1);
setDefaultBarThickness(1, 2);
setPlotType(PLOTTYPE_LINE, 0);
setPlotType(PLOTTYPE_LINE, 1);
setPlotType(PLOTTYPE_LINE, 2);
//}}EFSWizard_PreMain
}
function main() {
/**
* The main() function is called once per bar on all previous bars, once per
* each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
* in your preMain(), it is also called on every tick.
*/
//{{EFSWizard_Expressions
//{{EFSWizard_Expression_1
if (
vADXDM14_14.getValue(ADXDMStudy.PDI) > vADXDM14_14.getValue(ADXDMStudy.NDI) &&
vADXDM14_14.getValue(ADXDMStudy.PDI, -1) < vADXDM14_14.getValue(ADXDMStudy.NDI, -1) &&
vADXDM14_14.getValue(ADXDMStudy.PDI) >= vADXDM14_14.getValue(ADXDMStudy.ADX) &&
vADXDM14_14.getValue(ADXDMStudy.ADX) >= 18
) onAction1()
//}}EFSWizard_Expression_1
//{{EFSWizard_Expression_2
else if (
vADXDM14_14.getValue(ADXDMStudy.NDI) > vADXDM14_14.getValue(ADXDMStudy.PDI) &&
vADXDM14_14.getValue(ADXDMStudy.NDI, -1) < vADXDM14_14.getValue(ADXDMStudy.PDI, -1) &&
vADXDM14_14.getValue(ADXDMStudy.NDI) >= vADXDM14_14.getValue(ADXDMStudy.ADX) &&
vADXDM14_14.getValue(ADXDMStudy.ADX) >= 18
) onAction2();
//}}EFSWizard_Expression_2
//}}EFSWizard_Expressions
//{{EFSWizard_Return
return new Array(
vADXDM14_14.getValue(ADXDMStudy.ADX),
vADXDM14_14.getValue(ADXDMStudy.PDI),
vADXDM14_14.getValue(ADXDMStudy.NDI)
);
//}}EFSWizard_Return
}
function postMain() {
/**
* The postMain() function is called only once, when the EFS is no longer used for
* the current symbol (ie, symbol change, chart closing, or application shutdown).
*/
}
//{{EFSWizard_Actions
//{{EFSWizard_Action_1
function onAction1() {
drawShapeRelative(0, close(), Shape.UPARROW, "", Color.RGB(0,128,0), Shape.TOP);
vLastAlert = 1;
}
//}}EFSWizard_Action_1
//{{EFSWizard_Action_2
function onAction2() {
drawShapeAbsolute(0, close(), Shape.DOWNARROW, "", Color.RGB(255,0,0), Shape.TOP);
vLastAlert = 2;
}
//}}EFSWizard_Action_2
//}}EFSWizard_Actions
Comment