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

True ZigZag with Valid Peaks & Troughs for Amibroker (AFL)

Rating:
5 / 5 (Votes 1)
Tags:
amibroker

ZigZag’s Peaks and Troughs are validated via Buy-Sell Signals

Indicator / Formula

Copy & Paste Friendly
SetChartBkColor( ColorRGB( 0, 0, 0 ) );
SetChartOptions( 0, chartShowArrows | chartShowDates );
Plot( C, "C", colorWhite, styleCandle, Null, Null, 0, 0, 1 );
pr = Param( "ZigZag change amount", 5, 0.05, 20, 0.05 );

bi = BarIndex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );

x = C;
pk = PeakBars( x, pr ) == 0;
tr = TroughBars( x, pr ) == 0;

for( i = 0; i < 2; i++ )
{
    VarSet( "px" + i, ValueWhen( pk, bi, i ) );
    VarSet( "tx" + i, ValueWhen( tr, bi, i ) );
    VarSet( "ph" + i, ValueWhen( pk, x, i ) );
    VarSet( "tl" + i, ValueWhen( tr, x, i ) );
}

zzHiLo = Zig( x, pr );
PeakVal = Peak( x, pr );
TroughVal = Trough( x, pr );

validUp = Troughval + ( TroughVal / 100 ) * pr;
validDn = Peakval - ( PeakVal / 100 ) * pr;

Buy = ( ( Cross( C, validUp ) || C > validUp ) && tx1 > px1 ) || ( ( Cross( C, validUp ) || C > validUp ) && tx1 < px1 && pk );
BuyPrice = C;
Short = ( ( Cross( validDn, C ) || C < validDn ) && px1 > tx1 ) || ( ( Cross( validDn, C ) || C < validDn ) && px1 < tx1 && tr );
ShortPrice = C;
Buy = ExRem( Buy, Short );
Short = ExRem( Short, Buy );
Sell = Short; SellPrice = ShortPrice;
Cover = Buy; CoverPrice = BuyPrice;

PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), ColorRGB( 0, 250, 250 ), 0, L, -15 );
PlotShapes( IIf( Buy, shapeSmallSquare, shapeNone ), colorLightBlue, 0, BuyPrice, 0 );
PlotShapes( IIf( Short, shapeDownArrow, shapeNone ), ColorRGB( 250, 250, 0 ) , 0, H, -15 );
PlotShapes( IIf( Short, shapeSmallSquare, shapeNone ), colorOrange, 0, SellPrice, 0 );

Plot( zzHiLo, "", colorBlue , styleNoLabel );
Plot( validUp, "", colorBrightGreen, styleDashed | styleNoRescale, Null, Null, 0, 0, 1 );
Plot( validDn, "", colorRed, styleDashed | styleNoRescale, Null, Null, 0, 0, 1 );

ft = "Tahoma";
sz = 10;
clr1 = ColorRGB( 0, 0, 0 );
clr2 = ColorRGB( 250, 250, 250 );

for( i = fvb; i < lvb; i++ )
{
    if( pk[i] )
    {
        str = "Top";
        PlotTextSetFont( str, ft, sz, i, H[i], clr1, clr2, 20 - sz );
    }

    if( tr[i] )
    {
        str = "Bot";
        PlotTextSetFont( str, ft, sz, i, L[i], clr1, clr2, -20 );
    }
}

0 comments

Leave Comment

Please login here to leave a comment.

Back