File Name: HACOLT.efs
Description:
Long-Term Trading Using Exchange Traded Funds by Sylvain Vervoort
Formula Parameters:
HACOLT.efs
TEMA Average: 55
Shorting LT Average: 60
Candle Size Factor: 1.1
Notes:
The related article is copyrighted material. If you are not a subscriber
of Stocks & Commodities, please visit www.traders.com.
Download File:
HACOLT.efs
HACOLT.efs
EFS Code:
Description:
Long-Term Trading Using Exchange Traded Funds by Sylvain Vervoort
Formula Parameters:
HACOLT.efs
TEMA Average: 55
Shorting LT Average: 60
Candle Size Factor: 1.1
Notes:
The related article is copyrighted material. If you are not a subscriber
of Stocks & Commodities, please visit www.traders.com.
Download File:
HACOLT.efs
HACOLT.efs
EFS Code:
PHP Code:
/*********************************
Provided By:
Interactive Data Corporation (Copyright © 2012)
All rights reserved. This sample eSignal Formula Script (EFS)
is for educational purposes only. Interactive Data Corporation
reserves the right to modify and overwrite this EFS file with
each new release.
Description:
Long-Term Trading Using Exchange Traded Funds by Sylvain Vervoort
Version: 1.0 14/05/2012
Formula Parameters: Default:
TEMA Average 55
Shorting LT Average 60
Candle Size Factor 1.1
Notes:
The related article is copyrighted material. If you are not
a subscriber of Stocks & Commodities, please visit [url]www.traders.com.[/url]
**********************************/
var fpArray = new Array();
function preMain() {
setPriceStudy(false);
setStudyTitle("Heikin-Ashi Candelstick Oscillator Long-Term");
var x = 0;
fpArray[x] = new FunctionParameter("g_nAvgPeriod", FunctionParameter.NUMBER);
with(fpArray[x++])
{
setName("TEMA Average");
setLowerLimit(1);
setUpperLimit(100);
setDefault(55);
}
fpArray[x] = new FunctionParameter("g_nLTAvgPeriod", FunctionParameter.NUMBER);
with(fpArray[x++])
{
setName("Shorting LT Average");
setLowerLimit(1);
setUpperLimit(200);
setDefault(60);
}
fpArray[x] = new FunctionParameter("g_nCandleSize", FunctionParameter.NUMBER);
with(fpArray[x++])
{
setName("Candle Size Factor");
setLowerLimit(0.01);
setUpperLimit(5);
setDefault(1.1);
}
}
var xhaOpen = null;
var xhaC = null;
var xTEMA1_haC = null;
var xTEMA2_haC = null;
var xTEMA1_hl2 = null;
var xTEMA2_hl2 = null;
var xEMA_LT = null;
var bKeeping = false;
var bKeepall = false;
var bKeeping_ref = false;
var bKeepall_ref = false;
var bKeeping_2 = false;
var bKeepall_2 = false;
var bKeeping_2_ref = false;
var bKeepall_2_ref = false;
var bDtr = false;
var bUtr = false;
var bDtr_ref = false;
var bUtr_ref = false;
var nValueWhen = 0;
var nLTRes = 0;
var nLTRes_ref = 0;
var nResult = 0;
var nResult_ref = 0;
var bInit = false;
var bVersion = null;
function main(g_nAvgPeriod, g_nLTAvgPeriod, g_nCandleSize)
{
if (bVersion == null) bVersion = verify();
if (bVersion == false) return;
var nState = getBarState();
if (!bInit)
{
xhaOpen = efsInternal("Calc_haOpen", ohlc4());
xhaC = efsInternal("Calc_haC", ohlc4(), xhaOpen);
xTEMA1_haC = efsInternal("TEMA", g_nAvgPeriod, xhaC);
xTEMA2_haC = efsInternal("TEMA", g_nAvgPeriod, xTEMA1_haC);
xTEMA1_hl2 = efsInternal("TEMA", g_nAvgPeriod, hl2());
xTEMA2_hl2 = efsInternal("TEMA", g_nAvgPeriod, xTEMA1_hl2);
xEMA_LT = ema(g_nLTAvgPeriod, close());
bInit = true;
}
if (nState == BARSTATE_NEWBAR)
{
bKeeping_ref = bKeeping;
bKeepall_ref = bKeepall;
bKeeping_2_ref = bKeeping_2;
bKeepall_2_ref = bKeepall_2;
bDtr_ref = bDtr;
bUtr_ref = bUtr;
nLTRes_ref = nLTRes;
nResult_ref = nResult
}
else if (nState == BARSTATE_ALLBARS)
{
bKeeping_ref = bKeeping = false;
bKeepall_ref = bKeepall = false;
bKeeping_2_ref = bKeeping_2 = false;
bKeepall_2_ref = bKeepall_2 = false;
bDtr_ref = bDtr = false;
bUtr_ref = bUtr = false;
nValueWhen = 0;
nLTRes_ref = nLTRes = 0;
nResult_ref = nResult = 0;
}
var nhaOpen = xhaOpen.getValue(0);
var nhaC = xhaC.getValue(0);
var nTEMA1_haC = xTEMA1_haC.getValue(0);
var nTEMA2_haC = xTEMA2_haC.getValue(0);
var nTEMA1_hl2 = xTEMA1_hl2.getValue(0);
var nTEMA2_hl2 = xTEMA2_hl2.getValue(0);
var nEMA_LT = xEMA_LT.getValue(0);
if (nTEMA2_haC == null || nTEMA2_hl2 == null || nEMA_LT == null)
return;
var nZIHa = nTEMA1_haC + (nTEMA1_haC - nTEMA2_haC);
var nZICl = nTEMA1_hl2 + (nTEMA1_hl2 - nTEMA2_hl2);
// bKeep1 section
var fExpression1 = function(i)
{
if (xhaC.getValue(-i) == null || xhaOpen.getValue(-i) == null)
return false;
return xhaC.getValue(-i) >= xhaOpen.getValue(-i);
}
var bExp1 = Alert(fExpression1, 2);
var bExp2 = close(0) >= nhaC;
var bExp3 = high(0) > high(-1);
var bExp4 = low(0) > low(-1);
var bKeep1 = bExp1 || bExp2 || bExp3 || bExp4;
// end of bKeep1 section
var bKeep2 = (nZICl - nZIHa) >= 0;
var bKeep3 = (Math.abs(close(0) - open(0)) < (high(0) - low(0)) * g_nCandleSize) && (high(0) >= low(-1));
bKeeping = bKeep1 || bKeep2;
bKeepall = bKeeping || (bKeeping_ref && (close(0) >= 0) || (close(0) >= close(-1)));
bUtr = bKeepall || (bKeepall_ref && bKeep3);
// bKeep1_2 section
var fExpression2 = function(i)
{
if (xhaC.getValue(-i) == null || xhaOpen.getValue(-i) == null)
return false;
return xhaC.getValue(-i) < xhaOpen.getValue(-i);
}
var bKeep1_2 = Alert(fExpression2, 2);
// end of bKeep1_2 section
var bKeep2_2 = (nZICl - nZIHa) < 0;
var bKeep3_2 = (Math.abs(close(0) - open(0)) < (high(0) - low(0)) * g_nCandleSize) && (low(0) <= high(-1));
bKeeping_2 = bKeep1_2 || bKeep2_2;
bKeepall_2 = bKeeping_2 || (bKeeping_2_ref && (close(0) < open(0)) || (close(0) < close(-1)));
bDtr = bKeepall_2 || (bKeepall_2_ref && bKeep3_2);
bUpw = (!bDtr && bDtr_ref && bUtr);
bDnw = (!bUtr && bUtr_ref && bDtr);
nRes = bUpw ? 1 : (bDnw ? 0 : nValueWhen);
if (bUpw || bDnw)
{
if (bUpw)
nValueWhen = 1;
else
nValueWhen = 0;
}
var bLTSell = (close(0) < nEMA_LT);
nLTRes = (nRes == 1) ? 1 : (bLTSell ? 0 : nLTRes_ref);
nResult = (nRes == 1) ? 100 : ((nLTRes == 1) ? 50 : 0);
BackTesting();
return nResult;
}
function BackTesting()
{
// Back Testing formulas are not for real time analysis.
// Therefore, prevent processing and exit at bar 0.
if (getCurrentBarIndex() == 0) return;
// Exit Strategy
if (Strategy.isInTrade())
{
// Exit Long
if (Strategy.isLong() && (nResult_ref == 100) && (nResult < 100))
{
Strategy.doSell("Long Exit Signal", Strategy.CLOSE, Strategy.THISBAR);
}
// Exit Short
else if (Strategy.isShort() && (nResult_ref < 100) && (nResult == 100))
{
Strategy.doCover("Short Exit Signal", Strategy.CLOSE, Strategy.THISBAR);
}
}
// Entry Strategy
if (!Strategy.isInTrade())
{
// Enter Long
if ((nResult_ref < 100) && (nResult == 100))
{
Strategy.doLong("Long signal", Strategy.CLOSE, Strategy.THISBAR);
}
// Enter Short
else if ((nResult_ref > 0) && (nResult == 0))
{
Strategy.doShort("Short signal", Strategy.CLOSE, Strategy.THISBAR);
}
}
}
function Calc_haOpen(xOHLC4)
{
var nRef = ref(-1);
var nOHLC1 = xOHLC4.getValue(-1);
if (nOHLC1 == null)
return;
if (nRef == null)
nRef = nOHLC1;
return (nOHLC1 + nRef) / 2;
}
function Calc_haC(xOHLC4, xhaOpen)
{
var nOHLC = xOHLC4.getValue(0);
var nhaOpen = xhaOpen.getValue(0);
if (nhaOpen == null)
return;
return (nOHLC + nhaOpen + Math.max(high(0), nhaOpen) + Math.min(low(0), nhaOpen)) / 4;
}
// MetaStock Alert function
function Alert(fExpression, nPeriod)
{
for (var i = 0; i < nPeriod; i++)
if(fExpression(i)) return true;
return false;
}
var bInitTEMA = false;
var xEma1 = null;
var xEma2 = null;
var xEma3 = null;
// Triple Exponential Moving Average
function TEMA(period, series)
{
if(!bInitTEMA)
{
xEma1 = ema(period, series);
xEma2 = ema(period, xEma1);
xEma3 = ema(period, xEma2);
bInitTEMA = true;
}
var vEma1 = xEma1.getValue(0);
var vEma2 = xEma2.getValue(0);
var vEma3 = xEma3.getValue(0);
if (vEma3 == null)
return null;
return 3 * vEma1 - 3 * vEma2 + vEma3;
}
// verify version
function verify() {
var b = false;
if (getBuildNumber() < 779) {
drawTextAbsolute(5, 35, "This study requires version 8.0 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;
}