File Name: AI_SysDev.efs
Description:
Artificial Intelligence For System Development by Domenico D'Errico & Giovanni Trombetta
Formula Parameters:
AI_SysDev.efs
Enter Gap: -0.08
Bars To Exit: 8
Bars To Exit Gain: 6
Notes:
The related article is copyrighted material. If you are not a subscriber
of Stocks & Commodities, please visit www.traders.com.
Download File:
AI_SysDev.efs
AI_SysDev.efs
EFS Code:
Description:
Artificial Intelligence For System Development by Domenico D'Errico & Giovanni Trombetta
Formula Parameters:
AI_SysDev.efs
Enter Gap: -0.08
Bars To Exit: 8
Bars To Exit Gain: 6
Notes:
The related article is copyrighted material. If you are not a subscriber
of Stocks & Commodities, please visit www.traders.com.
Download File:
AI_SysDev.efs
AI_SysDev.efs
EFS Code:
PHP Code:
/*********************************
Provided By:
eSignal (Copyright c eSignal), a division of Interactive Data
Corporation. 2016. All rights reserved. This sample eSignal
Formula Script (EFS) is for educational purposes only and may be
modified and saved under a new file name. eSignal is not responsible
for the functionality once modified. eSignal reserves the right
to modify and overwrite this EFS file with each new release.
Description:
Artificial Intelligence For System Development by Domenico D'Errico & Giovanni Trombetta
Version: 1.00 06/14/2017
Formula Parameters: Default:
Enter Gap -0.08
Bars To Exit 8
Bars To Exit Gain 6
Notes:
The related article is copyrighted material. If you are not a subscriber
of Stocks & Commodities, please visit www.traders.com.
**********************************/
var fpArray = new Array();
function preMain(){
setPriceStudy(true);
setShowCursorLabel(false);
var x=0;
fpArray[x] = new FunctionParameter("gap", FunctionParameter.NUMBER);
with(fpArray[x++]){
setName("Enter Gap");
setDefault(-0.08);
}
fpArray[x] = new FunctionParameter("nBarsToExit", FunctionParameter.NUMBER);
with(fpArray[x++]){
setName("Bars To Exit");
setDefault(8);
setLowerLimit(1);
}
fpArray[x] = new FunctionParameter("nBarsToExitGain", FunctionParameter.NUMBER);
with(fpArray[x++]){
setName("Bars To Exit Gain");
setDefault(6);
setLowerLimit(1);
}
}
var bInit = false;
var bVersion = null;
var xClose = null;
var xOpen = null;
var xHigh = null;
var xLow = null;
var xAvgPrice = null;
var xMedPrice = null;
var xMedBodyPrice = null;
var nEntryBarN = 0;
var nEntryPrice = 0;
var positiveEntry = false;
var positiveExit = false;
function main(gap, nBarsToExit, nBarsToExitGain){
if (bVersion == null) bVersion = verify();
if (bVersion == false) return;
if (getBarState() == BARSTATE_ALLBARS){
bInit = false;
}
if (!bInit){
xOpen = open();
xClose = close();
xHigh = high();
xLow = low();
xAvgPrice = ohlc4();
xMedPrice = hl2();
xMedBodyPrice = oc2();
nEntryBarN = 0;
nEntryPrice = 0;
positiveEntry = false;
positiveExit = false;
bInit = true;
}
if (getCurrentBarIndex() != 0){
if ((xAvgPrice.getValue(-2) < xMedPrice.getValue(-2)
&& xMedPrice.getValue(-3) <= xAvgPrice.getValue(-2)
&& xMedBodyPrice.getValue(-3) <= xAvgPrice.getValue(-4))
|| (xAvgPrice.getValue(-2) < xMedPrice.getValue(-4)
&& xMedBodyPrice.getValue(-1) < xMedPrice.getValue(-3)
&& xMedBodyPrice.getValue(-2) < xMedBodyPrice.getValue(-3))){
positiveEntry = true;
if (nEntryPrice != 0) nEntryPrice = 0;
}
else {
positiveEntry = false;
nEntryPrice = 0;
}
if ((xAvgPrice.getValue(-2) < xMedBodyPrice.getValue(-2)
&& xMedPrice.getValue(-3) == xMedBodyPrice.getValue(-4)
&& xMedBodyPrice.getValue(-2) <= xMedBodyPrice.getValue(-5))
|| (xAvgPrice.getValue(-3) < xMedBodyPrice.getValue(-1)
&& xMedPrice.getValue(-5) <= xAvgPrice.getValue(-4)
&& xMedBodyPrice.getValue(-2) <= xAvgPrice.getValue(-2))
|| (xAvgPrice.getValue(-3) < xMedBodyPrice.getValue(-1)
&& xMedPrice.getValue(-5) <= xAvgPrice.getValue(-4)
&& xMedBodyPrice.getValue(-2) <= xAvgPrice.getValue(-2))){
positiveExit = true;
}
else positiveExit = false;
if (!Strategy.isInTrade() && positiveEntry){
if (nEntryPrice == 0) nEntryPrice = xLow.getValue(-1) + gap;
if (xHigh.getValue(0) >= nEntryPrice && nEntryPrice >= xLow.getValue(0)){
nEntryPrice = Math.min(xOpen.getValue(0), nEntryPrice);
Strategy.doLong("eL_L", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, nEntryPrice);
nEntryBarN = getCurrentBarCount();
positiveEntry = false;
}
}
else{
var nBarsSinceEntry = getCurrentBarCount() - nEntryBarN;
if (nBarsSinceEntry != nBarsToExit-1 && positiveExit && ((xClose.getValue(0) - nEntryPrice) < 0))
Strategy.doSell("P_L_exit_L", Strategy.MARKET, Strategy.THISBAR, Strategy.DEFAULT);
else if (nBarsSinceEntry >= nBarsToExit -1)
Strategy.doSell("T_exit_L", Strategy.MARKET, Strategy.THISBAR, Strategy.DEFAULT);
else if (nBarsSinceEntry >= nBarsToExitGain - 1 && ((xClose.getValue(0) - nEntryPrice) > 0))
Strategy.doSell("TimeExitGain_L", Strategy.MARKET, Strategy.THISBAR, Strategy.DEFAULT);
if (!Strategy.isInTrade()){
nEntryBarN = 0;
positiveExit = false;
}
}
}
if (Strategy.isInTrade()) setBarBgColor(Color.RGB(0,60,0));
}
function verify(){
var b = false;
if (getBuildNumber() < 3742){
drawTextAbsolute(5, 35, "This study requires version 12.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;
}