I have visited various post, one link is:-
The code I am posting has been copied from the above link. the chart I am posting is a 15 min chart with
fractal strength of "8".
CODE:
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates | chartHideQuoteMarker);
GraphLabelDecimals = 2;
GraphXSpace =10;
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} | {{DATE}} | Open %g | Hi %g | Lo %g | Close %g | (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
TC = IIf(C>Ref(C,-1),colorGreen,IIf(C<Ref(C,-1),colorRed,colorGold));
Plot( C, "Close", TC, styleNoTitle | styleBar | styleThick );
_SECTION_END();
_SECTION_BEGIN("WAVES");
x=xx = BarIndex();
fvb = FirstVisibleValue( x );
lvb = LastVisibleValue( x );
EWRS = EWLS =Param( "Strength",5, 2, 50, 1 );
plotpivots = ParamToggle( " Pivots", "NO|YES", 1 );
plotEWswings = ParamToggle( "EW Swings", "NO|YES", 0 );
// Identifying Pivots
pk = H == HHV( H, EWLS ) AND Ref( HHV( H, EWRS ), EWRS ) < H;
pk = pk AND LastValue( x ) - ValueWhen( pk, x ) > EWRS;
tr = L == LLV( L, EWLS ) AND Ref( LLV( L, EWRS ), EWRS ) > L;
tr = tr AND LastValue( x ) - ValueWhen( tr, x ) > EWRS;
if( Plotpivots )
{
PlotShapes( shapeSmallCircle * pk, colorRed, 0, H, 15 );
PlotShapes( shapeSmallCircle * tr, colorBlue, 0, L, -15 );
}
// DRAWING SWING LINES
pk = IIf( pk, IIf( ValueWhen( pk, x, 2 ) < ValueWhen( tr, x ), pk, IIf( ValueWhen( pk, H, 2 ) > H, False, pk ) ), pk );
pk = IIf( pk AND ValueWhen( pk, x, 0 ) > x, IIf( ValueWhen( pk, x, 0 ) < ValueWhen( tr, x, 0 ), IIf( ValueWhen( pk, H, 0 ) >= H, False, pk ), pk ), pk );
tr = IIf( tr, IIf( ValueWhen( tr, x, 2 ) < ValueWhen( pk, x ), tr, IIf( ValueWhen( tr, L, 2 ) < L, False, tr ) ), tr );
tr = IIf( tr AND ValueWhen( tr, x, 0 ) > x , IIf( ValueWhen( tr, x, 0 ) < ValueWhen( pk, x, 0 ), IIf( ValueWhen( tr, L, 0 ) <= L, False, tr ), tr ), tr );
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);
if( plotEWswings )
{
aa1=IIf(px0>tx1,(ph0-tl1)/(px0-tx1),0);
aa1=IIf(pk,Ref(aa1,-1),aa1);
ls1=aa1*(xx-tx1)+tl1;
bb1=IIf(px0>tx1 AND px1<tx1,1,0);
bb1=bb1+Ref(bb1,-1);bb1=IIf(bb1,1,0);
ls1=IIf(bb1,ls1,Null);
Plot(ls1,"",colorBlue,styleLine);
aa1=IIf(tx0>px1,(tl0-ph1)/(tx0-px1),0);
aa1=IIf(tr,Ref(aa1,-1),aa1);
Ls1=aa1*(xx-px1)+ph1;
bb1=IIf(tx0>px1 AND tx1<px1,1,0);
bb1=bb1+Ref(bb1,-1);
bb1=IIf(bb1,1,0);
ls2=IIf(bb1,ls1,Null);
Plot(ls2,"",colorOrange,styleLine);
}
_SECTION_END();or paste code here
SCREEN SHOT:
The comments on the chart explain what I have been trying to do , will put it down here:
ref the chart:-- when the price goes below the last fractal the swing should plot till the low of that bar, and continue doing so, same for upside--when the price exceeds a prior hIgh fractal the swing should keep plotting till the high of the last bar. OF COURSE, IF A NEW FRACTAL PLOTS IN THE OPPOSITE DIRECTION THEN THE SWINGS SHOULD PLOT TO THE FRACTALS.
With my limited knowledge of AFL I have been struggling with this, request some help.
thanks.