Stock Portfolio Organizer

The ultimate porfolio management solution.

Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
For Portfolio Manager Click Here

WiseTrader Toolbox

#1 Selling Amibroker Plugin featuring:

Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Find Out More Here

tl for Amibroker (AFL)

Copy & Paste Friendly
_SECTION_BEGIN( "Trendline " );
// E.M.Pottasch, 3/2015
SetChartOptions( 0, chartShowArrows | chartShowDates );

_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );

size = Param( "ZigZag-Sensitivity", 5, 0.1, 100, 0.1 ) ; // Size for the trendline
gs = ParamToggle( "Price Toggle", "H/L|C", 1 );

xx = x = BarIndex();
fvb = FirstVisibleValue( x );
lvb = LastVisibleValue( x );

if ( gs )
{
    pk = Peak( c, Size ) == c AND Zig( c, Size ) == c;
    tr = Trough( c, Size ) == c AND Zig( c, Size ) == c;

    px0 = ValueWhen( pk, x, 0 );
    tx0 = ValueWhen( tr, x, 0 );
    px1 = ValueWhen( pk, x, 1 );
    tx1 = ValueWhen( tr, x, 1 );
    px2 = ValueWhen( pk, x, 2 );
    tx2 = ValueWhen( tr, x, 2 );
    ph0 = ValueWhen( pk, C, 0 );
    tl0 = ValueWhen( tr, C, 0 );
    ph1 = ValueWhen( pk, C, 1 );
    tl1 = ValueWhen( tr, C, 1 );
    ph2 = ValueWhen( pk, C, 2 );
    tl2 = ValueWhen( tr, C, 2 );
}
else
{
    pk = Peak( H, Size ) == H AND Zig( H, Size ) == H;
    tr = Trough( L, Size ) == L AND Zig( L, Size ) == L;

    px0 = ValueWhen( pk, x, 0 );
    tx0 = ValueWhen( tr, x, 0 );
    px1 = ValueWhen( pk, x, 1 );
    tx1 = ValueWhen( tr, x, 1 );
    px2 = ValueWhen( pk, x, 2 );
    tx2 = ValueWhen( tr, x, 2 );
    ph0 = ValueWhen( pk, H, 0 );
    tl0 = ValueWhen( tr, L, 0 );
    ph1 = ValueWhen( pk, H, 1 );
    tl1 = ValueWhen( tr, L, 1 );
    ph2 = ValueWhen( pk, H, 2 );
    tl2 = ValueWhen( tr, L, 2 );
}

ll = tr AND tl1 < tl2;

hl = tr AND tl1 > tl2;
hh = pk AND ph1 > ph2;
lh = pk AND ph1 < ph2;
dt = pk AND ph1 == ph2;
db = tr AND tl1 == tl2;

Plot( C, "C", colorWhite, styleCandle, Null, Null, 0, 0, 1 );
PlotShapes( shapeCircle*pk, ColorRGB( 255, 0, 0 ), 0, H, 10 );
PlotShapes( shapeCircle*tr, ColorRGB( 0, 255, 0 ), 0, L, -10 );

if ( gs )
    Plot( Zig( c, Size ), "Zig", ColorRGB( 50, 50, 50 ), styleDashed, Null, Null, 0, 0, 1 );

for ( i = lvb;i > fvb;i-- )
{
    {
        if ( ll[i] )
            PlotTextSetFont( "LL", "Arial Black", 8, i, L[i], colorGreen, colorDefault, -30 );

        if ( hl[i] )
            PlotTextSetFont( "HL", "Arial Black", 8, i, L[i], colorGreen, colorDefault, -30 );

        if ( db[i] )
            PlotTextSetFont( "DB", "Arial Black", 8, i, L[i], colorLightBlue, colorDefault, -30 );

        if ( hh[i] )
            PlotTextSetFont( "HH", "Arial Black", 8, i, H[i], colorRed, colorDefault, 20 );

        if ( lh[i] )
            PlotTextSetFont( "LH", "Arial Black", 8, i, H[i], colorRed, colorDefault, 20 );

        if ( dt[i] )
            PlotTextSetFont( "DT", "Arial Black", 8, i, H[i], colorOrange, colorDefault, 20 );
    }
}

cnta = cntb = 0;

for ( i = lvb;i > fvb;i-- )
{
    if ( pk[ i ] AND ph2[i] > ph1[i] AND cnta < 200 )
    {
        x2 = px2[i];
        x1 = px1[i];
        x0 = px0[i];
        y2 = ph2[i];
        y1 = ph1[i];

        if ( x0 == x1 )
            x0 = BarCount - 1;

        Line = LineArray( x2, y2, x1, y1, 1 );

        idx2 = xx == x2;

        idx1 = xx == x0;

        idx = Flip( idx2, idx1 );

        Line = IIf( idx, Line, Null );

        Plot( Line, "", colorred, 1, Null, Null, 0, 1, 2 );

        cnta = cnta + 1;
    }

    if ( tr[ i ] AND tl2[i] < tl1[i] AND cntb < 200 )
    {
        x2 = tx2[i];
        x1 = tx1[i];
        x0 = tx0[i];
        y2 = tl2[i];
        y1 = tl1[i];

        if ( x0 == x1 )
            x0 = BarCount - 1;

        Line = LineArray( x2, y2, x1, y1, 1 );

        idx2 = xx == x2;

        idx1 = xx == x0;

        idx = Flip( idx2, idx1 );

        Line = IIf( idx, Line, Null );

        Plot( Line, "", colorgreen, 1, Null, Null, 0, 1, 2 );

        cntb = cntb + 1;
    }
}
_SECTION_END();
Back