I wrote these indicators for eSignal back in 2006 to trade the
ACD system. Feel free to translate to other languages:
/***
This formula will display the high/low lines of the
opening range and
the A & C lines for the day based on the book "The Logical Trader".
***/
function preMain() {
setPriceStudy(true);
setStudyTitle("ACD System");
setCursorLabelName("30m H", 0);
setCursorLabelName("30m L", 1);
setCursorLabelName("C Up ", 2);
setCursorLabelName("A Up ", 3);
setCursorLabelName("A Down", 4);
setCursorLabelName("C Down", 5);
setDefaultBarFgColor(Color.blue, 0);
setDefaultBarFgColor(Color.blue, 1);
setDefaultBarFgColor(Color.green, 2);
setDefaultBarFgColor(Color.green, 3);
setDefaultBarFgColor(Color.red, 4);
setDefaultBarFgColor(Color.red, 5);
setDefaultBarThickness(1, 0);
setDefaultBarThickness(1, 1);
setDefaultBarThickness(1, 2);
setDefaultBarThickness(1, 3);
setDefaultBarThickness(1, 4);
setDefaultBarThickness(1, 5);
setPlotType(PLOTTYPE_FLATLINES, 0);
setPlotType(PLOTTYPE_FLATLINES, 1);
setPlotType(PLOTTYPE_FLATLINES, 2);
setPlotType(PLOTTYPE_FLATLINES, 3);
setPlotType(PLOTTYPE_FLATLINES, 4);
setPlotType(PLOTTYPE_FLATLINES, 5);
var fp1 = new FunctionParameter("nMin", FunctionParameter.NUMBER);
fp1.setName("Number of Minutes");
fp1.setLowerLimit(1);
fp1.setDefault(60);
var fp2 = new FunctionParameter("nThickness", FunctionParameter.NUMBER);
fp2.setName("Line Thickness");
fp2.setLowerLimit(1);
fp2.setDefault(1);
var fp3 = new FunctionParameter("cColorH", FunctionParameter.COLOR);
fp3.setName("High Color");
fp3.setDefault(Color.RGB(0,0,192));
var fp4 = new FunctionParameter("cColorL", FunctionParameter.COLOR);
fp4.setName("Low Color");
fp4.setDefault(Color.RGB(0,0,192));
var fp5 = new FunctionParameter("nTicksA", FunctionParameter.NUMBER);
fp5.setName("Ticks for A");
fp5.setLowerLimit(.01);
fp5.setDefault(1)
var fp6 = new FunctionParameter("nTicksC", FunctionParameter.NUMBER);
fp6.setName("Ticks for C");
fp6.setLowerLimit(.01);
fp6.setDefault(1)
var fp7 = new FunctionParameter("cColorCUp", FunctionParameter.COLOR);
fp7.setName("C Up Color");
fp7.setDefault(Color.RGB(0,133,0));
var fp8 = new FunctionParameter("cColorAUp", FunctionParameter.COLOR);
fp8.setName("A Up Color");
fp8.setDefault(Color.RGB(0,133,0));
var fp9 = new FunctionParameter("cColorADown", FunctionParameter.COLOR);
fp9.setName("A Down Color");
fp9.setDefault(Color.RGB(192,0,0));
var fp10 = new FunctionParameter("cColorCDown", FunctionParameter.COLOR);
fp10.setName("C Down Color");
fp10.setDefault(Color.RGB(192,0,0));
}
var bEdit = true;
var bActive = true;
var nDayCntr = 0;
var vStartTime = null;
var vHigh = null;
var vLow = null;
var FirstBar = null;
function main(nMin, nThickness, cColorH, cColorL, cColorCUp, cColorAUp, cColorADown, cColorCDown, nTicksA, nTicksC) {
if (nMin == null) nMin = 60;
if (bEdit == true) {
nMin = Math.round(nMin);
setCursorLabelName(nMin + "min H", 0);
setCursorLabelName(nMin + "min L", 1);
setDefaultBarThickness(nThickness, 0);
setDefaultBarThickness(nThickness, 0);
setDefaultBarFgColor(cColorH, 0);
setDefaultBarFgColor(cColorL, 1);
setDefaultBarFgColor(cColorCUp, 2);
setDefaultBarFgColor(cColorAUp, 3);
setDefaultBarFgColor(cColorADown, 4);
setDefaultBarFgColor(cColorCDown, 5);
bEdit = false;
}
if (getDay() != getDay(-1) || vHigh == null || vLow == null) {
bActive = true;
nDayCntr += 1;
vStartTime = getValue("Time");
vHigh = high();
vLow = low();
}
FirstBar = getFirstBarIndexOfDay(vStartTime);
var vTime = getValue("Time");
// 3,600,000 milliseconds = 1 hour
// 60,000 milliseconds = 1 minute
if ((vTime - vStartTime)/60000 < nMin) {
vHigh = Math.max(high(), vHigh);
vLow = Math.min(low(), vLow);
} else {
bActive = false;
}
if (FirstBar != null) {
drawLineRelative( FirstBar, vHigh, 1, vHigh, PS_DASHDOT, nThickness,cColorH, "Hline");
drawTextRelative( 2, vHigh, vHigh.toFixed(2), cColorH, null, Text.VCENTER|Text.BOLD, null, 11, "High");
drawLineRelative( FirstBar, vHigh+nTicksC, 1,vHigh+nTicksC, PS_DOT, nThickness, cColorCUp, "CUp");
drawTextRelative( 2, vHigh+nTicksC, (vHigh+nTicksC).toFixed(2), cColorCUp, null, Text.VCENTER|Text.BOLD, null, 11, "CUp");
drawLineRelative( FirstBar, vHigh+nTicksA, 1,vHigh+nTicksA, PS_DASH, nThickness, cColorAUp, "AUp");
drawTextRelative( 2, vHigh+nTicksA, (vHigh+nTicksA).toFixed(2), cColorAUp, null, Text.VCENTER|Text.BOLD, null, 11, "AUp");
drawLineRelative( FirstBar, vLow, 1, vLow, PS_DASHDOT, nThickness, cColorL, "Lline")
drawTextRelative( 2, vLow, vLow.toFixed(2), cColorL, null, Text.VCENTER|Text.BOLD, null, 11, "Low");
drawLineRelative( FirstBar, vLow-nTicksA, 1,vLow-nTicksA, PS_DASH, nThickness, cColorADown, "ADown");
drawTextRelative( 2, vLow-nTicksA, (vLow-nTicksA).toFixed(2), cColorADown, null, Text.VCENTER|Text.BOLD, null, 11, "ADown");
drawLineRelative( FirstBar, vLow-nTicksC, 1,vLow-nTicksC, PS_DOT, nThickness, cColorCDown, "CDown");
drawTextRelative( 2, vLow-nTicksC, (vLow-nTicksC).toFixed(2), cColorCDown, null, Text.VCENTER|Text.BOLD, null, 11, "CDown");
}
if (bActive == false) {
return new Array(vHigh.toFixed(2), vLow.toFixed(2),(vHigh+nTicksC).toFixed(2),(vHigh+nTicksA).toFixed(2),
(vLow-nTicksA).toFixed(2),(vLow-nTicksC).toFixed(2));
}
return null;
}
/****************************************************************************************************
This study generates the
Pivot Range from the book "The Logical Trader"
****************************************************************************************************/
function preMain() {
setPriceStudy(true);
setStudyTitle("ACD Pivot
Range");
setCursorLabelName("PR1", 0);
setCursorLabelName("PR2", 1);
//
Pivot Range 1
setDefaultBarStyle(PS_SOLID, 0);
setDefaultBarFgColor(Color.RGB(40,40,40), 0);
setDefaultBarThickness(1, 0);
// Pivot Range 2
setDefaultBarStyle(PS_SOLID, 1);
setDefaultBarFgColor(Color.RGB(40,40,40), 1);
setDefaultBarThickness(1, 1);
}
// Start of Performance addition
var vLastRawTime = null;
var vLastPR1 = null;
var vLastPR2 = null;
var vLastArray = null;
var vSymbol = null;
var vInterval = null;
var vReset = true;
var vDisplayDate = null;
var bDisplay = false;
function main(nDays) {
if (vDisplayDate == null) {
if (nDays == null) nDays = 5;
var msPerDay = (24 * 60 * 60 * 1000);
vDisplayDate = new Date() *1;
vDisplayDate = vDisplayDate - ((nDays+2)*msPerDay);
vDisplayDate = new Date(vDisplayDate);
}
if (bDisplay == false && getDay(0) != getDay(-1)) {
var vDate = getValue("Time");
vDate = new Date(vDate);
if (vDate >= vDisplayDate) {
bDisplay = true;
}
}
if (bDisplay == false) return;
var vH;
var vL;
var vC;
var vRawTime;
var vBarTime;
var vIndex;
var nState = getBarState();
if(vReset == true) {
vLastRawTime = null;
vLastArray = null;
vLastPR1 = null;
vLastPR2 = null;
vInterval = getInterval();
vSymbol = getSymbol();
vSymbol += ",D";
vReset = false;
}
//vRawTime = getValue("rawtime"); // does not work properly with 1 min interval
vRawTime = getDay();
if(vRawTime == null)
return;
//vRawTime = Math.floor(vRawTime / RawTime.DAY);
// Start of Performance addition
if(vRawTime != null && vLastRawTime != null) {
if(vRawTime == vLastRawTime) {
return vLastArray;
// return new Array(vLastPR1, vLastPR2);
}
}
if(vInterval == null)
return null;
if(vInterval == "D")
return null;
if(vInterval == "W")
return null;
if(vInterval == "M")
return null;
if(vInterval == "T")
return null;
vBarTime = getValue("time");
if(vBarTime != null) {
var vDay = vBarTime.getDay();
if (vDay == 0) {
var vDate = vBarTime.getDate();
vDate -= 2;
vBarTime.setDate(vDate);
}
vAbsTime = getPreviousTradingDay(vBarTime, vSymbol);
if(vAbsTime == null) {
return;
}
vIndex = getFirstBarIndexOfDay(vAbsTime, vSymbol);
if(vIndex != null) {
vH = getValueAbsolute("High", vIndex, vSymbol);
vL = getValueAbsolute("Low", vIndex, vSymbol);
vC = getValueAbsolute("Close", vIndex, vSymbol);
if(vH != null && vL != null && vC != null) {
vLastPR1 = ((vH+vL+vC)/3)+(((vH+vL+ vC)/3)-((vH+vL)/2))
vLastPR2 = ((vH+vL+vC)/3)-(((vH+vL+ vC)/3)-((vH+vL)/2))
vLastRawTime = vRawTime;
vLastArray = new Array(vLastPR1, vLastPR2);
drawLineAbsolute(0,vLastPR1,1,vLastPR1,PS_SOLID,1,Color.RGB(40,40,40),10);
drawTextAbsolute( 9, vLastPR1, vLastPR1.toFixed(2), Color.RGB(40,40,40), null, Text.VCENTER|Text.BOLD, null, 11, "PR1");
drawLineAbsolute(0,vLastPR2,1,vLastPR2,PS_SOLID,1,Color.RGB(40,40,40),20);
drawTextAbsolute( 9, vLastPR2, vLastPR2.toFixed(2), Color.RGB(40,40,40), null, Text.VCENTER|Text.BOLD, null, 11, "PR2");
return vLastArray;
}
}
}
return null;
}
//{{EFSWizard_Description
//
// This formula generates the Pivot Moving Averages described in the book "The Logical Trader".
//
//}}EFSWizard_Description
//{{EFSWizard_Declarations
var vSMA14_of_HLC3 = new MAStudy(14, 1, "HLC/3", MAStudy.SIMPLE);
var vSMA30_of_HLC3 = new MAStudy(30, 1, "HLC/3", MAStudy.SIMPLE);
var vSMA50_of_HLC3 = new MAStudy(50, 1, "HLC/3", MAStudy.SIMPLE);
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(true);
setStudyTitle("ACD Pivot Moving Averages");
setCursorLabelName("14PMA", 0);
setCursorLabelName("30PMA", 1);
setCursorLabelName("50PMA", 2);
setDefaultBarStyle(PS_SOLID, 0);
setDefaultBarStyle(PS_SOLID, 1);
setDefaultBarStyle(PS_SOLID, 2);
setDefaultBarFgColor(Color.RGB(255,215,0), 0);
setDefaultBarFgColor(Color.RGB(0,0,255), 1);
setDefaultBarFgColor(Color.RGB(255,0,0), 2);
setDefaultBarThickness(1, 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
//}}EFSWizard_Expression_1
//}}EFSWizard_Expressions
//{{EFSWizard_Return
return new Array(
vSMA14_of_HLC3.getValue(MAStudy.MA),
vSMA30_of_HLC3.getValue(MAStudy.MA),
vSMA50_of_HLC3.getValue(MAStudy.MA)
);
//}}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() {
vLastAlert = 1;
}
//}}EFSWizard_Action_1
//}}EFSWizard_Actions