function preMain()
{
setPriceStudy(false);
setStudyTitle("Trade
Directional Trend Index");
setCursorLabelName("DTI_Trade", 0);
setCursorLabelName("DTI",
1);
setCursorLabelName("ZeroLine", 2);
setDefaultBarFgColor(Color.red, 0);
setDefaultBarFgColor(Color.blue, 1);
setDefaultBarFgColor(Color.green, 2);
setPlotType(PLOTTYPE_DOT,
0);
setDefaultBarThickness(3,
0);
setDefaultBarThickness(2,
1);
setDefaultBarThickness(2,
2);
}
var rXA = 0.0;
var sXA = 0.0;
var uXA = 0.0;
var rXAAbs = 0.0;
var sXAAbs = 0.0;
var uXAAbs = 0.0;
var Val3 = 0.0;
var lrXA = 0.0;
var lsXA = 0.0;
var luXA = 0.0;
var lrXAAbs = 0.0;
var lsXAAbs = 0.0;
var luXAAbs = 0.0;
var Val3_1 = 0.0;
function main(r, s, u, OB,
OS)
{
if (getBarState() ==
BARSTATE_NEWBAR)
{
lrXA
= rXA;
lsXA
= sXA;
luXA
= uXA;
lrXAAbs = rXAAbs;
lsXAAbs = sXAAbs;
luXAAbs = uXAAbs;
Val3_1 = Val3;
}
if (r == null) r = 14;
if (s == null) s = 10;
if (u == null) u = 5;
if (OB == null) OB = 25;
if (OS == null) OS =
-25;
var rFactor = 2 / (r +
1);
var sFactor = 2 / (s +
1);
var uFactor = 2 / (u +
1);
var HMU = 0.0;
var LMD = 0.0;
var High = getValue("High",
0, -2);
var Low = getValue("Low", 0,
-2);
if ((High[0] - High[1]) >
0)
{
HMU
= High[0] - High[1];
}
else HMU = 0.0;
if ((Low[0] - Low[1]) <
0)
{
LMD
= -(Low[0] - Low[1]);
}
else LMD = 0.0;
var Price = HMU - LMD;
var PriceAbs =
Math.abs(Price);
rXA = rFactor * Price + (1 -
rFactor) * lrXA;
sXA = sFactor * rXA + (1 -
sFactor) * lsXA;
uXA = uFactor * sXA + (1 -
uFactor) * luXA;
rXAAbs = rFactor * PriceAbs
+ (1 - rFactor) * lrXAAbs;
sXAAbs = sFactor * rXAAbs +
(1 - sFactor) * lsXAAbs;
uXAAbs = uFactor * sXAAbs +
(1 - uFactor) * luXAAbs;
var Val1 = 100 * uXA;
var Val2 = uXAAbs;
var DTI = 0.0;
if (Val2 != 0) DTI = Val1 /
Val2;
else DTI = 0.0;
Val3 = DTI;
var Val4 = 0.0;
var Val5 = 0.0;
if (((Val3 - Val3_1) >
0)&&(Val3 > 0)) Val4 = Val3;
else Val4 = 0.0;
if (((Val3 - Val3_1) <
0)&&(Val3 < 0)) Val5 = Val3;
else Val5 = 0.0;
var DTI_Trade = Val4 +
Val5;
return new Array(DTI_Trade,
DTI, 0);
}