File Name: APE.efs
Description:
These studies are based on the April 2006 article, The Average Peak Excursion, by Chris Young.
Formula Parameters:
APE.efs
n-Day Avg Peak Excursion: 20
APE_alpha.efs
n-Day Avg Peak Excursion: 20
Notes:
The APE.efs study plots the n-period APE, n-period Peaks and the 1-period APE series as a non-price study. The APE_alpha.efs study is also a non-price study that plots the APE alpha as described in the article. Please note that the APE_alpha.efs formula directly calls APE.efs to perform its calculations. Therefore, both formulas need to be saved to the same folder. The related article is copyrighted material. If you are not a subscriber of Stocks & Commodities, please visit www.traders.com.
Download File:
APE.efs
APE_alpha.efs
EFS Code:
APE.efs
APE_alpha.efs
Description:
These studies are based on the April 2006 article, The Average Peak Excursion, by Chris Young.
Formula Parameters:
APE.efs
n-Day Avg Peak Excursion: 20
APE_alpha.efs
n-Day Avg Peak Excursion: 20
Notes:
The APE.efs study plots the n-period APE, n-period Peaks and the 1-period APE series as a non-price study. The APE_alpha.efs study is also a non-price study that plots the APE alpha as described in the article. Please note that the APE_alpha.efs formula directly calls APE.efs to perform its calculations. Therefore, both formulas need to be saved to the same folder. The related article is copyrighted material. If you are not a subscriber of Stocks & Commodities, please visit www.traders.com.
Download File:
APE.efs
APE_alpha.efs
EFS Code:
APE.efs
PHP Code:
/***************************************
Provided By : eSignal (c) Copyright 2006
Description: The Average Peak Excursion - by Chris Young
Version 1.0 02/06/2006
Notes:
* Apr 2006 Issue of Stocks and Commodities Magazine
* Study requires version 7.9.1 or higher.
Formula Parameters: Defaults:
n-Day Avg Peak Excursion 20
***************************************/
function preMain() {
setStudyTitle("Average Peak Excursion");
setCursorLabelName("1-Day APE", 0);
setCursorLabelName("Peak", 1);
setCursorLabelName("APE", 2);
setDefaultBarThickness(2, 0);
setDefaultBarThickness(3, 1);
setDefaultBarThickness(2, 2);
setPlotType(PLOTTYPE_LINE, 0);
setPlotType(PLOTTYPE_HISTOGRAM, 1);
setDefaultBarFgColor(Color.navy, 0);
setDefaultBarFgColor(Color.red, 1);
setDefaultBarFgColor(Color.green, 2);
var fp1 = new FunctionParameter("nDayAPE", FunctionParameter.NUMBER);
fp1.setName("n-Day Avg Peak Excursion");
fp1.setLowerLimit(1);
fp1.setDefault(20);
}
var bVersion = null;
var bInit = false;
var xAPE = null; // APE series
var xAPEMA = null;
var xA0 = null; // 1-Day Peak series
function main(nDayAPE) {
if (bVersion == null) bVersion = verify();
if (bVersion == false) return;
if (bInit == false) {
xAPE = efsInternal("calcPeak", nDayAPE);
xAPEMA = sma(nDayAPE,xAPE);
xA0 = efsInternal("calcPeak", 1);
xA0MA = sma(nDayAPE,xA0);
setCursorLabelName(nDayAPE + "-Day Peak", 1);
setCursorLabelName(nDayAPE + "-Day APE", 2);
bInit = true;
}
return new Array(xA0MA.getValue(0), xAPE.getValue(0), xAPEMA.getValue(0));
}
var xHighest = null;
var xLowest = null;
function calcPeak(nDay) {
if(xHighest==null) xHighest = highest(nDay, high());
if(xLowest==null) xLowest = lowest(nDay, low());
var nO = open(-nDay+1);
if (nO == null) return null;
var nH = Math.abs((xHighest.getValue(0) - nO) / nO)*100;
var nL = Math.abs((xLowest.getValue(0) - nO) / nO)*100;
return Math.max(nH, nL);
}
function verify() {
var b = false;
if (getBuildNumber() < 730) {
drawTextAbsolute(5, 35, "This study requires version 7.9.1 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;
}
APE_alpha.efs
PHP Code:
/***************************************
Provided By : eSignal (c) Copyright 2006
Description: The Average Peak Excursion Alpha - by Chris Young
Version 1.0 02/06/2006
Notes:
* Apr 2006 Issue of Stocks and Commodities Magazine
* This study must reside in the same folder as APE.efs.
Or add the path information to APE.efs within the efsExternal()
functions if APE.efs is to be located in another folder.
* Study requires version 7.9.1 or higher.
Formula Parameters: Defaults:
n-Day Avg Peak Excursion 20
***************************************/
function preMain() {
setStudyTitle("Average Peak Excursion Alpha");
setCursorLabelName("APE Alpha", 0);
setDefaultBarThickness(2, 0);
var fp1 = new FunctionParameter("nDayAPE", FunctionParameter.NUMBER);
fp1.setName("n-Day Avg Peak Excursion");
fp1.setLowerLimit(1);
fp1.setDefault(20);
}
var bVersion = null;
var bInit = false;
var xAPE_n = null;
function main(nDayAPE) {
if (bVersion == null) bVersion = verify();
if (bVersion == false) return;
var nAlpha = null;
if (bInit == false) {
if (xAPE_n == null) xAPE_n = efsExternal("APE.efs", nDayAPE);
bInit = true;
}
var nAPE1 = getSeries(xAPE_n, 0);
var nAPEn = getSeries(xAPE_n, 2);
if (nAPEn == null || nAPE1 == null) return;
nAlpha = Math.log( (nAPEn/nAPE1) ) / Math.log(nDayAPE);
return nAlpha;
}
/***** Support Functions *****/
function verify() {
var b = false;
if (getBuildNumber() < 730) {
drawTextAbsolute(5, 35, "This study requires version 7.9.1 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;
}