File Name: BrownianMotion.efs, TradingSystem.efs, Fortune.efs, WinLossRatio.efs
Description:
This study is based on the June 2006 article, Harnessing The (Mis)Behavior Of Markets, by Rick Martinelli.
Formula Parameters:
BrownianMotion.efs
Standard Deviation Periods: 7
Mean Periods: 21
TradingSystem.efs
Alpha Cutoff: 1
Fortune.efs
Account Value: 10000
WinLossRatio.efs
Alpha Cutoff: 1
Notes:
The Trading System and Win/Loss Ratio studies have one parameter to set the Alpha Cutoff value, which is set to a default of 1. The author performed an optimization routine in Excel to find an optimized value for this cutoff. That functionality does not currently exist in EFS, therefore the cutoff value will need to me manually adjusted. This formula requires eSignal version 7.9.1 or later. The related article is copyrighted material. If you are not a subscriber of Stocks & Commodities, please visit www.traders.com.
Download File:
BrownianMotion.efs
TradingSystem.efs
Fortune.efs
WinLossRatio.efs
EFS Code:
Description:
This study is based on the June 2006 article, Harnessing The (Mis)Behavior Of Markets, by Rick Martinelli.
Formula Parameters:
BrownianMotion.efs
Standard Deviation Periods: 7
Mean Periods: 21
TradingSystem.efs
Alpha Cutoff: 1
Fortune.efs
Account Value: 10000
WinLossRatio.efs
Alpha Cutoff: 1
Notes:
The Trading System and Win/Loss Ratio studies have one parameter to set the Alpha Cutoff value, which is set to a default of 1. The author performed an optimization routine in Excel to find an optimized value for this cutoff. That functionality does not currently exist in EFS, therefore the cutoff value will need to me manually adjusted. This formula requires eSignal version 7.9.1 or later. The related article is copyrighted material. If you are not a subscriber of Stocks & Commodities, please visit www.traders.com.
Download File:
BrownianMotion.efs
TradingSystem.efs
Fortune.efs
WinLossRatio.efs
EFS Code:
PHP Code:
/***************************************
Provided By : eSignal (c) Copyright 2006
Description: Harnessing The (Mis)Behavior Of Markets
by Rick Martinelli
Version 1.0 04/06/2006
Notes:
* June 2006 Issue of Stocks and Commodities Magazine
* Study requires version 7.9.1 or higher.
Formula Parameters: Defaults:
Standard Deviation Periods 7
Mean Periods 21
***************************************/
function preMain() {
setStudyTitle("Brownian Motion ");
setCursorLabelName("Normalized W", 0);
setCursorLabelName("White Noise", 1);
setDefaultBarThickness(4, 0);
setDefaultBarThickness(2, 1);
setDefaultBarFgColor(Color.navy, 0);
setDefaultBarFgColor(Color.red, 1);
setPlotType(PLOTTYPE_HISTOGRAM, 0);
setPlotType(PLOTTYPE_HISTOGRAM, 1);
addBand(8, PS_SOLID, 2, Color.maroon, 8);
addBand(6, PS_SOLID, 2, Color.maroon, 6);
addBand(4, PS_SOLID, 2, Color.maroon, 4);
addBand(2, PS_SOLID, 2, Color.maroon, 2);
addBand(0, PS_SOLID, 2, Color.maroon, 0);
addBand(-2, PS_SOLID, 2, Color.maroon, -2);
addBand(-4, PS_SOLID, 2, Color.maroon, -4);
addBand(-6, PS_SOLID, 2, Color.maroon, -6);
addBand(-8, PS_SOLID, 2, Color.maroon, -8);
var fp1 = new FunctionParameter("nStdev", FunctionParameter.NUMBER);
fp1.setName("Standard Deviation Periods");
fp1.setLowerLimit(1);
fp1.setDefault(7);
var fp2 = new FunctionParameter("nMean", FunctionParameter.NUMBER);
fp2.setName("Mean Periods");
fp2.setLowerLimit(1);
fp2.setDefault(21);
}
var bVersion = null;
var bInit = false;
var xW = null;
var xW_mean = null;
var xW_stdev = null;
function main(nStdev, nMean) {
if (bVersion == null) bVersion = verify();
if (bVersion == false) return;
if (getCurrentBarCount() <= Math.max(nStdev, nMean)) return null;
if (bInit == false) {
xW = efsInternal("calcW");
xW_mean = sma(nMean, xW);
xW_stdev = efsInternal("calcStdev", xW, nStdev);
bInit = true;
}
var nNormP = xW.getValue(0);
var nWhiteNoise = (xW.getValue(0) - xW_mean.getValue(0)) / xW_stdev.getValue(0);
return new Array(nNormP, nWhiteNoise);
}
function calcW() {
return (close(0) - close(-1));
}
function calcStdev(xSrc, n) {
var sumX = 0;
var sumX2 = 0;
if (xSrc.getValue(-n) == null) return;
for (i = 0; i < n; ++i) {
sumX += xSrc.getValue(-i);
sumX2 += (xSrc.getValue(-i) * xSrc.getValue(-i))
}
var meanX = (sumX/n);
var stdev = Math.sqrt((sumX2/n) - (meanX*meanX));
return stdev;
}
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;
}
PHP Code:
/***************************************
Provided By : eSignal (c) Copyright 2006
Description: Harnessing The (Mis)Behavior Of Markets
by Rick Martinelli
Version 1.0 04/06/2006
Notes:
* June 2006 Issue of Stocks and Commodities Magazine
* Study requires version 7.9.1 or higher.
Formula Parameters: Defaults:
Alpha Cutoff 1
***************************************/
function preMain() {
setStudyTitle("Trading System ");
setCursorLabelName("Fortune", 0);
setDefaultBarThickness(2, 0);
setDefaultBarFgColor(Color.navy, 0);
var fp1 = new FunctionParameter("nCutoff", FunctionParameter.NUMBER);
fp1.setName("Alpha Cutoff");
fp1.setLowerLimit(0);
fp1.setDefault(1);
}
var bVersion = null;
var bInit = false;
var xW = null;
var xSigma = null;
var xDeltaP = null;
var xAlpha = null;
var xA_factor = null;
var nSum = 0;
function main(nCutoff) {
if (bVersion == null) bVersion = verify();
if (bVersion == false) return;
if (bInit == false) {
xW = efsInternal("calcW");
xDeltaP = efsInternal("calcDeltaP", xW);
xSigma = efsInternal("calcStdev", xW, 7);
xAlpha = efsInternal("calcAlpha", xDeltaP, xSigma);
xA_factor = efsInternal("calcA_factor", xAlpha, nCutoff);
addBand(0, PS_SOLID, 2, Color.magenta, 0);
bInit = true;
}
var nState = getBarState();
var nP_1 = close(-1);
var nFortune = 0;
var nA_factor_1 = xA_factor.getValue(-1);
var nA_factor_2 = xA_factor.getValue(-2);
if (nP_1 == null || nA_factor_2 == null ||
xSigma.getValue(0) == null || xAlpha.getValue(0) == null) return 0;
if (nState == BARSTATE_NEWBAR) {
nSum += (nA_factor_2 * xW.getValue(-1));
}
if (nSum != 0) {
nFortune = ((nSum + (nA_factor_1 * xW.getValue(0))) / nP_1);
}
return nFortune;
}
function calcW() {
return (close(0) - close(-1));
}
function calcStdev(xSrc, n) {
var sumX = 0;
var sumX2 = 0;
if (xSrc.getValue(-n) == null) return;
for (i = 0; i < n; ++i) {
sumX += xSrc.getValue(-i);
sumX2 += (xSrc.getValue(-i) * xSrc.getValue(-i))
}
var meanX = (sumX/n);
var stdev = Math.sqrt((sumX2/n) - (meanX*meanX));
return stdev;
}
function calcDeltaP(xSrc) {
return ((xSrc.getValue(0) + xSrc.getValue(-1)) + sma(3, 0)) - close(0);
}
function calcAlpha(xSrc1, xSrc2) {
return xSrc1.getValue(0) / xSrc2.getValue(0);
}
function calcA_factor(xSrc, C) {
var nA = 0;
if (xSrc.getValue(0) > C) nA = 1;
else if (xSrc.getValue(0) < -C) nA = -1;
return nA;
}
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;
}
PHP Code:
/***************************************
Provided By : eSignal (c) Copyright 2006
Description: Harnessing The (Mis)Behavior Of Markets
by Rick Martinelli
Version 1.0 04/06/2006
Notes:
* June 2006 Issue of Stocks and Commodities Magazine
* Study requires version 7.9.1 or higher.
Formula Parameters: Defaults:
Account Value 10000
***************************************/
function preMain() {
setStudyTitle("Fortune Indicator ");
setCursorLabelName("Fortune", 0);
setDefaultBarThickness(2, 0);
setDefaultBarFgColor(Color.navy, 0);
var fp1 = new FunctionParameter("nDollars", FunctionParameter.NUMBER);
fp1.setName("Account Value");
fp1.setLowerLimit(0);
fp1.setDefault(10000);
}
var bVersion = null;
var bInit = false;
var xW = null;
var nSum = 0;
var nCntr = 1;
function main(nDollars) {
if (bVersion == null) bVersion = verify();
if (bVersion == false) return;
if (bInit == false) {
xW = efsInternal("calcW");
addBand(0, PS_SOLID, 2, Color.magenta, 0);
bInit = true;
}
var nState = getBarState();
var nP_1 = close(-1);
var nFortune = 0;
if (nP_1 == null) return;
if (nState == BARSTATE_NEWBAR) {
nCntr++;
nSum += xW.getValue(-1);
}
if (nSum != 0) {
nFortune = ((nSum + xW.getValue(0)) / nP_1) * nDollars;
}
return nFortune;
}
function calcW() {
return (close(0) - close(-1));
}
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;
}
PHP Code:
/***************************************
Provided By : eSignal (c) Copyright 2006
Description: Harnessing The (Mis)Behavior Of Markets
by Rick Martinelli
Version 1.0 04/06/2006
Notes:
* June 2006 Issue of Stocks and Commodities Magazine
* Study requires version 7.9.1 or higher.
Formula Parameters: Defaults:
Alpha Cutoff 1
***************************************/
function preMain() {
setStudyTitle("Win/Loss Ratio ");
setCursorLabelName("W/L", 0);
setDefaultBarThickness(3, 0);
setDefaultBarFgColor(Color.navy, 0);
setPlotType(PLOTTYPE_HISTOGRAM, 0);
var fp1 = new FunctionParameter("nCutoff", FunctionParameter.NUMBER);
fp1.setName("Alpha Cutoff");
fp1.setLowerLimit(0);
fp1.setDefault(1);
}
var bVersion = null;
var bInit = false;
var xW = null;
var xSigma = null;
var xDeltaP = null;
var xAlpha = null;
function main(nCutoff) {
if (bVersion == null) bVersion = verify();
if (bVersion == false) return;
if (bInit == false) {
xW = efsInternal("calcW");
xSigma = efsInternal("calcStdev", xW, 7);
xDeltaP = efsInternal("calcDeltaP", xW);
xAlpha = efsInternal("calcAlpha", xDeltaP, xSigma);
addBand(0, PS_SOLID, 2, Color.magenta, 0);
bInit = true;
}
var nState = getBarState();
var nWL = 0;
if (xAlpha.getValue(-2) == null) return 0;
// Trading $ accumulation
if (nState == BARSTATE_NEWBAR) {
if (xAlpha.getValue(-2) > nCutoff) { // long signal
nWL = (close(-1) - close(-2)) / close(-2);
} else if (xAlpha.getValue(-2) < -nCutoff) { // short signal
nWL = (close(-2) - close(-1)) / close(-2);
}
}
return nWL;
}
function calcW() {
return (close(0) - close(-1));
}
function calcStdev(xSrc, n) {
var sumX = 0;
var sumX2 = 0;
if (xSrc.getValue(-n) == null) return;
for (i = 0; i < n; ++i) {
sumX += xSrc.getValue(-i);
sumX2 += (xSrc.getValue(-i) * xSrc.getValue(-i))
}
var meanX = (sumX/n);
var stdev = Math.sqrt((sumX2/n) - (meanX*meanX));
return stdev;
}
function calcDeltaP(xSrc) {
return ((xSrc.getValue(0) + xSrc.getValue(-1)) + sma(3, 0)) - close(0);
}
function calcAlpha(xSrc1, xSrc2) {
return xSrc1.getValue(0) / xSrc2.getValue(0);
}
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;
}