// AFL code by E.M.Pottasch, 3/2018
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();
The above code plots the chart as below:
The above code I have taken from a code by @empottasch
In the sabove cide . I want to join the HH-LH-LL-HL points by green and red lines to show the trend in channels.
Till the HH-HL points continue to print we should get both HH & HL points by green lines and this signals uptrend.
Simillarly, till the LH-LL points continue to print we should get both LH & LL points by red lines and this signals downtrend.
Any other combination of points when printed considering the last two points printed (always) we can join the points by yellow lines to denote undecided trend.
@empottasch and other experts please help me to achieve this idea getting coded.
Any suggestions to improve the efficiency of this idea is much appreciated