# Tillson Function ???

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 );
}
``````

You haven't searched basic formula resource - AFL Formula Library (in the members zone):
https://www.amibroker.com/members/library/

T3 is available there:

https://www.amibroker.com/members/library/detail.php?id=82

another flavor is here:
http://www.amibroker.com/members/library/detail.php?id=342

As to your other questions : any average can be nested so of course you can have EMA from EMA and AMA from AMA and any other nesting imaginable.

Yes I did find several in the library and others. My trouble is that I was unable to match the results of the code I posted with the T3 examples I found. I have my login.

It may be that the code examples I posted are different or I do not understand the parameters well enough. I want to use the Tillson at T6, not the typical T3. I will try the code you mentioned. It is different than the ones I found.

My hope is what I have working on the other platforms will work in Amibroker. I know my code works for my purposes and look forward to being able to run much more testing in Amibroker.

I did not find the T3 in this reference list:
https://www.amibroker.com/guide/a_funref.html
Am I looking in the wrong place?

Richard

I never understood the concept of "matching" results to some random code from random platform.
Instead you should match results to original author's results, i.e. if author presented his idea in the form of book or article, you should match results to original article. If somebody comes with his own tweaked idea, it should not be called T3 anymore because it just creates confusion among casual readers looking for code.

If you want to replicate other platform code - just translate line by line.

The function gd in AFL would be just

``````function _gd( _input, _period, _v )
{
_ema = EMA( _input, _period  );
return _ema * ( 1 + _v ) - EMA( _ema, _period  ) * _v;
}

``````

Then the rest of the code is almost unchanged

``````TilsonPeriod            = 2;
TilsonVolumeFactor = 0.70;

_t1 = _gd( Close, TilsonPeriod, TilsonVolumeFactor );
_t2 = _gd( _t1,   TilsonPeriod, TilsonVolumeFactor );
_t3 = _gd( _t2,   TilsonPeriod, TilsonVolumeFactor );
_t4 = _gd( _t3,   TilsonPeriod, TilsonVolumeFactor );
_t5 = _gd( _t4,   TilsonPeriod, TilsonVolumeFactor );
_t6 = _gd( _t5,   TilsonPeriod, TilsonVolumeFactor );
``````

Tomasz,

I did not consider the code random. It is posted in Amibroker like the other platforms. I have read, although with partial understanding of the math, much on the Tillson and many many other ideas. I do try to follow what you've suggested and not make things up. I believe the work of others has value and should be studied and try to understand their work, but often fall short. I don't think it necessary to understand every moving part of a car to be able to drive. Bad analogy but hopefully it makes sense.

I am finding Amibroker and it member to have information I can rely upon, not only from the depth of education found but in the care given to doing everything well and to high standards.

I am an old procedural programmer who liked to write efficient and succinct code, but sadly years ago and am out of practice. It is good to see others who take this seriously.
Thank you again,
Richard

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.