Wednesday, 23 October 2019

Trendline based on HH-LH-LL-HL AFL for Amibroker

Trendline based on HH-LH-LL-HL AFL for Amibroker





function ParamOptimize( pname, defaultval, minv, maxv, step )
{
    return Optimize( pname,
                     Param( pname, defaultval, minv, maxv, step ),
                     minv, maxv, step );
}

ParmSCThreshold = ParamOptimize( "ScoreCard Threshold", 5, 1, 9, 1 );
labelsswitch = ParamToggle( "Show Labels", "Off|On", 1 );
sz = Param( "Font Size", 8, 4, 16, 1 );

upColor = ColorRGB( 0, 150, 250 );
dnColor = ColorRGB( 250, 150, 0 );

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

KPA900 = E_TSKPA900( Close );
KPAutoStop = E_TSKPAUTOSTOP( High, Low, Close );
Ctmpl = E_TSKPCOLORTMPL( Open, High, Low, Close, Volume );    //ScoreCard

KPScoreCard = 0;
KPScoreCard = KPScoreCard  + IIf( tskp_colortmplcnd0 > 0, 1, -1 );
KPScoreCard = KPScoreCard  + IIf( tskp_colortmplcnd1 > 0, 1, -1 );
KPScoreCard = KPScoreCard  + IIf( tskp_colortmplcnd2 > 0, 1, -1 );
KPScoreCard = KPScoreCard  + IIf( tskp_colortmplcnd3 > 0, 1, -1 );
KPScoreCard = KPScoreCard  + IIf( tskp_colortmplcnd4 > 0, 1, -1 );
KPScoreCard = KPScoreCard  + IIf( tskp_colortmplcnd5 > 0, 1, -1 );
KPScoreCard = KPScoreCard  + IIf( tskp_colortmplcnd6 > 0, 1, -1 );
KPScoreCard = KPScoreCard  + IIf( tskp_colortmplcnd7 > 0, 1, -1 );
KPScoreCard = KPScoreCard  + IIf( tskp_colortmplcnd8 > 0, 1, -1 );
Plot( Close, "C", colorWhite, styleCandle);

XOUp = ( KPA900 > KPAutoStop ) AND( KPScoreCard >= parmSCThreshold );
XODn = ( KPA900 < KPAutoStop ) AND( KPScoreCard <= -parmSCThreshold );
XOUp = ExRem( XOUp, XODn );
XODn = ExRem( XODn, XOUp );

HighestSinceXOUp = HighestSince( XOUp, H ) == H;
LowestSinceXODn = LowestSince( XODn, L ) == L;
LowestSinceXODn = IIf( LowestSinceXODn && HighestSinceXOUp, 0, LowestSinceXODn );
HighestSinceXOUp = IIf( LowestSinceXODn && HighestSinceXOUp, 0, HighestSinceXOUp );

rHighestSinceXOUp = Reverse( HighestSinceXOUp );
rLowestSinceXODn = Reverse( LowestSinceXODn );
tr = ExRem( rLowestSinceXODn, rHighestSinceXOUp );
pk = ExRem( rHighestSinceXOUp, rLowestSinceXODn );
tr = Reverse( tr );
pk = Reverse( pk );

PlotShapes( shapeSmallCircle*tr, colorGreen, 0, L, -10 );
PlotShapes( shapeSmallCircle*pk, colorRed, 0, H, 10 );

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

pl = ll = tr AND tl1 < tl2;
hpl = hl = tr AND tl1 > tl2;
ph = hh = pk AND ph1 > ph2;
lph = lh = pk AND ph1 < ph2;
dt = pk AND ph1 == ph2;
db = tr AND tl1 == tl2;

ft = "arial black";
clr = ColorRGB( 10, 10, 10 );//colorDefault;
clr1 = ColorRGB( 150, 150, 150 );

if( labelsswitch )
{
    for( i = fvb; i <= lvb; i++ )
    {
      
        if( ll[i] )
        {
            str = "LL";
            PlotTextSetFont( str, ft, sz, i, L[i], clr1, clr, -30 );
        }

        if( hpl[i] )
        {
            str = "HL";
            PlotTextSetFont( str, ft , sz, i, L[i], clr1, clr, -30 );
        }

        if( db[i] )
        {
            str = "DB";
            PlotTextSetFont( str, ft, sz, i, L[i], clr1, clr, -30 );
        }

        if( ph[i] )
        {
            str = "HH";
            PlotTextSetFont( str, ft, sz, i, H[i], clr1, clr, 20 );
        }

        if( lph[i] )
        {
            str = "LH";
            PlotTextSetFont( str, ft, sz, i, H[i], clr1, clr, 20 );
        }

        if( dt[i] )
        {
            str = "DT";
            PlotTextSetFont( str, ft, sz, i, H[i], clr1, clr, 20 );
        }
    }
}

_SECTION_END();

2 comments:

  1. the code seems broken.. some fault ...syntax error identifier "e_tskpa900" is unindentified

    ReplyDelete
  2. Afsa alam you are A real son of a bitch

    ReplyDelete

Thanks