Need help with programming the TB-F

@empottasch
dear friend, i have one more entreaty. If it possible of course.
Let's see at QUIK TB-F:

gazprom011

As you can see there are digits above the tb-f curve. This the procent of the spent TB-F. So as we can see it the final bars of this tb-f

So is it possible to make the same in Ami?

gazprom010

1 Like

yes this is possible because D (or the amount of fuel :smile: ) is known. Will add this tomorrow

1 Like

you can add the following at the bottom of the code I posted

if( stidx < ( BarCount - 1 ) AND( d1 / dd * 100 ) <= 100 )
{
    x1 = LastValue( ValueWhen( TBFLoop, bi ) );
    y1 = LastValue( ValueWhen( TBFLoop, TBFLoop ) );
    pleft = d1 / dd * 100;
    GfxSetZOrder( -5 );
    GfxSetCoordsMode( 1 );
    GfxSetTextAlign( 0 | 8 );
    GfxSetBkColor( ColorRGB( 0, 0, 0 ) );
    GfxSetTextColor( ColorRGB( 0, 255, 255 ) );
    GfxSelectFont( "Tahoma", 10 );
    GfxTextOut( "" + Prec( pleft, 2 ), x1 + 1 , y1 );
}
1 Like

It give the error :frowning:
TBF015

i wrote that for the last code I posted.

so not sure which code you use but just add bi = BarIndex(); like this

bi = BarIndex();
if( stidx < ( BarCount - 1 ) AND( d1 / dd * 100 ) <= 100 )
{
    x1 = LastValue( ValueWhen( TBFLoop, bi ) );
    y1 = LastValue( ValueWhen( TBFLoop, TBFLoop ) );
    pleft = d1 / dd * 100;
    GfxSetZOrder( -5 );
    GfxSetCoordsMode( 1 );
    GfxSetTextAlign( 0 | 8 );
    GfxSetBkColor( ColorRGB( 0, 0, 0 ) );
    GfxSetTextColor( ColorRGB( 0, 255, 255 ) );
    GfxSelectFont( "Tahoma", 10 );
    GfxTextOut( "" + Prec( pleft, 2 ), x1 + 1 , y1 );
}

i used gfx functions because you are using 5.6 but it would be better to use PlotTextSetFont(), but you need a more recent version of Amibroker for that

2 Likes

I am using 6.00 already

you then also use this at the bottom of your code instead

bi = BarIndex();
if( stidx < ( BarCount - 1 ) AND( d1 / dd * 100 ) <= 100 )
{
    x1 = LastValue( ValueWhen( TBFLoop, bi ) );
    y1 = LastValue( ValueWhen( TBFLoop, TBFLoop ) );
    pleft = Prec( d1 / dd * 100, 2 );
    PlotTextSetFont( "" + pleft, "Tahoma", 10, x1, y1, ColorRGB( 0, 255, 255 ), colorDefault, 10 );
}
2 Likes

Awesome! Thanks a lot!

1 Like

Hi @empottasch,

Really appreciate your contribution of TB_F codes here, this is huge because I am a long time fan of MIDAS(Paul Levine) since he first published these articles back in early 90's. I even used "WinMidas" which was developed by Dr Fisher, Paul's colleague. I have been looking to understand/implement TB_F for AB but never got around the "e" calculation. One question regarding your code if you could elaborate the logic behind

for( j = stidx + 1; j <= i; j++ )
{
    if( x1 > cumvol[j - 1] AND x1 < cumvol[j] )
    {
        idx = j;
        //_TRACE( "i: " + i + " j: " + j );
        break;
    }
}

// interpolate
if( idx != 0 AND  e1 >= 0 )
{
    v0 = cumpvol[idx - 1];
    v1 = cumpvol[idx];
    t = ( x1 - cumvol[idx - 1] ) / ( cumvol[idx] - cumvol[idx - 1] );
    result = ( 1 - t ) * v0 + t * v1;
    TBFLoop[i] = ( cumpvol[i] - result ) / e1;
}

Is "result" the interpolation mechanism? I don't really follow this part.

Again, than you for your work.

One more thing, what does the for loop do?

hi, i'm sorry, i would have to dig into it again and doing other things now. Best to go through it step by step or try to write your own version and then compare.