TMO True Momentum Oscillator

Hello

Has anyone come across the True Momentum indicator for Amibroker? Am using it in ToS and would be great to have for in Amibroekr for optimization.

TMO Code

Thanks

hi, i am not familiar with thinkscript so this section is the tricky part:

def data = fold i = 0 to length
           with s
           do s + (if c > getValue(o, i)
                   then 1
                   else if c < getValue(o, i)
                        then - 1
                        else 0);

i first thought it was simply this:

data = IIf( C > O, 1, IIf( C < O, -1, 0 ) );
data = Sum( data, length );

but maybe it is a bit more complicated. I came up with the code below. Maybe you can check if the result is the same as ToS gives:

_SECTION_BEGIN( "TMO" );
length = Param( "Length", 14, 2, 200, 1 );
calcLength = Param( "Calc Length", 5, 2, 200, 1 );
smoothLength = Param( "Smooth Length", 3, 2, 200, 1 );

data = 0;

for( i = length - 1; i < BarCount; i++ )
{
    cnt = 0;

    for( j = 0; j < length; j++ )
    {
        if( C[i] > O[( j - ( length - 1 ) ) + i] )
        {
            cnt = cnt + 1;
        }
        else
            if( C[i] < O[( j - ( length - 1 ) ) + i] )
            {
                cnt = cnt - 1;
            }
    }

    data[i] = cnt;
}

EMA5 = EMA( data, calcLength );
ml = Main = EMA( EMA5, smoothLength );
sl = Signal1 = EMA( Main, smoothLength );
Plot( ml, "TMO" + _PARAM_VALUES(), IIf( ml > sl, colorBrightGreen, colorRed ), styleLine, Null, Null, 0, 0, 1 );
Plot( sl, "", IIf( ml > sl, colorBrightGreen, colorRed ), styleLine, Null, Null, 0, 0, 1 );
PlotOHLC( ml, ml, sl, sl, "", IIf( ml > sl, colorDarkGreen, IIf( ml < sl, colorDarkRed, colorDarkGrey ) ), styleNoTitle | styleCloud | styleNoLabel, Null, Null, 0, 0, 1 );
PlotOHLC( length, length, length * 0.7, length * 0.7, "",colorDarkRed, styleNoTitle | styleCloud | styleNoLabel, Null, Null, 0, -1, 1);
PlotOHLC( -length, -length, -length * 0.7, -length * 0.7, "",colorDarkGreen, styleNoTitle | styleCloud | styleNoLabel, Null, Null, 0, -1, 1);
_SECTION_END();
5 Likes

@empottasch,

BarCount loop is too slow.
It can be done without it.
E.g.

cnt = 0;
for ( j = 0; j < length; j++ )
	cnt += (C > Ref(O, -j)) - (C < Ref(O, -j));	
data = cnt;

So,

_SECTION_BEGIN( "TMO" );
/// @link https://forum.amibroker.com/t/tmo-true-momentum-oscillator/20426
length = Param( "Length", 14, 2, 200, 1 );
calcLength = Param( "Calc Length", 5, 2, 200, 1 );
smoothLength = Param( "Smooth Length", 3, 2, 200, 1 );

cnt = 0;
for ( j = 0; j < length; j++ )
	cnt += (C > Ref(O, -j)) - (C < Ref(O, -j));	
data = cnt;

EMA5 = EMA( data, calcLength );
ml = Main = EMA( EMA5, smoothLength );
sl = Signal1 = EMA( Main, smoothLength );
Plot( ml, "TMO" + _PARAM_VALUES(), IIf( ml > sl, colorBrightGreen, colorRed ), styleLine, Null, Null, 0, 0, 1 );
Plot( sl, "", IIf( ml > sl, colorBrightGreen, colorRed ), styleLine, Null, Null, 0, 0, 1 );
PlotOHLC( ml, ml, sl, sl, "", IIf( ml > sl, colorDarkGreen, IIf( ml < sl, colorDarkRed, colorDarkGrey ) ), styleNoTitle | styleCloud | styleNoLabel, Null, Null, 0, 0, 1 );
PlotOHLC( length, length, length * 0.7, length * 0.7, "",colorDarkRed, styleNoTitle | styleCloud | styleNoLabel, Null, Null, 0, -1, 1);
PlotOHLC( -length, -length, -length * 0.7, -length * 0.7, "",colorDarkGreen, styleNoTitle | styleCloud | styleNoLabel, Null, Null, 0, -1, 1);
_SECTION_END();

Both result in same output.
14

10 Likes

very nice solution. Is this also as intended by ToS, meaning is the translation from ToS also correct?

with the same parameters as the standard MACD( 12, 26, 9) the chart looks very similar to MACD

QHG

2 Likes
input agg = AggregationPeriod.Fifteen_min; 
 
def o = open(period = agg); 
def c = close(period = agg); 
def data = fold i = 0 to length 

The " AggregationPeriod.Fifteen_min" means do all calculation in 15min timeframe

1 Like

hi, yes I seen that but this version does not use that:

but 15min is easy to add. But I guess the rest is translated correctly, at least it looks similar :slight_smile:

2 Likes

very nice code! Thanks for sharing!
Tony Roylance

Very nice, much appreciated. Spot on against ToS.

Decent signals for standalone momo indicator ...

tmo

1 Like

Thanks for your sharing!