PureBytes Links
Trading Reference Links
|
I did some additional testing of the T3 average I posted last Sunday.
(The MetaStock code for this average was published in the January issue of
Technical Analysis of Stocks & Commodities in the article "Smoothing
Techniques for More Accurate Signals", by Tim Tillson.)
I recoded the function for better efficiency and created both a "series"
version and a "simple" version. The "simple" version is coded to allow
dynamically varying the "Periods" input on a bar-by-bar basis, should this
be needed. I have included a demo indicator that shows this input being
modulated by volatility as an example of a possible usage.
The frequency response of the average as a low-pass filter is very good.
The cutoff frequency is approximately:
Cut off frequency (cycles/year) = 100 / "Periods"
if "Periods" is given in daily bars.
The frequency response drops quickly and is down by a factor of 100 at
about 7 times the cutoff frequency which is a pretty steep cutoff. The
response is very smooth for the small lag created.
Included below are the two functions, an indicator using the series
function, and a demo indicator illustrating the modulation of the "Periods"
input.
Bob Fulks
{ *******************************************************************
Function : T3Average.series
Last Edit : 12/16/97
Provided By : Bob Fulks
Description : This function is an EasyLanguage version of the
moving average described in the January. 1998 issue of TASC,
p57, "Smoothing Techniques for More Accurate Signals", by Tim
Tillson. It is translated from the MetaStock code presented
in the article and recoded for efficiency.
The variable, "Hot", is a damping coefficient which is set to
the suggested default value of 0.7. The variable "b" is
substituted for the variable, "a" used in the article since
"a" is a reserved word. The variables e1 through e6 calculate
the exponential moving averages in-line rather than calling
other functions.
The resulting indicator plotting this function appears to
duplicate the results shown in Figure 4 of the article.
The series version of this function uses previous values
and, hence, cannot call variables.
The "Periods" input can need not be an integer.
********************************************************************}
Inputs: Price(NumericSeries), Periods(NumericSimple);
Variables: b(0), b2(0), b3(0), e1(Price), e2(Price), e3(Price),
e4(Price), e5(Price), e6(Price), c1(0), c2(0), c3(0),
c4(0), f1(0), f2(0), Hot(0.7);
if Periods + 1 <> 0 then begin
if CurrentBar <= 1 then begin
b = Hot;
b2 = b * b;
b3 = b * b * b;
c1 = -b3;
c2 = 3 * b2 + 3 * b3;
c3 = -6 * b2 - 3 * b - 3 * b3;
c4 = 1 + 3 * b + b3 + 3 * b2;
f1 = 2 / (Periods + 1);
f2 = 1 - f1;
end else begin
e1 = f1 * Price + f2 * e1[1];
e2 = f1 * e1 + f2 * e2[1];
e3 = f1 * e2 + f2 * e3[1];
e4 = f1 * e3 + f2 * e4[1];
e5 = f1 * e4 + f2 * e5[1];
e6 = f1 * e5 + f2 * e6[1];
end;
T3Average.series = c1 * e6 + c2 * e5 + c3 * e4 + c4 * e3;
end;
{ *******************************************************************
Function : T3Average.simple
Last Edit : 12/16/97
Provided By : Bob Fulks
Description : This function is an EasyLanguage version of the
moving average described in the January. 1998 issue of TASC,
p57, "Smoothing Techniques for More Accurate Signals", by Tim
Tillson. It is translated from the MetaStock code presented
in the article and recoded for efficiency and to allow
variable inputs.
The variable, "Hot", is a damping coefficient which is set to
the suggested default value of 0.7. The variable "b" is
substituted for the variable, "a" used in the article since
"a" is a reserved word. The variables e1 through e6 calculate
the exponential moving averages in-line rather than calling
other functions.
The resulting indicator plotting this function appears to
duplicate the results shown in Figure 4 of the article.
The "simple" version of this function must be called on each
bar. It should not be put inside a conditional statement where
it is only evaluated on some bars.
The inputs can be variables or arrays. The "Periods" input can
be changed dynamically from bar to bar, if necessary, and need
not be an integer.
********************************************************************}
Inputs: Price(NumericSeries), Periods(NumericSimple);
Variables: b(0), b2(0), b3(0), e1(Price), e2(Price), e3(Price),
e4(Price), e5(Price), e6(Price), c1(0), c2(0), c3(0),
c4(0), f1(0), f2(0), Hot(0.7);
if Periods + 1 <> 0 then begin
if CurrentBar <= 1 then begin
b = Hot;
b2 = b * b;
b3 = b * b * b;
c1 = -b3;
c2 = 3 * b2 + 3 * b3;
c3 = -6 * b2 - 3 * b - 3 * b3;
c4 = 1 + 3 * b + b3 + 3 * b2;
end else begin
f1 = 2 / (Periods + 1);
f2 = 1 - f1;
e1 = f1 * Price + f2 * e1;
e2 = f1 * e1 + f2 * e2;
e3 = f1 * e2 + f2 * e3;
e4 = f1 * e3 + f2 * e4;
e5 = f1 * e4 + f2 * e5;
e6 = f1 * e5 + f2 * e6;
end;
T3Average.simple = c1 * e6 + c2 * e5 + c3 * e4 + c4 * e3;
end;
{ *******************************************************************
Indicator : T3Average
Last Edit : 12/16/97
Provided By : Bob Fulks
Description : : This indicator plots the moving average described
in the January. 1998 issue of TASC, p57, "Smoothing Techniques
for More Accurate Signals", by Tim Tillson.
The input, "Period", need not be an integer.
********************************************************************}
Inputs: Price(Close), Periods(5);
Plot1(T3Average.series(Price, Periods),"T3");
{ *******************************************************************
Indicator : T3Average.Demo
Last Edit : 12/16/97
Provided By : Bob Fulks
Description : : This indicator plots the moving average described
in the January. 1998 issue of TASC, p57, "Smoothing Techniques
for More Accurate Signals", by Tim Tillson.
It uses the previous T3Average function, the new T3Average.series
function, and the new T3Average.simple function.
The new T3Average.simple function duplicates the response of the
previous T3Average function.
The demo shows the effect of dynamically varying the "Periods"
input with the T3Average.simple function as a function of
volatility.
********************************************************************}
Inputs: Price(Close), Periods(5);
Vars: YYY(5);
if TrueRange <> 0 then
YYY = Periods * (1 + Volatility(10) / TrueRange) / 2;
Plot1(T3Average(Price, Periods),"T3.prev");
Plot2(T3Average.simple(Price, YYY),"T3.simple");
Plot3(T3Average.series(Price, Periods),"T3.series");
Attachment Converted: "c:\eudora\attach\T3A.ELA"--
Bob Fulks
bfulks@xxxxxxxxxxx
|