Marking fractals and drawing swing lines

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:
image

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.

I don't believe these kind of drawn trendlines would have any trading benefit unless you like to explain a little bit about the reason behind it.

But as it may carry some programming value to you , here's a modified version from the above 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);


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);

aa2=IIf(tx0>px1,(tl0-ph1)/(tx0-px1),0);
aa2=IIf(tr,Ref(aa2,-1),aa2);
Ls2=aa2*(xx-px1)+ph1;

bb2=IIf(tx0>px1 AND tx1<px1,1,0);
bb2=bb2+Ref(bb2,-1);
bb2=IIf(bb2,1,0);
ls2=IIf(bb2,ls2,Null);


ls3 = IIf(bb1,ls1,ls2);


Peak_0   = (Ref(ls3,0) > Ref(ls3,1) AND Ref(ls3,0) > Ref(ls3,-1)) OR ExRem((Ref(IsNull(ls3),1) AND Ref(IsNull(ls3),-1) == 0) AND ROC(ls1,1) > 0,0);
Trough_0 = (Ref(ls3,0) < Ref(ls3,1) AND Ref(ls3,0) < Ref(ls3,-1)) OR ExRem((Ref(IsNull(ls3),1) AND Ref(IsNull(ls3),-1) == 0) AND ROC(ls2,1) < 0,0);

LPB = Last_Peak_Bar     = LastValue(ValueWhen(ExRem(Cum(Peak_0) == LastValue(Cum(Peak_0)),0),BarIndex()));
LPP = Last_Peak_Price   = LastValue(ValueWhen(ExRem(Cum(Peak_0) == LastValue(Cum(Peak_0)),0),High));

LTB = Last_Trough_Bar   = LastValue(ValueWhen(ExRem(Cum(Trough_0) == LastValue(Cum(Trough_0)),0),BarIndex()));
LTP = Last_Trough_Price = LastValue(ValueWhen(ExRem(Cum(Trough_0) == LastValue(Cum(Trough_0)),0),Low));


Bi   		= BarIndex();
LBi			= LastValue(Bi);
Condition   = LPB > LTB;
Break_Level = IIf(Condition,ValueWhen(LTB == BarIndex(),LTP),ValueWhen(LPB == BarIndex(),LPP));

GfxSetZOrder(-1);
GfxSetCoordsMode(1);
GfxSelectPen(colorWhite);

for ( i = FVB; i < LVB; i++ )
{
	if ( Condition AND L[i] < LTP AND Bi[i] >= LPB )
	{
		GfxMoveTo(LPB,LPP);
		GfxLineTo(i,L[i]);
	
	}
	
	if ( !Condition AND H[i] > LPP AND Bi[i] >= LTB )
	{
		GfxMoveTo(LTB,LTP);
		GfxLineTo(i,H[i]);
	}
}


if( plotEWswings )
{
	Plot(ls1,"",colorBlue,styleLine);
	Plot(ls2,"",colorOrange,styleLine);
}

1 Like

Looks like some old Bill Williams stuff, who used the term Fractals when determining swing pivots...
Ref: https://www.youtube.com/watch?v=bNxt298VVOw

1 Like

@Sebastian

Trying to clarify: ALL THE WHITE LINES ARE NOT REQUIRED.
In te posted chart only the last swing line , from the established "fractal high" to the new low which is lower than the established "fractal low" is needed --- the other intermediate lines should not plot !

Thanks for your code - helped me to remove a lot of unwanted lines in the code I was using .

I am posting another chart to illustrate my point.

image

Only the last swing line is required. Kindly guide me.

Thanks.

Thank you @Sean :slight_smile: , appreciating this and going to watch the video at weekend


@JEETU

You wrote in your first post that you want multiple lines to be drawn once there's
a new high above the last confirmed high OR
a new low below the last confirmed low

See the bold text from you first post

While if you wrote the below phrase from the first time , it would save my time and effort and also you would get the right code from the first time.

Please, next time try to articulate your words & ideas better in a clear writing style

You need to add the below code and also delete the GFX section from the old code

LCP = Last_Confirmed_Price_Level		= IIf(Condition,LPP,LTP);
LCB = Last_Confirmed_BarIndex_Level		= IIf(Condition,LPB,LTB);

LNP = Last_Non_Confirmed_Price_Level    = LastValue(IIf(Condition,Lowest(ValueWhen(LPB <= Bi,L)),Highest(ValueWhen(LTB <= Bi,H))));
LNB = Last_Non_Confirmed_BarIndex_Level = LastValue(IIf(Condition,ValueWhen(LPB <= Bi AND L == LNP,Bi),ValueWhen(LTB <= Bi AND H == LNP,Bi)));

LA  = Last_Line			 				= LineArray(LCB,LCP,LNB,LNP);
1 Like

@Sebastian
Maybe we can write it like this…………..

condition0 = LastValue(px1)>LastValue(tx1);
Bar_Last_Peak_Trough = IIf(condition0,LastValue(px1),LastValue(tx1));
Last_Peak_Trough_Value = IIf(condition0,LastValue(ph1),LastValue(tl1));
1 Like

@Fossil,
This is much better and more simplified , when i started to modify the code , i did not carefully check it line by line from top to bottom , instead i directly focused on extracting the variables representing Up&Down swings , then i united those variables ( ls1 & ls2 ) into one ( ls3 ), and from that point i began to write the additional part without any need to look again at the original code , that's why my additions was a little bit longer.

1 Like

Just a hint (but not a reproof). :slight_smile:

If you want to get last element of array then you just need single call of LastValue

e.g.

instead of

condition0 = LastValue(px1)>LastValue(tx1);

->

condition0 = LastValue(px1 > tx1);

So as in regards to @Fossil's three lines

condition0 = px1 > tx1;// we just keep array type for condition0
Bar_Last_Peak_Trough = LastValue( IIf(condition0, px1, tx1) );
Last_Peak_Trough_Value = LastValue( IIf(condition0, ph1, tl1) );

So instead of six times LastValue you would just need to write two times that function.

3 Likes

Thanks to all of u, as always I learn from every post.

Though I am still having a problem with the code so I am posting the full code and a capture of the chart.

First the 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);


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);

aa2=IIf(tx0>px1,(tl0-ph1)/(tx0-px1),0);
aa2=IIf(tr,Ref(aa2,-1),aa2);
Ls2=aa2*(xx-px1)+ph1;

bb2=IIf(tx0>px1 AND tx1<px1,1,0);
bb2=bb2+Ref(bb2,-1);
bb2=IIf(bb2,1,0);
ls2=IIf(bb2,ls2,Null);

if( plotEWswings )
{
	Plot(ls1,"",colorBlue,styleLine);
	Plot(ls2,"",colorOrange,styleLine);
}


ls3 = IIf(bb1,ls1,ls2);


Peak_0   = (Ref(ls3,0) > Ref(ls3,1) AND Ref(ls3,0) > Ref(ls3,-1)) OR ExRem((Ref(IsNull(ls3),1) AND Ref(IsNull(ls3),-1) == 0) AND ROC(ls1,1) > 0,0);
Trough_0 = (Ref(ls3,0) < Ref(ls3,1) AND Ref(ls3,0) < Ref(ls3,-1)) OR ExRem((Ref(IsNull(ls3),1) AND Ref(IsNull(ls3),-1) == 0) AND ROC(ls2,1) < 0,0);

LPB = Last_Peak_Bar     = LastValue(ValueWhen(ExRem(Cum(Peak_0) == LastValue(Cum(Peak_0)),0),BarIndex()));
LPP = Last_Peak_Price   = LastValue(ValueWhen(ExRem(Cum(Peak_0) == LastValue(Cum(Peak_0)),0),High));

LTB = Last_Trough_Bar   = LastValue(ValueWhen(ExRem(Cum(Trough_0) == LastValue(Cum(Trough_0)),0),BarIndex()));
LTP = Last_Trough_Price = LastValue(ValueWhen(ExRem(Cum(Trough_0) == LastValue(Cum(Trough_0)),0),Low));

Bi   		= BarIndex();
LBi			= LastValue(Bi);
Condition   = LPB > LTB;
Break_Level = IIf(Condition,ValueWhen(LTB == BarIndex(),LTP),ValueWhen(LPB == BarIndex(),LPP));
LCP = Last_Confirmed_Price_Level		= IIf(Condition,LPP,LTP);
LCB = Last_Confirmed_BarIndex_Level		= IIf(Condition,LPB,LTB);

LNP = Last_Non_Confirmed_Price_Level    = LastValue(IIf(Condition,Lowest(ValueWhen(LPB <= Bi,L)),Highest(ValueWhen(LTB <= Bi,H))));
LNB = Last_Non_Confirmed_BarIndex_Level = LastValue(IIf(Condition,ValueWhen(LPB <= Bi AND L == LNP,Bi),ValueWhen(LTB <= Bi AND H == LNP,Bi)));

LA  = Last_Line			 				= LineArray(LCB,LCP,LNB,LNP);

Plot( LA ,"", colorLightYellow,  styleDashed|styleThick );or paste code here

Now the chart capture---
image

NOW THE ERROR;---

The Param setting for the fractal recognition I am using is "2", notice on the chart I have marked a DARK RED "X" at many places, this is because the fractal markings are wrong, in all cases the LEFT
STRENGTH is "1" and not "2" as selected using "Param".

Kindly help, I have thought about this over the weekend and have not been able to figure out why a fractal is being marked with LEFT STRENGTH =1, when "2" has been selected in the Param setting.

Thanks to all of u for helping with drawing the swing line (white line on chart), this needs further
refinement, I will try .

In the mean time kindly help with correct marking of fractals.

@Sebastian

The way you have written the code is absolutely excellent for a person like me, each line is very well explained, the code maybe a few lines longer, but from teaching point of view hats of to you !
Thanks a ton. :smile:

2 Likes

@Sebastion

Sorry to bother you again.

I am still having a problem with marking the fractals.

At numerous places the fractals are marking incorrectly.

I had posted this on the 18th but I think due to the sequence my post has been missed out- it is the 2nd last post (9/10).

Will be grateful if u can help.

@fxshrat

I am having a problem with the marking of fractals .

I had posted this on the 18th but maybe due to the sequence my post was missed out, kindly have a look , it is post 9/10 of this link.

Over the last year since I have been using this post for help have noticed your mastery over writing code.

Will be grateful if you can take a little time to provide a solution.

Thanks

No need to say this you are always welcome , the main point is that i don't understand what you want exactly , you complain about the fractal marks , but what is exactly the point that you try to address ?
How do you expect fractal marks to appear on the chart ?


I repeat my old request again , try to articulate your ideas in a clear obvious fluent writing style , please

The above statement is full of contradictions that make it hard for any reader to understand it properly ,you said at the beginning that Param setting that you are using is 2 , then in the end you said in all cases the left strength is 1 , How this could be ?!! -- see bold text --

Note that we are talking about EWRS variable , right ?

If you change the EWRS to equal one , it will plot fractal marks , represented in those small diamonds , for every bar on chart , and if you changed it to equal to 2 it will not give the same result.

Note that EWRS's minimum value allowed is two , so you can't assign 1 to that variable unless you change the value of the 3rd argument

@Sebastian
Thanks for your reply.
I have selected "2" as the Param value for ----

EWRS =EWLS =Param( "Strength",5, 2, 50, 1 );

BUT SOME FRACTALS PLOT WRONG, ie, the fractals plot as if "1" has been selected for the EWLS !

This is the mystery which I have been unable to solve !
There is another code which I use , based on the PROFITUNITY theory of Bill Williams - in this case dashed lines plot to mark fractal levels - AND THEY ARE CORRECT - with the same code I have been trying to mark the fractals with shapes instead of with lines - no success (my poor coding
knowledge), first the code ;

_SECTION_BEGIN("Fractals");

 
_SECTION_BEGIN("Price");
// CCI Bar color
tgt = 37;
a = CCI(20) < -tgt;
b = CCI(20) > tgt;
state = IIf(a>b,-1,IIf(a==b,0,1));
Color = IIf(state == 0, colorBlue, IIf(state == 1, colorGreen, IIf(state == -1, colorRed, 0)));
Plot( C, "Close", Color, styleNoTitle | styleBar | styleThick );
_SECTION_END();


// FRACTAL RECOGNITION
 //bars = Param(" Strength",2,13,2,1);

// Fractal Up
fUpA =
    ( Ref( H, -2 )  > Ref( H, -4 ) ) AND
    ( Ref( H, -2 )  > Ref( H, -3 ) ) AND
    ( Ref( H, -2 )  > Ref( H, -1 ) ) AND
    ( Ref( H, -2 )  > H );
 
fUpB =
    ( Ref( H, -2 )  > Ref( H, -5 ) ) AND
    ( Ref( H, -2 )  > Ref( H, -4 ) ) AND
    ( Ref( H, -2 ) == Ref( H, -3 ) ) AND
    ( Ref( H, -2 )  > Ref( H, -1 ) ) AND
    ( Ref( H, -2 )  > H );
 
fUpC =
    ( Ref( H, -2 )  > Ref( H, -6 ) ) AND
    ( Ref( H, -2 )  > Ref( H, -5 ) ) AND
    ( Ref( H, -2 ) == Ref( H, -4 ) ) AND
    ( Ref( H, -2 ) == Ref( H, -3 ) ) AND
    ( Ref( H, -2 )  > Ref( H, -1 ) ) AND
    ( Ref( H, -2 )  > H );
 
fUpD =
    ( Ref( H, -2 )  > Ref( H, -6 ) ) AND
    ( Ref( H, -2 )  > Ref( H, -5 ) ) AND
    ( Ref( H, -2 ) == Ref( H, -4 ) ) AND
    ( Ref( H, -2 )  > Ref( H, -3 ) ) AND
    ( Ref( H, -2 )  > Ref( H, -1 ) ) AND
    ( Ref( H, -2 )  > H );
 
fUpE =
    ( Ref( H, -2 )  > Ref( H, -8 ) ) AND
    ( Ref( H, -2 )  > Ref( H, -7 ) ) AND
    ( Ref( H, -2 ) == Ref( H, -6 ) ) AND
    ( Ref( H, -2 )  > Ref( H, -5 ) ) AND
    ( Ref( H, -2 ) == Ref( H, -4 ) ) AND
    ( Ref( H, -2 )  > Ref( H, -3 ) ) AND
    ( Ref( H, -2 )  > Ref( H, -1 ) ) AND
    ( Ref( H, -2 )  > H );
 
// Fractal Dn
fDnA =
    ( Ref( L, -2 )  < Ref( L, -4 ) ) AND
    ( Ref( L, -2 )  < Ref( L, -3 ) ) AND
    ( Ref( L, -2 )  < Ref( L, -1 ) ) AND
    ( Ref( L, -2 )  < L );
 
fDnB =
    ( Ref( L, -2 )  < Ref( L, -5 ) ) AND
    ( Ref( L, -2 )  < Ref( L, -4 ) ) AND
    ( Ref( L, -2 ) == Ref( L, -3 ) ) AND
    ( Ref( L, -2 )  < Ref( L, -1 ) ) AND
    ( Ref( L, -2 )  < L );
 
fDnC =
    ( Ref( L, -2 )  < Ref( L, -6 ) ) AND
    ( Ref( L, -2 )  < Ref( L, -5 ) ) AND
    ( Ref( L, -2 ) == Ref( L, -4 ) ) AND
    ( Ref( L, -2 ) == Ref( L, -3 ) ) AND
    ( Ref( L, -2 )  < Ref( L, -1 ) ) AND
    ( Ref( L, -2 )  < L );
 
fDnD =
    ( Ref( L, -2 )  < Ref( L, -6 ) ) AND
    ( Ref( L, -2 )  < Ref( L, -5 ) ) AND
    ( Ref( L, -2 ) == Ref( L, -4 ) ) AND
    ( Ref( L, -2 )  < Ref( L, -3 ) ) AND
    ( Ref( L, -2 )  < Ref( L, -1 ) ) AND
    ( Ref( L, -2 )  < L );
 
fDnE =
    ( Ref( L, -2 )  < Ref( L, -8 ) ) AND
    ( Ref( L, -2 )  < Ref( L, -7 ) ) AND
    ( Ref( L, -2 ) == Ref( L, -6 ) ) AND
    ( Ref( L, -2 )  < Ref( L, -5 ) ) AND
    ( Ref( L, -2 ) == Ref( L, -4 ) ) AND
    ( Ref( L, -2 )  < Ref( L, -3 ) ) AND
    ( Ref( L, -2 )  < Ref( L, -1 ) ) AND
    ( Ref( L, -2 )  < L );
 
FracUp    = ValueWhen( fUpE OR fUpD OR fUpC OR fUpB OR fUpA, Ref( H, -2 ), 0 );
FracDn   = ValueWhen( fDnE OR fDnD OR fDnC OR fDnB OR fDnA, Ref( L, -2 ), 0 );


FUP = IIf(fUpE OR fUpD OR fUpC OR fUpB OR fUpA, Ref( H, -2 ), 0 );
FDN = IIf(fDnE OR fDnD OR fDnC OR fDnB OR fDnA, Ref( L, -2 ), 0 );


Plot( FracUp , " | F Up", colorGrey40 ,  styleDashed );
Plot( FracDn , " | F Dn", colorOrange ,  styleDashed );
/*
// ///try windings/////
x =BarIndex();
FUPx = ValueWhen(FUP,x);
FUPy = ValueWhen(FUP,H));
xfonts = "Wingdings 3";
PlotTextSetFont( "$" , xfonts, 15, FUPx,FUPy, colorRed, colorDefault,10 );*/
PlotShapes(FUP*shapeDownTriangle, colorBlue,0, H,15,-2 );
PlotShapes(FDN*shapeDownTriangle, colorRed,0,  L,  -15,-2 );
 
_SECTION_END();

Now the screen capture:

image
Just like to say that basically I am trying to plot fractals (using Param for varying the strength)
and connect them with swing lines.

You mean that if you enter any different value from Param window to EWRS variable , there 's nothing gonna to change on your chart !!! This is really weird and strange , i don't have any reasonable explanation for this case.

try these two line

PlotShapes(FUP*shapeDownTriangle, colorLime,0,Ref(H,-2),-10,-2 );
PlotShapes(FDN*shapeDownTriangle, colorRed,0,  Ref(L,-2),-10,-2 );

you should use Ref() function , to refer to the the past two days for all high and low values as you are already using it in FUP and FDN