I have found numerous moving average functions in AmiBroker but not an explicit Tillson Moving Average (T3). I have found AFL in both AmiBroker and elsewhere using Tillson but their results do not match my code.
I use the below code in two other platforms. The results match. As I understand it Tillson uses three inputs: price, period, and volume factor with the ability to smooth to usually 6 iterations.
My question is how to translate the code I have to AFL.
It may be that the code below is not correct Tillson, but it is what I have used and still wish to use for now. My hope is to have AFL that matches the results of the below code.
//==================================================================================================================================================
//Tillson Moving Average to T6 "ProRealtime"
//==================================================================================================================================================
t0 = close
t1 = ( ExponentialAverage[TilsonPeriod](t0) * ( 1 + TilsonVolumeFactor ) ) - ( ( ExponentialAverage[TilsonPeriod](ExponentialAverage[TilsonPeriod](t0) ) ) * TilsonVolumeFactor )
t2 = ( ExponentialAverage[TilsonPeriod](t1) * ( 1 + TilsonVolumeFactor ) ) - ( ( ExponentialAverage[TilsonPeriod](ExponentialAverage[TilsonPeriod](t1) ) ) * TilsonVolumeFactor )
t3 = ( ExponentialAverage[TilsonPeriod](t2) * ( 1 + TilsonVolumeFactor ) ) - ( ( ExponentialAverage[TilsonPeriod](ExponentialAverage[TilsonPeriod](t2) ) ) * TilsonVolumeFactor )
t4 = ( ExponentialAverage[TilsonPeriod](t3) * ( 1 + TilsonVolumeFactor ) ) - ( ( ExponentialAverage[TilsonPeriod](ExponentialAverage[TilsonPeriod](t3) ) ) * TilsonVolumeFactor )
t5 = ( ExponentialAverage[TilsonPeriod](t4) * ( 1 + TilsonVolumeFactor ) ) - ( ( ExponentialAverage[TilsonPeriod](ExponentialAverage[TilsonPeriod](t4) ) ) * TilsonVolumeFactor )
t6 = ( ExponentialAverage[TilsonPeriod](t5) * ( 1 + TilsonVolumeFactor ) ) - ( ( ExponentialAverage[TilsonPeriod](ExponentialAverage[TilsonPeriod](t5) ) ) * TilsonVolumeFactor )
return t3 as "T3"
//==================================================================================================================================================
//Tillson Moving Average to T6 "ThinkOrSwim"
//==================================================================================================================================================
input TilsonPeriod = 2;
input TilsonVolumeFactor = 0.70;
input TilsonLevel = { T1, T2, default T3, T4, T5, T6};
script _gd {
input _price = close;
input _period = 2;
input _v = 0.70;
def _ema = ExpAverage( _price, _period );
plot _gd = ( _ema * ( 1 + _v ) ) - ( ExpAverage( _ema, _period ) * _v );
}
def _t1 = _gd( price, TilsonPeriod, TilsonVolumeFactor );
def _t2 = _gd( _t1, TilsonPeriod, TilsonVolumeFactor );
def _t3 = _gd( _t2, TilsonPeriod, TilsonVolumeFactor );
def _t4 = _gd( _t3, TilsonPeriod, TilsonVolumeFactor );
def _t5 = _gd( _t4, TilsonPeriod, TilsonVolumeFactor );
def _t6 = _gd( _t5, TilsonPeriod, TilsonVolumeFactor );
def T;
switch ( TilsonLevel ) {
case T1:
T = _t1;
case T2:
T = _t2;
case T3:
T = _t3;
case T4:
T = _t4;
case T5:
T = _t5;
case T6:
T = _t6;
}
plot TT = T;
//==================================================================================================================================================
I am still going through the documentation and tutorials trying to catch up to AmiBroker. I have coded in numerous languages starting with Fortran and Assembler about a hundred year ago, most of which doesn't seem to help me.
Thanks to the very knowledgeable creators and members of Amibroker,
Richard
PS I don't understand AMA, but does it allow an EMA of an EMA of an EMA... It that why it is used in the code I found? Still puzzled about "T3result" calculations.
function T3( Price, T3Periods, s )
{
e1 = AMA( Price, 2 / ( T3Periods + 1 ) );
e2 = AMA( e1, 2 / ( T3Periods + 1 ) );
e3 = AMA( e2, 2 / ( T3Periods + 1 ) );
e4 = AMA( e3, 2 / ( T3Periods + 1 ) );
e5 = AMA( e4, 2 / ( T3Periods + 1 ) );
e6 = AMA
( e5, 2 / ( T3Periods + 1 ) );
C1 = -s ^ 3;
C2 = 3 * s ^ 2 * ( 1 + s );
C3 = -3 * s * ( s + 1 ) ^ 2;
C4 = ( 1 + s ) ^ 3;
T3Result = c1 * e6 + c2 * e5 + c3 * e4 + c4 * e3;
return Nz( T3Result );
}