Pesavento Patterns

#11
Hi Traderji

Would anyone be kind enough to convert the TradeStation code below into Amibroker code?
See attached screenshot of TS S&P 500 Pesavento Pattern
Expand to full size for better color

Thank you in advance
Hoping that you can oblige

Best regards
Derek

Code:
Inputs:
// Parameters for ZigZag.

depth(50),
ExtDeviation(5),
ExtBackstep(3),
zigzagLinesColor(blue),

// Parameters for Pesavento Patterns.

ExtFractalEnd(10), // Number of Fractals (maximums and minimums), connected with Lines
ExtDelta (0.04), // max Percent of difference from Pessavento numbers
ExtLine (DarkBlue),
ExtLine886 (lightgray),
ExtNotFibo (darkgray),
ExtPesavento (Yellow),
ExtGartley886(Yellow);

//========================= ==========

Vars:
bar_resolution(0),

ExtLine_(0),

colorPPattern(green),

num_bar(0),
HL(0),
HLp(0),
kk(0),
kj(0),
Angle(0),

LowPrim(0),
HighPrim(0),
LowLast(0),
HighLast(0),

numLowPrim(0),
numHighPrim(0),
numLowLast(0),
numHighLast(0),

k(0),
k1(0),
k2(0),
ki(0),

kiPRZ(0),
countLow1(0),
countHigh1(0),

shift(0),
shift1(0),

txtkk(""),

countFr(0),
countBarEnd(0),
numBar(0),


// For ZigZag

back(0),
lasthighpos(0),
lastlowpos(0),
res(0),
curlow(0),
curhigh(0),
lasthigh(0),
lastlow(0),
i_var(0),
j_var(0);



Arrays:

double zz[1000](0),
double zzL[1000](0),
double zzH[1000](0),
_time[1000](0),

MyText[64](""),
number[64](0),
numbertxt[64](""),
numberGartley[64](0),
numberMix[64](0);


//---------------------------------------------------------------------//
//---------------------------------------------------------------------//
//---------------------------------------------------------------------//

if bartype=0 and lastbaronchart then value1=text_new( date, time,close+5," Only for minute charts and above");

if bartype>=1 then begin

if currentbar > 1000 then num_bar = 1000 else num_bar = currentbar;

//print(date, " ",time," ", num_bar); 
for i_var = 0 to ( num_bar - 1 )
begin
_time[i_var] = time[i_var];
end;


if ( LastCalcTime = time ) and ( LastCalcDate = date ) then

begin


if ( currentbar > depth ) then

begin


if (ExtDelta<=0) then raiseruntimeerror("ExtDel ta parameter should be >0 and <=1");
if (ExtDelta>1) then raiseruntimeerror("ExtDel ta parameter should be >0 and <=1");

if ( ExtFractalEnd <= 0 ) then raiseruntimeerror("ExtFra ctalEnd parameter should be >=1");


number [0]=0.111;
numbertxt [0]=".111";

number [1]=0.125;
numbertxt [1]=".125";
numberMix [1]=1;

number [2]=0.146;
numbertxt [2]=".146";

number [3]=0.167;
numbertxt [3]=".167";

number [4]=0.177;
numbertxt [4]=".177";

number [5]=0.186;
numbertxt [5]=".186";

number [6]=0.192;
numbertxt [6]=".192";

number [7]=0.2;
numbertxt [7]=".2";

number [8]=0.236;
numbertxt [8]=".236";
numberMix [8]=1;

number [9]=0.25;
numbertxt [9]=".25";

number [10]=0.3;
numbertxt [10]=".3";

number [11]=0.333;
numbertxt [11]=".333";

number [12]=0.354;
numbertxt [12]=".354";

number [13]=0.382;
numbertxt [13]=".382";
numberGartley [13]=1;

number [14]=0.447;
numbertxt [14]=".447";
numberGartley [14]=1;

number [15]=0.486;
numbertxt [15]=".486";

number [16]=0.5;
numbertxt [16]=".5";
numberGartley [16]=1;

number [17]=0.526;
numbertxt [17]=".526";

number [18]=0.577;
numbertxt [18]=".577";

number [19]=0.618;
numbertxt [19]=".618";
numberGartley [19]=1;

number [20]=0.667;
numbertxt [20]=".667";

number [21]=0.707;
numbertxt [21]=".707";
numberGartley [21]=1;

number [22]=0.764;
numbertxt [22]=".764";

number [23]=0.786;
numbertxt [23]=".786";
numberGartley [23]=1;

number [24]=0.809;
numbertxt [24]=".809";

number [25]=0.841;
numbertxt [25]=".841";

number [26]=0.854;
numbertxt [26]=".854";
numberMix [26]=1;

number [27]=0.874;
numbertxt [27]=".874";

number [28]=0.886;
numbertxt [28]=".886";
numberGartley [28]=1;

number [29]=1.0;
numbertxt [29]="1.";
numberGartley [29]=1;

number [30]=1.128;
numbertxt [30]="1.128";
numberGartley [30]=1;

number [31]=1.236;
numbertxt [31]="1.236";

number [32]=1.272;
numbertxt [32]="1.272";
numberGartley [32]=1;

number [33]=1.309;
numbertxt [33]="1.309";

number [34]=1.414;
numbertxt [34]="1.414";
numberGartley [34]=1;

number [35]=1.5;
numbertxt [35]="1.5";


number [36]=1.618;
numbertxt [36]="1.618";
numberGartley [36]=1;

number [37]=1.732;
numbertxt [37]="1.732";
numberMix [37]=1;


number [38]=1.75;
numbertxt [38]="1.75";

number [39]=1.902;
numbertxt [39]="1.902";
numberMix [39]=1;

number [40]=2.0;
numbertxt [40]="2.";
numberGartley [40]=1;

number [41]=2.058;
numbertxt [41]="2.058";

number [42]=2.236;
numbertxt [42]="2.236";
numberGartley [42]=1;

number [43]=2.288;
numbertxt [43]="2.288";

number [44]=2.5;
numbertxt [44]="2.5";

number [45]=2.618;
numbertxt [45]="2.618";
numberGartley [45]=1;

number [46]=2.828;
numbertxt [46]="2.828";

number [47]=3.0;

number [48]=3.142;
numbertxt [48]="3.142";
numberGartley [48]=1;

number [49]=3.236;
numbertxt [49]="3.236";

number [50]=3.33;
numbertxt [50]="3.33";

number [51]=3.464;
numbertxt [51]="3.464";

number [52]=3.618;
numbertxt [52]="3.618";
numberGartley [52]=1;

number [53]=4.0;
numbertxt [53]="4.";

number [54]=4.236;
numbertxt [54]="4.236";

number [55]=4.472;
numbertxt [55]="4.472";

number [56]=5.0;
numbertxt [56]="5.";

number [57]=5.2;
numbertxt [57]="5.2";

number [58]=5.388;
numbertxt [58]="5.388";

number [59]=5.657;
numbertxt [59]="5.657";

number [60]=6.0;
numbertxt [60]="6.";

number [61]=6.854;
numbertxt [61]="6.854";

number [62]=8.0;
numbertxt [62]="8.";

number [63]=9.0;
numbertxt [63]="9.";


value1 = 0; 
lasthighpos = -1;
lastlowpos = -1;
res = 0;
curlow = -1;
curhigh = -1;
lasthigh = -1;
lastlow = -1;


// ZigZag plotting. Begin.


for shift = ( num_bar - 1 ) downto 0
begin
zz[shift] = 0; 
zzL[shift] = 0; 
zzH[shift] = 0;
end;

for shift = ( num_bar - depth ) downto 0
begin
value1 = Low[ LowestBar(low, depth)[shift] ];
if (value1 = lastlow) then value1 = 0.0
else 
begin 
lastlow = value1; 
if ( ( Low[shift] - value1 ) > extdeviation*PointValue ) then value1 = 0.0
else
begin
for back = 1 to extbackstep
begin
res = zzL[shift+back];
if ( ( res <> 0 ) and ( res > value1 ) ) then zzL[shift+back] = 0.0; 
end;
end;
end; 
if ( Low[shift] = value1 ) then zzL[shift] = value1;

value1 = High[ HighestBar(high, depth)[shift] ];
if ( value1 = lasthigh ) then value1 = 0.0
else 
begin
lasthigh = value1;
if ( ( value1 - High[shift] ) > extdeviation*pointValue ) then value1 = 0.0
else
begin
for back = 1 to extbackstep
begin
res = zzH[shift+back];
if ( ( res <> 0 ) and ( res < value1 ) ) then zzH[shift+back] = 0.0; 
end; 
end;
end;
if ( High[shift] = value1 ) then zzH[shift] = value1;
end;

lasthigh = -1; 
lasthighpos = -1;
lastlow = -1;  
lastlowpos = -1;

for shift = (num_bar - depth) downto 0
begin
curlow = zzL[shift];
curhigh = zzH[shift];
if ( ( curlow = 0 ) and ( curhigh = 0 ) ) then
//else
begin

if ( curhigh <> 0 ) then
begin
if ( lasthigh > 0 ) then
begin
if (lasthigh < curhigh ) then zzH[lasthighpos] = 0
else zzH[shift] = 0;
end;

if ( (lasthigh < curhigh) or (lasthigh < 0) ) then
begin
lasthigh = curhigh;
lasthighpos = shift;
end;
lastlow = -1;
end;

if ( curlow <> 0 ) then
begin
if ( lastlow > 0 ) then
begin
if ( lastlow > curlow ) then zzL[lastlowpos] = 0
else zzL[shift] = 0;
end;

if ( ( curlow < lastlow ) or ( lastlow < 0 ) ) then
begin
lastlow = curlow;
lastlowpos = shift;
end; 
lasthigh = -1;
end;
end;
end;

for shift = num_bar - 1 downto 0
begin
zz[shift] = zzL[shift];
if ( shift >= num_bar-depth ) then
begin
zzH[shift] = 0.0; 
zzL[shift] = 0.0; 
zz[shift] = 0.0;
end
else
begin
res = zzH[shift];
if ( res <> 0.0 ) then zz[shift] = res;  
end;
end;


// Check for humpbacks and their removing. Begin.

vars: vel1(0), 
vel2(0),
vel3(0), 
vel4(0),
bar_(0),
bar1(0), 
bar2(0), 
bar3(0), 
bar4(0),
count_(0);

for bar_ = ( num_bar - depth ) downto 0
begin
if ( zz[bar_] <> 0 ) then
begin
count_ = count_ + 1;
vel4 = vel3;
bar4 = bar3;
vel3 = vel2;
bar3 = bar2;
vel2 = vel1;
bar2 = bar1;
vel1 = zz[bar_];
bar1 = bar_;
if ( count_>=3 ) then
begin 
if ( ( vel3 < vel2 ) and ( vel2 < vel1 ) ) then
begin
zz[bar2] = 0;
zzL[bar2] = 0;
zzH[bar2] = 0;
bar_ = bar3 + 1;
end;
if ( ( vel3 > vel2 ) and ( vel2 > vel1 ) ) then
begin
zz[bar2] = 0;
zzL[bar2] = 0;
zzH[bar2] = 0;
bar_ = bar3 + 1;
end;
if ( ( vel2 = vel1 ) and ( vel1 <> 0 ) ) then
begin
zz[bar1] = 0;
zzL[bar1] = 0;
zzH[bar1] = 0;
bar_ = bar3 + 1;
end;
end;
end;
end; 

// Check for humpbacks and their removing. End.


value1 = 0;
{
i_var = 1;
while(i_var > 0)
begin
i_var = tl_getfirst(1);
tl_delete(i_var);
end;}


for shift = (num_bar - 1) downto 0
begin
if zz[shift] <> 0 then
begin
if (value1 <> 0) then 
begin
value11 = date[value2];
value12 = time[value2];
value13 = value1;
value21 = date[shift];
value22 = time[shift];
value23 = zz[shift];  

j_var = TL_new(value11, value12, value13, value21, value22, value23);	
tl_setcolor(j_var, zigzagLinesColor);	

//Plot1 [shift](value23);
//Print(value11, " ",value12, " ",value13, " ",value21, " ",value22, " ",value23, " ");





end;
value1 = zz[shift];
value2 = shift; 
end;
end;
// ZigZag plotting. End.


if ( ExtFractalEnd > 0) then
begin
k = ExtFractalEnd;
for shift = 0 to num_bar 
begin 
if ( zz[shift] > 0 and zzH[shift] > 0 ) then
begin 
if k > 0 then
begin
countBarEnd = shift; 
k = k - 1;
end;
end;
end;
end;


// count Fractal ( count maximums and minimums ). Begin.

countLow1 = 0;
countHigh1 = 0;
begin
for shift = 0 to countBarEnd
begin
if (zzL[shift] > 0.0) then countLow1 = countLow1 + 1;
if (zzH[shift] > 0.0) then countHigh1 = countHigh1 + 1;
end;
end;

// count Fractal ( count maximums and minimums ). End.


{i_var = 1;
while(i_var > 0)
begin
i_var = text_getfirst(1);
text_delete(i_var);
end;}

//+--------------------------------------------------------------------------+
//| printing Pessavento and 0.886 for maximums of ZigZag
//+--------------------------------------------------------------------------+

numLowPrim = 0; 
numLowLast = 0;
numHighPrim = 0; 
numHighLast = 0;

LowPrim = 0.0; 
LowLast = 0.0;
HighPrim = 0.0; 
HighLast = 0.0;

Angle = -100;


countFr = ExtFractalend;

for k = 0 to ( num_bar - 1 )
begin
if ( countHigh1 > 0 and countFr > 0 ) then
begin

if ( zzL[k] > 0.0 and ( zzL[k] < LowPrim or LowPrim = 0.0 ) 
and HighPrim > 0 and zzL[k] = zz[k] ) then
begin
LowPrim = Low[k]; 
numLowPrim = k;
end;
if ( zzH[k] > 0.0 and zzH[k] = zz[k] ) then
begin
if ( HighPrim > 0 ) then
begin

HighLast = High[k];
numHighLast = k;

HL = HighLast - LowPrim;
kj = (HighPrim-HighLast)*1000/(numHighLast-numHighPrim);
if ( HL > 0 and ( Angle >= kj or Angle = -100 ) ) then
begin
Angle = kj;

HLp = HighPrim - LowPrim;
k1 = ceiling((numHighPrim+numHighLast)/2);
kj = HLp/HL;

ExtLine_ = ExtLine;
if ( kj > 0.1 and kj < 9.36 ) then
begin
kk = kj;
k2 = 1;


ki = 0;
colorPPattern = ExtNotFibo;
ki = kiPRZ;
condition1 = true;

while (ki <= 63) and (condition1)
begin
if ( numberGartley[ki] > 0 ) then
if ( absvalue((number[ki]-kj)/number[ki]) <= ExtDelta ) then
begin
kk = number[ki]; 
txtkk = numbertxt[ki]; 
k2 = -1; 
colorPPattern = ExtGartley886;
condition1 = false;
end
else if ( numberMix[ki] > 0 ) then
if ( absvalue((number[ki]-kj)/number[ki]) <= ExtDelta ) then
begin
kk = number[ki]; 
txtkk = numbertxt[ki]; 
k2 = -1; 
colorPPattern = ExtPesavento; 
condition1 = false;
end;
ki = ki + 1;
end;


if ( k2 < 0 ) then
begin
ExtLine_ = ExtLine886;
i_var = text_new(d[k1], time[k1], (HighPrim+highlast)/2, txtkk);
text_setcolor(i_var, colorPpattern);
//text_setsize(i_var, 8);
end
else
begin
txtkk = numtostr(kk, 3);
i_var = text_new(d[k1], time[k1], (HighPrim+highlast)/2, txtkk);
text_setcolor(i_var, colorPpattern);
//text_setsize(i_var, 8);
end;

i_var = tl_new(d[numHighLast], time[numHighLast], HighLast, d[numHighPrim], time[numHighPrim], HighPrim);
tl_setstyle(i_var, 3);
tl_setcolor(i_var, extline_);

end;
end;
end
else 
begin
HighPrim = High[k];
numHighPrim = k;
end;
end;

if ( k > countBarEnd ) then 
begin
k = numHighPrim + 1; 
countHigh1 = countHigh1 - 1; 
countFr = countFr - 1;

numLowPrim = 0; 
numLowLast = 0;
numHighPrim = 0; 
numHighLast = 0;

LowPrim = 0.0; 
LowLast = 0.0;
HighPrim = 0.0; 
HighLast = 0.0;

Angle = -100;
end;

end;
end;

//+-------------------------------------------------------------------------+
//| printing Pessavento and 0.886 for minimums of ZigZag
//+-------------------------------------------------------------------------+

numLowPrim = 0; 
numLowLast = 0;
numHighPrim = 0; 
numHighLast = 0;

LowPrim = 0.0; 
LowLast = 0.0;
HighPrim = 0.0; 
HighLast = 0.0;

Angle = -100;


countFr = ExtFractalend;

for k = 0 to ( num_bar - 1 )
begin 
if ( countLow1 > 0 and countFr > 0 ) then
begin
if ( zzH[k] > HighPrim and LowPrim > 0 ) then
begin
HighPrim = High[k];
numHighPrim = k;
end;

if ( zzL[k] > 0.0 and zzL[k] = zz[k] ) then
begin
if ( LowPrim > 0 ) then
begin

LowLast = Low[k];
numLowLast = k;

HL = HighPrim - LowLast;
kj = (LowPrim-LowLast)*1000/(numLowLast-numLowPrim);
if ( HL > 0 and ( Angle <= kj or Angle = -100)) then
begin
Angle = kj;

HLp = HighPrim-LowPrim;
k1 = ceiling((numLowPrim+numLowLast)/2);
kj = HLp/HL;

ExtLine_ = ExtLine;
if ( kj > 0.1 and kj < 9.36) then
begin
kk = kj;
k2 = 1;


ki = 0;
colorPPattern = ExtNotFibo;
ki = kiPRZ;
condition1 = true;

while (ki <= 63) and (condition1)
begin
if ( numberGartley[ki] > 0 ) then
if ( absvalue((number[ki]-kj)/number[ki]) <= ExtDelta ) then
begin
kk = number[ki]; 
txtkk = numbertxt[ki]; 
k2 = -1; 
colorPPattern = ExtGartley886;
condition1 = false;
end
else if ( numberMix[ki] > 0 ) then
if ( absvalue((number[ki]-kj)/number[ki]) <= ExtDelta ) then
begin
kk = number[ki]; 
txtkk = numbertxt[ki]; 
k2 = -1; 
colorPPattern = ExtPesavento; 
condition1 = false;
end;
ki = ki + 1;
end;



if ( k2 < 0 ) then
begin
ExtLine_ = ExtLine886;
i_var = text_new(d[k1], time[k1], (lowprim+lowlast)/2, txtkk);
text_setcolor(i_var, colorPpattern);
//text_setsize(i_var, 8);
end
else 
begin 
txtkk = NumToStr(kk, 3);
i_var = text_new(d[k1], time[k1], (lowprim+lowlast)/2, txtkk);
text_setcolor(i_var, colorPpattern);
//text_setsize(i_var, 8);
end;

i_var = tl_new(d[numlowlast], time[numlowlast], lowLast, d[numlowPrim], time[numlowPrim], lowPrim);
tl_setstyle(i_var, 3);
tl_setcolor(i_var, extline_);

end;
end;
end
else
begin
numLowPrim = k; 
LowPrim = Low[k];
end;
end;

if (k > countBarEnd) then
begin
k = numLowPrim + 1; 
countLow1 = countLow1 - 1; 
countFr = countFr - 1;

numLowPrim = 0; 
numLowLast = 0;
numHighPrim = 0; 
numHighLast = 0;

LowPrim = 0.0; 
LowLast = 0.0;
HighPrim = 0.0; 
HighLast = 0.0;

Angle = -100;
end;

end;
end;


end;


end;
end; //end bartype
 

Attachments

monkeybusiness

Well-Known Member
#12
Hi Traderji

Would anyone be kind enough to convert the TradeStation code below into Amibroker code?
See attached screenshot of TS S&P 500 Pesavento Pattern
Expand to full size for better color

Thank you in advance
Hoping that you can oblige

Best regards
Derek

[/CODE]
Ed Pottasch & Joy Edakad AFL

Code:
/*                     HARMONIC PATTERN DETECTION

Automatic Detection of Harmonic Patterns - Gartley, Bat, Butterfly and Crab.

Zig Zag is not used in this AFL. It is based on fractals

Contact - [email protected]

Modernized by E.M.Pottasch (Dec 2016).
- All calculations by the original author left as they were.
- Improved visualisation of the patterns.
- Adjusted names of variables, constants and arrays, adapted
	using code from David Keleher.

The code I used is the original code from:
http://www.***********.com/amibroker/1934-afl-harmonic-patterns.html
file: Harmonic1.1.afl (2009)  */

Version( 6.0 );
GfxSetCoordsMode( 1 );
GfxSetOverlayMode( 1 );

BullBat4 = BullButterfly4 = BullCrab4 = BullGartley4 = 0;
BullBat = BullButterfly = BullCrab = BullGartley = 0;
BearBat4 = BearButterfly4 = BearCrab4 = BearGartley4 = 0;
BearBat = BearButterfly = BearCrab = BearGartley = 0;

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

GraphXSpace = 0;
SetChartBkColor( colorBlack );
SetChartOptions( 1, chartShowDates, chartGridMiddle, 0, 0, 0 );
SetBarFillColor( IIf( C > O, ColorRGB( 0, 75, 0 ), IIf( C <= O, ColorRGB( 75, 0, 0 ), colorLightGrey ) ) );
Plot( C, "", IIf( C > O, ColorRGB( 0, 255, 0 ), IIf( C <= O, ColorRGB( 255, 0, 0 ), colorLightGrey ) ), 64, Null, Null, 0, 0, 1 );

_SECTION_BEGIN( "Patterns" );
rightstrength = Param( "Right Strength", 5, 2, 50, 1 );
leftstrength = Param( "Left Strength", 10, 2, 50, 1 );
plotFractals = ParamToggle( "Show Fractal Pivots", "Off|On", 0 );
plotLabels = ParamToggle( "Show Fractal Labels", "Off|On", 0 );
bu = ParamToggle( "Show Bullish Pattern", "Off|On", 1 );
be = ParamToggle( "Show Bearish Pattern", "Off|On", 1 );
nBull = Param( "Max Number of Bullish Patterns", 10, 0, 100, 1 );
nBear = Param( "Max Number of Bearish Patterns", 10, 0, 100, 1 );
dBat = ParamToggle( "Draw Bat", "Off|On", 1 );
dBut = ParamToggle( "Draw Buterfly", "Off|On", 1 );
dCrab = ParamToggle( "Draw Crab", "Off|On", 1 );
dGart = ParamToggle( "Draw Gartley", "Off|On", 1 );
showPatternDevelopmentPoints = ParamToggle( "Show Points of Pattern Development", "Off|On", 0 );
showPatternLabels = ParamToggle( "Show Pattern Labels", "Off|On", 0 );
_SECTION_END();

_SECTION_BEGIN( "Gartley" );
GBmin = Param( "Swing B Min.", 0.55, 0.3, 1, 0.01 );
GBmax = Param( "Swing B Max.", 0.72, 0.4, 1, 0.01 );
GCmin = Param( "Swing C Min.", 0.38, 0.3, 1.27, 0.01 );
GCmax = Param( "Swing C Max.", 1.0, 0.4, 1.27, 0.01 );
GDmin = Param( "Swing D Min.(XA)", 0.55, 0.3, 1, 0.01 );
GDmax = Param( "Swing D Max.(XA)", 1.0, 0.4, 1.0, 0.01 );
_SECTION_END();

_SECTION_BEGIN( "Bat" );
BatBmin = Param( "Swing B Min.", 0.38, 0.3, 1, 0.01 );
BatBmax = Param( "Swing B Max.", 0.55, 0.4, 1, 0.01 );
BatCmin = Param( "Swing C Min.", 0.38, 0.3, 1.62, 0.01 );
BatCmax = Param( "Swing C Max.", 1.27, 0.4, 1.62, 0.01 );
BatDmin = Param( "Swing D Min.(XA)", 0.5, 0.3, 1, 0.01 );
BatDmax = Param( "Swing D Max.(XA)", 1.0, 0.4, 1.0, 0.01 );
_SECTION_END();

_SECTION_BEGIN( "Butterfly" );
BtBmin = Param( "Swing B Min.", 0.55, 0.3, 1, 0.01 );
BtBmax = Param( "Swing B Max.", 0.9, 0.4, 1, 0.01 );
BtCmin = Param( "Swing C Min.", 0.38, 0.3, 1.62, 0.01 );
BtCmax = Param( "Swing C Max.", 1.27, 0.4, 1.62, 0.01 );
BtDmin = Param( "Swing D Min.(XA)", 1, 1, 1.8, 0.01 );
BtDmax = Param( "Swing D Max.(XA)", 1.38, 1, 1.8, 0.01 );
_SECTION_END();

_SECTION_BEGIN( "Crab" );
CBmin = Param( "Swing B Min.", 0.38, 0.3, 1, 0.01 );
CBmax = Param( "Swing B Max.", 0.65, 0.4, 1, 0.01 );
CCmin = Param( "Swing C Min.", 0.38, 0.3, 1.62, 0.01 );
CCmax = Param( "Swing C Max.", 1.270, 0.4, 1.62, 0.01 );
CDmin = Param( "Swing D Min.(XA)", 1.25, 1, 1.8, 0.01 );
CDmax = Param( "Swing D Max.(XA)", 1.8, 1, 2, 0.01 );
_SECTION_END();

function GetTop()
{
    Top = H == HHV( H, leftstrength ) AND Ref( HHV( H, rightstrength ), rightstrength ) < H;
    Top = Top AND LastValue( bi ) - ValueWhen( Top, bi ) > rightstrength;
    return Top;
}

function GetValley()
{
    Valley = L == LLV( L, leftstrength ) AND Ref( LLV( L, rightstrength ), rightstrength ) > L;
    Valley = Valley AND LastValue( bi ) - ValueWhen( Valley, bi ) > rightstrength;
    return Valley;
}

pk = GetTop();
tr = GetValley();

pk = IIf( pk, IIf( ValueWhen( pk, bi, 2 ) < ValueWhen( tr, bi ), pk, IIf( ValueWhen( pk, H, 2 ) > H, False, pk ) ), pk );
pk = IIf( pk AND ValueWhen( pk, bi, 0 ) > bi, IIf( ValueWhen( pk, bi, 0 ) < ValueWhen( tr, bi, 0 ), IIf( ValueWhen( pk, H, 0 ) >= H, False, pk ), pk ), pk );
tr = IIf( tr, IIf( ValueWhen( tr, bi, 2 ) < ValueWhen( pk, bi ), tr, IIf( ValueWhen( tr, L, 2 ) < L, False, tr ) ), tr );
tr = IIf( tr AND ValueWhen( tr, bi, 0 ) > bi , IIf( ValueWhen( tr, bi, 0 ) < ValueWhen( pk, bi, 0 ), IIf( ValueWhen( tr, L, 0 ) <= L, False, tr ), tr ), tr );

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

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

if( PlotFractals )
{
    PlotShapes( shapeSmallCircle * pk, colorRed, 0, H, 10 );
    PlotShapes( shapeSmallCircle * tr, colorBlue, O, L, -10 );
}

// +++ Bullish Patterns
PTvalid = ( px1 > tx1 AND tx1 > px2 AND px2 > tx2 ) AND pk;

if( dGart AND bu )
{
    BullGartley4 = PTvalid AND( ph2 - tl1 ) / ( ph2 - tl2 ) > GBmin AND( ph2 - tl1 ) / ( ph2 - tl2 ) < GBmax
                   AND( ph1 - tl1 ) / ( ph2 - tl1 ) > GCMin AND( ph1 - tl1 ) / ( ph2 - tl1 ) < GCMax;
    BullGartley = IIf( LowestSince( BullGartley4, L ) < ValueWhen( BullGartley4, ph2 ) - ( ValueWhen( BullGartley4, ph2 ) - ValueWhen( BullGartley4, tl2 ) ) * GDmin AND
                       LowestSince( bullGartley4, L ) > ValueWhen( BullGartley4, ph2 ) - ( ValueWhen( BullGartley4, ph2 ) - ValueWhen( BullGartley4, tl2 ) ) * GDmax AND
                       HighestSince( BullGartley4, H ) <= ValueWhen( BullGartley4, ph1 ) AND
                       LowestSince( bullGartley4, L ) == L, True, False );
    BullGartley = BullGartley AND LowestSince( BullGartley4, L ) < ValueWhen( BullGartley4, tl1 );
}

if( dBat AND bu )
{
    BullBat4 = PTvalid AND( ph2 - tl1 ) / ( ph2 - tl2 ) > BatBmin AND( ph2 - tl1 ) / ( ph2 - tl2 ) < BatBmax
               AND( ph1 - tl1 ) / ( ph2 - tl1 ) > BatCMin AND( ph1 - tl1 ) / ( ph2 - tl1 ) < BatCMax;
    BullBat = IIf( LowestSince( BullBat4, L ) < ValueWhen( BullBat4, ph2 ) - ( ValueWhen( BullBat4, ph2 ) - ValueWhen( BullBat4, tl2 ) ) * BatDmin AND
                   LowestSince( BullBat4, L ) > ValueWhen( BullBat4, ph2 ) - ( ValueWhen( BullBat4, ph2 ) - ValueWhen( BullBat4, tl2 ) ) * BatDmax AND
                   HighestSince( BullBat4, H ) <= ValueWhen( BullBat4, ph1 ) AND
                   LowestSince( BullBat4, L ) == L, True, False );
    BullBat = BullBat AND LowestSince( BullCrab4, L ) < ValueWhen( BullCrab4, tl1 );
}

if( dBut AND bu )
{
    BullButterfly4 = PTvalid AND( ph2 - tl1 ) / ( ph2 - tl2 ) > BtBmin AND( ph2 - tl1 ) / ( ph2 - tl2 ) < BtBMax
                     AND( ph1 - tl1 ) / ( ph2 - tl1 ) > BtCmin AND( ph1 - tl1 ) / ( ph2 - tl1 ) < BtCmax;
    BullButterfly = IIf( LowestSince( BullButterfly4, L ) < ValueWhen( BullButterfly4, ph2 ) - ( ValueWhen( BullButterfly4, ph2 ) - ValueWhen( BullButterfly4, tl2 ) ) * BtDMin AND
                         LowestSince( BullButterfly4, L ) > ValueWhen( BullButterfly4, ph2 ) - ( ValueWhen( BullButterfly4, ph2 ) - ValueWhen( BullButterfly4, tl2 ) ) * BtDmax AND
                         HighestSince( BullButterfly4, H ) <= ValueWhen( BullButterfly4, ph1 ) AND
                         LowestSince( bullButterfly4, L ) == L, True, False );
    BullButterfly = BullButterfly AND LowestSince( BullButterfly4, L ) < ValueWhen( BullButterfly4, tl2 );
}

if( dCrab AND bu )
{
    BullCrab4 = PTvalid AND( ph2 - tl1 ) / ( ph2 - tl2 ) > CBmin AND( ph2 - tl1 ) / ( ph2 - tl2 ) < CBmax
                AND( ph1 - tl1 ) / ( ph2 - tl1 ) > CCmin AND( ph1 - tl1 ) / ( ph2 - tl1 ) < CCmax;
    BullCrab = IIf( LowestSince( BullCrab4, L ) < ValueWhen( BullCrab4, ph2 ) - ( ValueWhen( BullCrab4, ph2 ) - ValueWhen( BullCrab4, tl2 ) ) * CDmin AND
                    LowestSince( BullCrab4, L ) > ValueWhen( BullCrab4, ph2 ) - ( ValueWhen( BullCrab4, ph2 ) - ValueWhen( BullCrab4, tl2 ) ) * CDmax AND
                    HighestSince( BullCrab4, H ) <= ValueWhen( BullCrab4, ph1 ) AND
                    LowestSince( bullGartley4, L ) == L, True, False );
    BullCrab = BullCrab AND LowestSince( BullCrab4, L ) < ValueWhen( BullCrab4, tl2 );
}

BullHar4 = BullGartley4 OR BullButterfly4 OR BullBat4 OR BullCrab4 ;
BullHar = BullGartley OR BullButterfly OR BullBat OR BullCrab ;

buXy = ValueWhen( BullHar4, tl2 );
buXx = ValueWhen( BullHar4, tx2 );
buAy = ValueWhen( BullHar4, ph2 );
buAx = ValueWhen( BullHar4, px2 );
buBy = ValueWhen( BullHar4, tl1 );
buBx = ValueWhen( BullHar4, tx1 );
buCy = ValueWhen( BullHar4, ph1 );
buCx = ValueWhen( BullHar4, px1 );
buDy = ValueWhen( BullHar, L );
buDx = ValueWhen( BullHar, bi );

buABdXA = ( buAy - buBy ) / ( buAy - buXy );
buBCdAB = ( buCy - buBy ) / ( buAy - buBy );
buADdXA = ( buAy - buDy ) / ( buAy - buXy );
buBCdCD = ( buCy - buDy ) / ( buCy - buBy );

function drawBullishPattern( i, patternName )
{
    GfxSelectSolidBrush( ColorRGB( 0, 0, 50 ) );
    GfxSetBkColor( colorBlack );
    GfxSelectPen( ColorRGB( 0, 0, 255 ), 2, 0 );
    GfxMoveTo( buXx[i], buXy[i] );
    GfxLineTo( buAx[i], buAy[i] );
    GfxMoveTo( buAx[i], buAy[i] );
    GfxLineTo( buBx[i], buBy[i] );
    GfxMoveTo( buBx[i], buBy[i] );
    GfxLineTo( buCx[i], buCy[i] );
    GfxMoveTo( buCx[i], buCy[i] );
    GfxLineTo( buDx[i], buDy[i] );
    GfxMoveTo( buXx[i], buXy[i] );
    GfxLineTo( buAx[i], buAy[i] );

    GfxSelectPen( ColorRGB( 0, 0, 255 ), 1, 2 );
    GfxMoveTo( buXx[i], buXy[i] );
    GfxLineTo( buBx[i], buBy[i] );
    GfxMoveTo( buAx[i], buAy[i] );
    GfxLineTo( buCx[i], buCy[i] );
    GfxMoveTo( buBx[i], buBy[i] );
    GfxLineTo( buDx[i], buDy[i] );
    GfxMoveTo( buXx[i], buXy[i] );
    GfxLineTo( buDx[i], buDy[i] );

    GfxPolygon( buXx[i], buXy[i], buAx[i], buAy[i], buBx[i], buBy[i], buCx[i], buCy[i], buDx[i], buDy[i], buBx[i], buBy[i], buXx[i], buXy[i] );

    GfxSetTextColor( ColorRGB( 0, 0, 0 ) );
    GfxSelectFont( "Helvetica", 10, 700 );
    GfxSetBkColor( ColorRGB( 0, 0, 255 ) );
    GfxSetTextAlign( 0 | 8 );
    GfxTextOut( patternName, buCx[i] + 3, buCy[i] );

    GfxSetTextAlign( 0 | 0 );
    GfxSetTextColor( ColorRGB( 0, 0, 255 ) );
    GfxSetBkColor( ColorRGB( 0, 0, 0 ) );
    GfxSelectFont( "Helvetica", 8, 700 );
    GfxTextOut( "" + Prec( buABdXA[i], 2 ), ( buBx[i] + buXx[i] ) / 2, ( buBy[i] + buXy[i] ) / 2 );
    GfxTextOut( "" + Prec( buBCdAB[i], 2 ), ( buCx[i] + buAx[i] ) / 2, ( buCy[i] + buAy[i] ) / 2 );
    GfxTextOut( "" + Prec( buADdXA[i], 2 ), ( buDx[i] + buXx[i] ) / 2, ( buDy[i] + buXy[i] ) / 2 );
    GfxTextOut( "" + Prec( buBCdCD[i], 2 ), ( buBx[i] + buDx[i] ) / 2, ( buBy[i] + buDy[i] ) / 2 );

    if( showPatternLabels )
    {
        GfxSetTextColor( ColorRGB( 0, 0, 0 ) );
        GfxSelectFont( "Helvetica", 10, 700 );
        GfxSetBkColor( ColorRGB( 0, 0, 255 ) );
        GfxSetTextAlign( 0 | 24 );
        GfxTextOut( "X", buXx[i] - 2, buXy[i] );
        GfxTextOut( "A", buAx[i] - 2, buAy[i] );
        GfxTextOut( "B", buBx[i] - 2, buBy[i] );
        GfxTextOut( "C", buCx[i] + 1, buCy[i] );
        GfxTextOut( "D", buDx[i] + 1, buDy[i] );
    }
}

function drawBullishPatterns()
{
    flag1 = 1;
    flag2 = 0;
    cnt = 0;

    for( i = lvb; i > fvb; i-- )
    {
        if( BullHar[i] AND flag1 AND cnt < nBull )
        {
            flag1 = 0;
            flag2 = 1;
            cnt = cnt + 1;

            if( BullButterfly[i] AND bu AND dBut )
            {
                drawBullishPattern( i, "Bullish Butterfly" );
            }
            else
                if( BullCrab[i] AND bu AND dCrab )
                {
                    drawBullishPattern( i, "Bullish Crab" );
                }
                else
                    if( BullBat[i] AND bu AND dBat )
                    {
                        drawBullishPattern( i, "Bullish Bat" );
                    }
                    else
                        if( BullGartley[i] AND bu AND dGart )
                        {
                            drawBullishPattern( i, "Bullish Gartley" );
                        }
        }

        if( BullHar4[i] AND flag2 )
        {
            flag1 = 1;
            flag2 = 0;
        }
    }
}
drawBullishPatterns();

// +++ Bearish Patterns
PTvalid = ( tx1 > px1 AND px1 > tx2 AND tx2 > px2 ) AND tr;

if( dGart AND be )
{
    BearGartley4 = PTvalid AND( ph1 - tl2 ) / ( ph2 - tl2 ) > GBmin AND( ph1 - tl2 ) / ( ph2 - tl2 ) < GBmax AND
                   ( ph1 - tl1 ) / ( ph1 - tl2 ) > GCmin AND( ph1 - tl1 ) / ( ph1 - tl2 ) < GCmax;
    BearGartley = IIf( HighestSince( bearGartley4, H ) > ValueWhen( BearGartley4, tl2 ) + ( ValueWhen( BearGartley4, ph2 ) - ValueWhen( BearGartley4, tl2 ) ) * GDmin AND
                       HighestSince( bearGartley4, H ) < ValueWhen( BearGartley4, tl2 ) + ( ValueWhen( BearGartley4, ph2 ) - ValueWhen( BearGartley4, tl2 ) ) * GDMax AND
                       LowestSince( BearGartley4, L ) >= ValueWhen( BearGartley4, tl1 ) AND
                       HighestSince( BearGartley4, H ) == H, True, False );
    BearGartley = BearGartley AND HighestSince( BearGartley4, H ) > ValueWhen( BearGartley4, ph1 );
}

if( dBat AND be )
{
    BearBat4 = PTvalid AND( ph1 - tl2 ) / ( ph2 - tl2 ) > BatBmin AND( ph1 - tl2 ) / ( ph2 - tl2 ) < BatBmax AND
               ( ph1 - tl1 ) / ( ph1 - tl2 ) > BatCmin AND( ph1 - tl1 ) / ( ph1 - tl2 ) < BatCmax;
    BearBat = IIf( ( HighestSince( BearBat4, H ) > ValueWhen( BearBat4, tl2 ) + ( ValueWhen( BearBat4, ph2 ) - ValueWhen( BearBat4, tl2 ) ) * BatDmin AND
                     HighestSince( BearBat4, H ) < ValueWhen( BearBat4, tl2 ) + ( ValueWhen( BearBat4, ph2 ) - ValueWhen( BearBat4, tl2 ) ) * BatDMax AND
                     LowestSince( BearBat4, L ) >= ValueWhen( BearBat4, tl1 ) AND
                     HighestSince( BearBat4, H ) == H ), True, False );
    BearBat = BearBat AND HighestSince( BearBat4, H ) > ValueWhen( BearBat4, ph1 );
}

if( dBut AND be )
{
    BearButterfly4 = PTvalid AND( ph1 - tl2 ) / ( ph2 - tl2 ) > BtBmin AND( ph1 - tl2 ) / ( ph2 - tl2 ) < BtBmax AND
                     ( ph1 - tl1 ) / ( ph1 - tl2 ) > BtCmin AND( ph1 - tl1 ) / ( ph1 - tl2 ) < BtCmax;
    BearButterfly = IIf( HighestSince( BearButterfly4, H ) > ValueWhen( BearButterfly4, tl2 ) + ( ValueWhen( BearButterfly4, ph2 ) - ValueWhen( BearButterfly4, tl2 ) ) * BtDmin AND
                         HighestSince( BearButterfly4, H ) < ValueWhen( BearButterfly4, tl2 ) + ( ValueWhen( BearButterfly4, ph2 ) - ValueWhen( BearButterfly4, tl2 ) ) * BtDMax AND
                         LowestSince( BearButterfly4, L ) >= ValueWhen( BearButterfly4, tl1 ) AND
                         HighestSince( BearButterfly4, H ) == H, True, False );
    BearButterfly = BearButterfly AND HighestSince( BearButterfly4, H ) > ValueWhen( BearButterfly4, ph2 );
}

if( dCrab AND be )
{
    BearCrab4 = PTvalid AND( ph1 - tl2 ) / ( ph2 - tl2 ) > CBmin AND( ph1 - tl2 ) / ( ph2 - tl2 ) < CBmax AND
                ( ph1 - tl1 ) / ( ph1 - tl2 ) > CCmin AND( ph1 - tl1 ) / ( ph1 - tl2 ) < CCmax;
    BearCrab = IIf( HighestSince( BearCrab4, H ) > ValueWhen( BearCrab4, tl2 ) + ( ValueWhen( BearCrab4, ph2 ) - ValueWhen( BearCrab4, tl2 ) ) * CDmin AND
                    HighestSince( BearCrab4, H ) < ValueWhen( BearCrab4, tl2 ) + ( ValueWhen( BearCrab4, ph2 ) - ValueWhen( BearCrab4, tl2 ) ) * CDMax AND
                    LowestSince( BearCrab4, L ) >= ValueWhen( BearCrab4, tl1 ) AND
                    HighestSince( BearCrab4, H ) == H, True, False );
    BearCrab = BearCrab AND HighestSince( BearCrab4, H ) > ValueWhen( BearCrab4, ph2 );
}

BearHar4 = BearGartley4 OR BearButterfly4 OR BearBat4 OR BearCrab4 ;
BearHar = BearGartley OR BearButterfly OR BearBat OR BearCrab ;

beXy = ValueWhen( BearHar4, ph2 );
beXx = ValueWhen( BearHar4, px2 );
beAy = ValueWhen( BearHar4, tl2 );
beAx = ValueWhen( BearHar4, tx2 );
beBy = ValueWhen( BearHar4, ph1 );
beBx = ValueWhen( BearHar4, px1 );
beCy = ValueWhen( BearHar4, tl1 );
beCx = ValueWhen( BearHar4, tx1 );
beDy = ValueWhen( BearHar, H );
beDx = ValueWhen( BearHar, bi );

beABdXA = ( beBy - beAy ) / ( beXy - beAy );
beBCdAB = ( beBy - beCy ) / ( beBy - beAy );
beADdXA = ( beDy - beAy ) / ( beXy - beAy );
beBCdCD = ( beDy - beCy ) / ( beBy - beCy );

function drawBearishPattern( i, patternName )
{
    GfxSelectSolidBrush( ColorRGB( 50, 0, 0 ) );
    GfxSetBkColor( colorBlack );
    GfxSelectPen( ColorRGB( 255, 0, 0 ), 2, 0 );
    GfxMoveTo( beXx[i], beXy[i] );
    GfxLineTo( beAx[i], beAy[i] );
    GfxMoveTo( beAx[i], beAy[i] );
    GfxLineTo( beBx[i], beBy[i] );
    GfxMoveTo( beBx[i], beBy[i] );
    GfxLineTo( beCx[i], beCy[i] );
    GfxMoveTo( beCx[i], beCy[i] );
    GfxLineTo( beDx[i], beDy[i] );
    GfxMoveTo( beXx[i], beXy[i] );
    GfxLineTo( beAx[i], beAy[i] );

    GfxSelectPen( ColorRGB( 255, 0, 0 ), 1, 2 );
    GfxMoveTo( beXx[i], beXy[i] );
    GfxLineTo( beBx[i], beBy[i] );
    GfxMoveTo( beAx[i], beAy[i] );
    GfxLineTo( beCx[i], beCy[i] );
    GfxMoveTo( beBx[i], beBy[i] );
    GfxLineTo( beDx[i], beDy[i] );
    GfxMoveTo( beXx[i], beXy[i] );
    GfxLineTo( beDx[i], beDy[i] );

    GfxPolygon( beXx[i], beXy[i], beAx[i], beAy[i], beBx[i], beBy[i], beCx[i], beCy[i], beDx[i], beDy[i], beBx[i], beBy[i], beXx[i], beXy[i] );

    GfxSetTextColor( ColorRGB( 0, 0, 0 ) );
    GfxSelectFont( "Helvetica", 10, 700 );
    GfxSetBkColor( ColorRGB( 255, 0, 0 ) );
    GfxSetTextAlign( 0 | 0 );
    GfxTextOut( patternName, beCx[i] + 3, beCy[i] );

    GfxSetTextAlign( 0 | 0 );
    GfxSetTextColor( ColorRGB( 255, 0, 0 ) );
    GfxSetBkColor( ColorRGB( 0, 0, 0 ) );
    GfxSelectFont( "Helvetica", 8, 700 );
    GfxTextOut( "" + Prec( beABdXA[i], 2 ), ( beBx[i] + beXx[i] ) / 2, ( beBy[i] + beXy[i] ) / 2 );
    GfxTextOut( "" + Prec( beBCdAB[i], 2 ), ( beCx[i] + beAx[i] ) / 2, ( beCy[i] + beAy[i] ) / 2 );
    GfxTextOut( "" + Prec( beADdXA[i], 2 ), ( beDx[i] + beXx[i] ) / 2, ( beDy[i] + beXy[i] ) / 2 );
    GfxTextOut( "" + Prec( beBCdCD[i], 2 ), ( beBx[i] + beDx[i] ) / 2, ( beBy[i] + beDy[i] ) / 2 );

    if( showPatternLabels )
    {
        GfxSetTextColor( ColorRGB( 0, 0, 0 ) );
        GfxSelectFont( "Helvetica", 10, 700 );
        GfxSetBkColor( ColorRGB( 255, 0, 0 ) );
        GfxSetTextAlign( 0 | 24 );
        GfxTextOut( "X", beXx[i] - 2, beXy[i] );
        GfxTextOut( "A", beAx[i] - 2, beAy[i] );
        GfxTextOut( "B", beBx[i] - 2, beBy[i] );
        GfxTextOut( "C", beCx[i] + 1, beCy[i] );
        GfxTextOut( "D", beDx[i] + 1, beDy[i] );
    }
}

function drawBearishPatterns()
{
    flag1 = 1;
    flag2 = 0;
    cnt = 0;

    for( i = lvb; i > fvb; i-- )
    {
        if( BearHar[i] AND flag1 AND cnt < nBear )
        {
            flag1 = 0;
            flag2 = 1;
            cnt = cnt + 1;

            if( BearButterfly[i] AND be AND dBut )
            {
                drawBearishPattern( i, "Bearish Butterfly" );
            }
            else
                if( BearCrab[i] AND be AND dCrab )
                {
                    drawBearishPattern( i, "Bearish Crab" );
                }
                else
                    if( BearBat[i] AND be AND dBat )
                    {
                        drawBearishPattern( i, "Bearish Bat" );
                    }
                    else
                        if( BearGartley[i] AND be AND dGart )
                        {
                            drawBearishPattern( i, "Bearish Gartley" );
                        }
        }

        if( BearHar4[i] AND flag2 )
        {
            flag1 = 1;
            flag2 = 0;
        }
    }
}
drawBearishPatterns();

function drawPivotLabels()
{
    sz = 5;

    for( i = lvb; i > fvb; i-- )
    {
        {
            if( ll[i] ) PlotTextSetFont( "LL", "Arial Black", sz, i, L[i], colorBlue, colorDefault, -25 );

            if( hl[i] ) PlotTextSetFont( "HL", "Arial Black", sz, i, L[i], colorBlue, colorDefault, -25 );

            if( db[i] ) PlotTextSetFont( "DB", "Arial Black", sz, i, L[i], colorLightBlue, colorDefault, -25 );

            if( hh[i] ) PlotTextSetFont( "HH", "Arial Black", sz, i, H[i], colorRed, colorDefault, 20 );

            if( lh[i] ) PlotTextSetFont( "LH", "Arial Black", sz, i, H[i], colorRed, colorDefault, 20 );

            if( dt[i] ) PlotTextSetFont( "DT", "Arial Black", sz, i, H[i], colorOrange, colorDefault, 20 );
        }
    }
}

if( plotLabels ) drawPivotLabels();

if( showPatternDevelopmentPoints )
{
    if( bu )
    {
        PlotShapes( shapeDigit4 * BullHar4, colorBlue, O, H, 10 );
        PlotShapes( shapeSmallCircle * BullHar, colorLightBlue, O, L, -10 );
    }

    if( be )
    {
        PlotShapes( shapeDigit4 * BearHar4, colorRed, O, L, -10 );
        PlotShapes( shapeSmallCircle * BearHar, colorOrange, O, H, 10 );
    }
}
 
#13
Hi Traderji

Thank you for your reply to my posting re Pesavento Patterns
It was not the short term Gartley & Butterfly Patterns I was after on a chart
........................................................................................................

After plotting say a 10 Percent Zig -Zag on a Chart

I would like Labels of the Fibonacci Ratios Numbers between each Leg of the the Zig-Zag Pattern from a Major Low
As the original TradeStation screenshot of the S&P 500 shows

Or as shown on the Harmonic Analyzer screenshot of the Dax Index
Harmonic Analyzer screenshot of the Dax .... is much better than all my words
Link to Harmonic Analyzer screenshot below:



http://imgur.com/a/mLsc2

Or using a modified version of ..."The Lord " KSA Glattery afl " code below:
from a Major Low on the Chart......
Then Label the Fibonacci Ratios Numbers between each Leg of the the Zig-Zag Pattern

With many thanks to the "The Lord" KSA for his great programming of the Glattery afl

Code:
SetOption("RefreshWhenCompleted", True ); 
_SECTION_BEGIN("Basic Chart");
BringPatternToFront = ParamToggle("Bring Pattern To Front ", "Yes|No" );
if(BringPatternToFront ==1)
{

Plot( C, "Close", ParamColor("Color", colorBlack ),ParamStyle("Style") | GetPriceStyle() ); 
}

OpenPct = (Open - Ref(C,-1))/Ref(C,-1)*100 ;
HighPct = (H - Ref(C,-1))/Ref(C,-1)*100 ;
LowPct = (L - Ref(C,-1))/Ref(C,-1)*100 ;
ClosePct = (C - Ref(C,-1))/Ref(C,-1)*100 ;
VolPct = (V - Ref(V,-1))/Ref(V,-1)*100 ;
	_N(Title =Name() + "   " + FullName() + "   Date: "+Date() 
	+WriteIf(Open>Ref(C,-1),EncodeColor(colorGreen),EncodeColor(colorRed))+"   Open:"+ WriteVal( Open, 1.2 ) +"  ("+WriteVal(OpenPct ,1.2) +"%)"
	+WriteIf(H>Ref(C,-1),EncodeColor(colorGreen),EncodeColor(colorRed))+ "    Hi:" + WriteVal( H , 1.2 ) +"  ("+WriteVal(HighPct ,1.2) +"%)" 
	+WriteIf(L>Ref(C,-1),EncodeColor(colorGreen),EncodeColor(colorRed))+"    Lo:"+ WriteVal( L, 1.2 ) +"  ("+WriteVal(LowPct ,1.2) +"%)" 
	+WriteIf(C>Ref(C,-1),EncodeColor(colorGreen),EncodeColor(colorRed))+"    Close:"+ WriteVal( C, 1.2 ) +"  ("+WriteVal(ClosePct ,1.2) +"%)" 
	+WriteIf(V>Ref(V,-1),EncodeColor(colorGreen),EncodeColor(colorRed))+"    Vol: "+ WriteVal( V, 1.2 ) +"  ("+WriteVal(VolPct ,1.2) +"%)") ;

ShowToolTip =0;
if( ShowToolTip == 0)
{
 ToolTip=  "Open: "+ WriteVal( Open, 1.2 ) +"  ("+WriteVal(OpenPct ,1.2) +"%)"
		 +"\nHigh  : "+ WriteVal( H , 1.2 ) +"  ("+WriteVal(HighPct ,1.2) +"%)"  
		 +"\nLow   : "+ WriteVal( L, 1.2 ) +"  ("+WriteVal(LowPct ,1.2) +"%)"  
		 +"\nClose: "+ WriteVal( C, 1.2 ) +"  ("+WriteVal(ClosePct ,1.2) +"%)"  
		 +"\nVolume: "+ WriteVal( V, 1.2 ) +"  ("+WriteVal(VolPct ,1.2) +"%)"  ;

}



lvb = Status("lastvisiblebar"); 
fvb = Status("firstvisiblebar"); 

VisibleBars= Min( Lvb - fvb, BarCount - fvb ); 
//"VisibleBars= "+VisibleBars;
ShowAuthorName = ParamToggle("Show Author Name", "Yes|No" );
if (ShowAuthorName ==0)
{	GfxSelectFont("ARIAL", 16, 800 ); 
	GfxSetBkMode(1); 
	GfxSetTextColor(colorWhite); 
	GfxTextOut("THE LORD KSA V 1.0", 5 , 10); 
}
SetChartBkGradientFill( ParamColor("Bg Top Color", colorWhite),
							ParamColor("Bg Bottom Color", colorWhite),
							ParamColor("Title Block Color",colorWhite));
GraphXSpace = Param("Vertical Zoom Out",2,-50,200,0.5);
_SECTION_END(); //Eof Basic Chart
Buy = BuyEma = BuyStc = Buyengulf = BuySwing3days = buyRsiCciVol = BuyBBand = buyFibo =0;

Sell = SellEma = SellStc = Sellengulf = SellSwing3days = sellRsiCciVol = sellBBand = sellFibo =0;
	printf(  Name()+" "+FullName()+"\n");

_SECTION_BEGIN("Last 4 Days Zigzag Lines");
	Linestyle1 = ParamStyle("Line Style1",styleThick ,styleDots|styleLine|styleDashed|styleThick  ); 
	ZigzagChange = Param ("Zigzag Change %", 10,0.5,100.0,0.5); 
	"Zigzag Change Sensitivity = "+ ZigzagChange +" %\n";
	bi = BarIndex();
	x0_1st = (BarCount -1) - LastValue(PeakBars( H, ZigzagChange , 1)); 
	y0_1st = LastTop1st = LastValue(Peak( H, ZigzagChange ,1));
	x1_1st = x1_0th = LastValue(bi);
	y1_1st = LastValue(L); 
	x1_0th = LastValue(bi);
	y1_0th = LastValue(L); 

	LLValueBarNumber = BarCount - x0_1st;
	LLValue = LastValue( LLV(L, LLValueBarNumber ));
	LLVBar = LLVBars( L, LLValueBarNumber ); 
	y1_1st = LLValue ; 
	x1_1st = LastValue(ValueWhen( LLValue == L, BarIndex(), 1));
	x1_0th = LastValue(bi);
	y1_0th = LastValue(L); 
	x0_2nd = (BarCount -1) - LastValue(TroughBars( L, ZigzagChange , 1)); 
	y0_2nd = LastTop2nd = LastValue(Trough( L, ZigzagChange ,1)); 
	x1_2nd = x0_1st;
	y1_2nd = LastTop2nd = y0_1st; 
	x0_3rd = (BarCount -1) - LastValue(PeakBars( H, ZigzagChange , 2)); 
	y0_3rd = LastTop3rd = LastValue(Peak( H, ZigzagChange ,2)); 
	x1_3rd = x0_2nd ;
	y1_3rd = LastTop3rd = y0_2nd ; 

	if(x0_3rd > x1_3rd )
	{
		for (i = 3; i <= 10; i++)
		{
			x0_3rd = (BarCount -1) - LastValue(PeakBars( H, ZigzagChange , i)); 
			y0_3rd = LastTop3rd = LastValue(Peak( H, ZigzagChange ,i)); 
			if(x0_3rd < x1_3rd )
				i=10 ;
		}

	}
	x0_4th= (BarCount -1) - LastValue(TroughBars( L, ZigzagChange , 2)); 
	y0_4th= LastTop4th= LastValue(Trough( L, ZigzagChange ,2)); 
	x1_4th= x0_3rd  ;
	y1_4th= LastTop4th= y0_3rd  ; 
	if(x0_4th> x1_4th)
	{
		for (i = 3; i <= 10; i++)
		{	x0_4th= (BarCount -1) - LastValue(TroughBars( L, ZigzagChange , i)); 
			y0_4th= LastTo=p4th= LastValue(Trough( L, ZigzagChange ,i)); 
			if(x0_4th< x1_4th)
				i=10 ;
		}

	}
	x0_5th = (BarCount -1) - LastValue(PeakBars( H, ZigzagChange , 2)); 
	y0_5th = LastTop5th = LastValue(Peak( H, ZigzagChange ,2)); 
	x1_5th = x0_4th;
	y1_5th = LastTop5th = y0_4th; 

	if(x0_5th > x1_5th )
	{
		for (i = 3; i <= 10; i++)
		{
			x0_5th = (BarCount -1) - LastValue(PeakBars( H, ZigzagChange , i)); 
			y0_5th = LastTop5th = LastValue(Peak( H, ZigzagChange ,i)); 
			if(x0_5th < x1_5th )
				i=10 ;
		}

	}
	x0_6th= (BarCount -1) - LastValue(TroughBars( L, ZigzagChange , 2)); 
	y0_6th= LastTop6th= LastValue(Trough( L, ZigzagChange ,2)); 
	x1_6th= x0_5th ;
	y1_6th= LastTop6th= y0_5th ; 
	if(x0_6th> x1_6th)
	{
		for (i = 3; i <= 10; i++)
		{	x0_6th= (BarCount -1) - LastValue(TroughBars( L, ZigzagChange , i)); 
			y0_6th= LastTo=p6th= LastValue(Trough( L, ZigzagChange ,i)); 
			if(x0_6th< x1_6th)
				i=10 ;
		}

	}
	x0_7th = (BarCount -1) - LastValue(PeakBars( H, ZigzagChange , 2)); 
	y0_7th = LastTop7th = LastValue(Peak( H, ZigzagChange ,2)); 
	x1_7th = x0_6th;
	y1_7th = LastTop7th = y0_6th; 

	if(x0_7th > x1_7th )
	{
		for (i = 3; i <= 10; i++)
		{
			x0_7th = (BarCount -1) - LastValue(PeakBars( H, ZigzagChange , i)); 
			y0_7th = LastTop7th = LastValue(Peak( H, ZigzagChange ,i)); 
			if(x0_7th < x1_7th )
				i=10 ;
		}

	}

	x0_8th= (BarCount -1) - LastValue(TroughBars( L, ZigzagChange , 2)); 
	y0_8th= LastTop8th= LastValue(Trough( L, ZigzagChange ,2)); 
	x1_8th= x0_7th ;
	y1_8th= LastTop8th= y0_7th ; 
	if(x0_8th> x1_8th)
	{
		for (i = 3; i <= 10; i++)
		{	x0_8th= (BarCount -1) - LastValue(TroughBars( L, ZigzagChange , i)); 
			y0_8th= LastTo=p8th= LastValue(Trough( L, ZigzagChange ,i)); 
			if(x0_8th< x1_8th)
				i=10 ;
		}

	}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(x0_2nd > x1_2nd )
{
	x0_1st = (BarCount -1) - LastValue(TroughBars( L, ZigzagChange , 1)); 
	y0_1st = LastTop1st = LastValue(Trough( L, ZigzagChange ,1));
	y1_1st = LastValue(H); 
	HHValueBarNumber = BarCount - x0_1st;
	HHValue = LastValue( HHV(H, HHValueBarNumber ));
	HHVBar = HHVBars( H, HHValueBarNumber); 
	y1_1st = HHValue ; 
	x1_1st = LastValue(ValueWhen( HHValue == H, BarIndex(), 1));
	x1_0th = LastValue(bi);
	y1_0th = LastValue(L); 
	x0_2nd = (BarCount -1) - LastValue(PeakBars( H, ZigzagChange , 1)); 
	y0_2nd = LastTop2nd = LastValue(Peak( H, ZigzagChange ,1)); 
	x1_2nd = x0_1st;
	y1_2nd = LastTop2nd = y0_1st; 
	x0_3rd = (BarCount -1) - LastValue(TroughBars( L, ZigzagChange , 2)); 
	y0_3rd = LastTop3rd = LastValue(Trough( L, ZigzagChange ,2)); 
	x1_3rd = x0_2nd ;
	y1_3rd = LastTop3rd = y0_2nd ; 

	if(x0_3rd > x1_3rd )
	{
		for (i = ZigzagChange ; i >= 0; i--)
	{
			x0_3rd = (BarCount -1) - LastValue(TroughBars( L, ZigzagChange , i)); 
			y0_3rd = LastTop3rd = LastValue(Trough( L, ZigzagChange ,i)); 

			if(x0_3rd < x1_3rd )
				i=0 ;
		}
	}

	x0_4th= (BarCount -1) - LastValue(PeakBars( H, ZigzagChange , 1)); 
	y0_4th= LastTop4th= LastValue(Peak( H, ZigzagChange ,1)); 
	x1_4th= x0_3rd  ;
	y1_4th= LastTop4th= y0_3rd  ; 

	if(x0_4th == x1_3rd )
	{
		for (i = ZigzagChange ; i >= 0; i--)
		{	
		x0_4th= (BarCount -1) - LastValue(PeakBars( H, ZigzagChange -i , 2)); 
		y0_4th= LastTop4th= LastValue(Peak( H,ZigzagChange - i ,2)); 
			if(x0_4th < x1_3rd )
				i=0 ;
		}

	}

	x0_5th = (BarCount -1) - LastValue(TroughBars( L, ZigzagChange , 2)); 
	y0_5th = LastTop5th = LastValue(Trough( L, ZigzagChange ,2)); 
	x1_5th = x0_4th ;
	y1_5th = LastTop5th = y0_4th ; 
	if(x0_5th > x1_5th )
	{
		for (i = 3; i <= 10; i++)
		{
			x0_5th = (BarCount -1) - LastValue(TroughBars( L, ZigzagChange , i)); 
			y0_5th = LastTop5th = LastValue(Trough( L, ZigzagChange ,i)); 
			if(x0_5th < x1_5th )
				i=10 ;
		}
	}

	x0_6th = (BarCount -1) - LastValue(PeakBars( H, ZigzagChange , 2)); 
	y0_6th = LastTop6th = LastValue(Peak( H, ZigzagChange ,2)); 
	x1_6th = x0_5th ;
	y1_6th = LastTop6th = y0_5th ; 
	if(x0_6th > x1_6th )
	{
		for (i = 3; i <= 10; i++)
		{
			x0_6th = (BarCount -1) - LastValue(PeakBars( H, ZigzagChange , i)); 
			y0_6th = LastTop6th = LastValue(Peak( H, ZigzagChange ,i)); 
			if(x0_6th < x1_6th )
				i=10 ;
		}
	}

	x0_7th = (BarCount -1) - LastValue(TroughBars( L, ZigzagChange , 2)); 
	y0_7th = LastTop7th = LastValue(Trough( L, ZigzagChange ,2)); 
	x1_7th = x0_6th ;
	y1_7th = LastTop7th = y0_6th ; 
	if(x0_7th > x1_7th )
	{
		for (i = 3; i <= 10; i++)
		{
			x0_7th = (BarCount -1) - LastValue(TroughBars( L, ZigzagChange , i)); 
			y0_7th = LastTop7th = LastValue(Trough( L, ZigzagChange ,i)); 
			if(x0_7th < x1_7th )
				i=10 ;
		}
	}
	x0_8th = (BarCount -1) - LastValue(PeakBars( H, ZigzagChange , 2)); 
	y0_8th = LastTop8th = LastValue(Peak( H, ZigzagChange ,2)); 
	x1_8th = x0_7th;
	y1_8th = LastTop8th = y0_7th; 

	if(x0_8th > x1_8th )
	{
		for (i = 3; i <= 10; i++)
		{
			x0_8th = (BarCount -1) - LastValue(PeakBars( H, ZigzagChange , i)); 
			y0_8th = LastTop8th = LastValue(Peak( H, ZigzagChange ,i)); 
			if(x0_8th < x1_8th )
				i=10 ;
		}

	}

}

/*------------------------------------------------------------------------*/
/*------------------------------------------------------------------------*/
	ShowAnalysisOnMainScreen = ParamToggle("Show Analysis On Main Screen ", "Yes|No" );
	TargetPosition = Param ("Target Position ", 2,1,40,1); 
	TargetPosition = BarCount + TargetPosition ;
	GfxSelectFont("ARIAL", 12, 800 ); 

ShowLabels = ParamToggle("Show Zigzag Labels  ", "Yes|No" );
FindLastTrueHiLow = ParamToggle("Find Last True Hi Low ", "Yes|No" );
ReReadPattern = ParamToggle("Re-Read Pattern ", "Yes|No" );
ShowSuppRes1 = ParamToggle("Show Supp & Res Lines1", "Yes|No" );
ShowSuppRes2 = ParamToggle("Show Supp & Res Lines2", "Yes|No" );
ShowXYvalues = 1;

pk=PeakBars(H,ZigzagChange)==0;
tr=TroughBars(L,ZigzagChange)==0;

ZigzagHi=Zig(H,ZigzagChange);
ZigzagLo=Zig(L,ZigzagChange);
Avg=(ZigzagHi+ZigzagLo)/2;

x=IIf(pk,ZigzagHi,IIf(tr,ZigzagLo,IIf(Avg>Ref(Avg,-1),H,L)));
ZigzagHiLo=Zig(x,ZigzagChange);

bar1 = bar2 = bar3 = bar4 = bar5 = 1;
DownTrend =0;
x1_1st = x1_0th = BarCount-1;
y1_1st = y1_0th = LastValue(L);
if(LastValue( ZigzagHiLo) > LastValue( Ref(ZigzagHiLo,-1)))
	{
	DownTrend =1;
	y1_1st = y1_0th = LastValue(H);
	}
NoValidTrend = _x0_5th =_x0_4th = 0;
	if (DownTrend == 1 OR DownTrend == 0)
	{
		for (bar1= 1; bar1< BarCount; bar1++ ) 
		{
			x0_1st =  x1_2nd = BarCount - bar1-1; //
			if( DownTrend == 1 AND ZigzagHiLo [BarCount-bar1] > ZigzagHiLo[BarCount-bar1-1] 
						AND ZigzagHiLo [BarCount-bar1-1] < ZigzagHiLo[BarCount-bar1-2] OR DownTrend == 1  AND IsEmpty(ZigzagHiLo[BarCount-bar1]))
			{	y0_1st = y1_2nd = L[ BarCount-bar1-1]; //
				if(ShowXYvalues == 0)
				{
					printf("\n x0_1st = x1_2nd = "+x0_1st);
					printf( "\n y0_1st = y1_2nd = "+y0_1st );
					printf("\n aaaa exit = 1");
					printf( "\n");
				}
				bar2 = bar1;
				bar1 = BarCount;

				if(FindLastTrueHiLow == 0)
				{
					HHValueBarNumber = BarCount - x0_1st;
					HHValue = LastValue( HHV(H, HHValueBarNumber ));
					HHVBar = HHVBars( H, HHValueBarNumber); 
					y1_1st = HHValue ; 
					x1_1st = LastValue(ValueWhen( HHValue == H, BarIndex(), 1));
					x1_0th = LastValue(bi); 
					y1_0th = LastValue(L); 
				}
			}
			if( DownTrend == 0 AND ZigzagHiLo [BarCount-bar1] < ZigzagHiLo[BarCount-bar1-1] 
						AND ZigzagHiLo [BarCount-bar1-1] > ZigzagHiLo[BarCount-bar1-2]  OR DownTrend == 0  AND IsEmpty(ZigzagHiLo[BarCount-bar1]))
			{
				y0_1st = y1_2nd = H[ BarCount-bar1-1]; 
				if(ShowXYvalues == 0)
				{
					printf("\n x0_1st = x1_2nd = "+x0_1st);
					printf( "\n y0_1st = y1_2nd = "+y0_1st);
					printf("\n bbbb exit = 1");
					printf( "\n");
				}
				bar2 = bar1;
				bar1 = BarCount;

				if(FindLastTrueHiLow == 0)
				{
					LLValueBarNumber = BarCount - x0_1st;
					LLValue = LastValue( LLV(L, LLValueBarNumber ));
					LLVBar = LLVBars( L, LLValueBarNumber ); 
					y1_1st = LLValue ; 
					x1_1st = LastValue(ValueWhen( LLValue == L, BarIndex(), 1));
					y1_0th = LastValue(H); 
				}
			}
		}
//-----------------------------------------------------------
		for (bar2= bar2+1; bar2< BarCount; bar2++ ) 
		{
			x0_2nd = x1_3rd = BarCount-bar2-1;
			if( DownTrend == 1 AND ZigzagHiLo [BarCount-bar2] < ZigzagHiLo[BarCount-bar2-1] 
						AND ZigzagHiLo [BarCount-bar2-1] > ZigzagHiLo[BarCount-bar2-2] OR DownTrend == 1  AND IsEmpty(ZigzagHiLo[BarCount-bar2-2]))
			{
				y0_2nd = y1_3rd = H[ BarCount-bar2-1];
				if(ShowXYvalues == 0)
				{
					printf("\n x0_2nd = x1_3rd = "+x0_2nd );
					printf( "\n y0_2nd = y1_3rd = "+y0_2nd);
					printf("\n aaa exit = 2");
					printf( "\n");
				}
				if(IsEmpty(ZigzagHiLo[BarCount-bar2]))
				{	x0_2nd= x0_1st;
					y0_2nd= y0_1st;
					NoValidTrend = NoValidTrend + 1;
				}
				bar3 = bar2;
				bar2 = BarCount;
			}
			if( DownTrend == 0 AND ZigzagHiLo [BarCount-bar2] > ZigzagHiLo[BarCount-bar2-1] 
						AND ZigzagHiLo [BarCount-bar2-1] < ZigzagHiLo[BarCount-bar2-2] OR DownTrend == 0  AND IsEmpty(ZigzagHiLo[BarCount-bar2]))
			{
				y0_2nd = y1_3rd = L[ BarCount-bar2-1];
				if(ShowXYvalues == 0)
				{
					printf("\n x0_2nd = x1_3rd = "+x1_2nd );
					printf( "\n y0_2nd = y1_3rd = "+y0_2nd);
					printf("\n bbb exit = 2");
					printf( "\n");
				}
				if(IsEmpty(ZigzagHiLo[BarCount-bar2]))
				{	x0_2nd= x0_1st;
					y0_2nd= y0_1st;
					NoValidTrend = NoValidTrend + 1;
				}
				bar3 = bar2;
				bar2 = BarCount;
			}
		}
//-----------------------------------------------------------
		for (bar3= bar3+1; bar3< BarCount; bar3++ ) 
		{
			x0_3rd = x1_4th = BarCount-bar3-1;
			if( DownTrend == 1 AND ZigzagHiLo [BarCount-bar3] > ZigzagHiLo[BarCount-bar3-1] 
						AND ZigzagHiLo [BarCount-bar3-1] < ZigzagHiLo[BarCount-bar3-2] OR DownTrend == 1  AND IsEmpty(ZigzagHiLo[BarCount-bar3-2]))
			{
				y0_3rd = y1_4th = L[ BarCount-bar3-1];
				if(ShowXYvalues == 0)
				{
					printf("\n x0_3rd = x1_4th = "+ x0_3rd);
					printf( "\n y0_3rd = y1_4th = "+y0_3rd);
					printf("\n aaa exit = 3");
					printf( "\n");
				}
				if(IsEmpty(ZigzagHiLo[BarCount-bar3]))
				{	x0_3rd= x0_2nd;
					y0_3rd= y0_2nd;
					NoValidTrend = NoValidTrend + 1;
				}
				bar4 = bar3;
				bar3 = BarCount;
			}
			if( DownTrend == 0 AND ZigzagHiLo [BarCount-bar3] < ZigzagHiLo[BarCount-bar3-1] 
						AND ZigzagHiLo [BarCount-bar3-1] > ZigzagHiLo[BarCount-bar3-2] OR DownTrend == 0  AND IsEmpty(ZigzagHiLo[BarCount-bar3]))
			{
				y0_3rd = y1_4th = H[ BarCount-bar3-1];
				if(ShowXYvalues == 0)
				{
					printf("\n x0_3rd = x1_4th = "+x0_3rd);
					printf( "\n y0_3rd = y1_4th = "+y0_3rd );
					printf("\n bbb exit = 3");
					printf( "\n");
				}
				if(IsEmpty(ZigzagHiLo[BarCount-bar3]))
				{	x0_3rd= x0_2nd;
					y0_3rd= y0_2nd;
					NoValidTrend = NoValidTrend + 1;
				}
				bar4 = bar3;
				bar3 = BarCount;
			}
		}

//-----------------------------------------------------------
		for (bar4= bar4+1; bar4< BarCount; bar4++ ) 
		{
			x0_4th = x1_5th = BarCount-bar4-1;
			if( DownTrend == 1 AND ZigzagHiLo [BarCount-bar4] < ZigzagHiLo[BarCount-bar4-1] 
						AND ZigzagHiLo [BarCount-bar4-1] > ZigzagHiLo[BarCount-bar4-2] OR DownTrend == 1  AND IsEmpty(ZigzagHiLo[BarCount-bar4-2]))
			{
				y0_4th = y1_5th = H[ BarCount-bar4-1];
				if(ShowXYvalues == 0)
				{
					printf("\n x0_4th = x1_5th = "+x0_4th);
					printf( "\n y0_4th = y1_5th = "+y0_4th );
					printf("\n aaa exit = 4" );
					printf( "\n");
				}
				if(IsEmpty(ZigzagHiLo[BarCount-bar4]))
				{	x0_4th= x0_3rd;
					y0_4th= y0_3rd;
					NoValidTrend = NoValidTrend + 1;
				}
				bar5 = bar4;
				bar4 = BarCount;
			}
			if( DownTrend == 0 AND ZigzagHiLo [BarCount-bar4] > ZigzagHiLo[BarCount-bar4-1] 
								AND ZigzagHiLo [BarCount-bar4-1] < ZigzagHiLo[BarCount-bar4-2]  OR DownTrend == 0  AND IsEmpty(ZigzagHiLo[BarCount-bar4]))
			{
				y0_4th = y1_5th = L[ BarCount-bar4-1];
				if(ShowXYvalues == 0)
				{
					printf("\n x0_4th = x1_5th = "+x0_4th);
					printf( "\n y0_4th = y1_5th = "+y0_4th);
					printf("\n bbb exit = 4");
					printf( "\n");
				}
				if(IsEmpty(ZigzagHiLo[BarCount-bar4]))
				{	_x0_4th= x0_3rd;
					x0_4th= x0_3rd;
					y0_4th= y0_3rd;
					NoValidTrend = NoValidTrend + 1;
				}
				bar5 = bar4;
				bar4 = BarCount;
			}
		}
//-----------------------------------------------------------		
	for (bar5= bar5+1; bar5< BarCount; bar5++ ) 
		{
			x0_5th = BarCount-bar5-1;
			if( DownTrend == 1 AND ZigzagHiLo [BarCount-bar5] > ZigzagHiLo[BarCount-bar5-1] 
					AND ZigzagHiLo [BarCount-bar5-1] < ZigzagHiLo[BarCount-bar5-2] OR DownTrend == 1  AND IsEmpty(ZigzagHiLo[BarCount-bar5-2]))
			{
				y0_5th = L[ BarCount-bar5-1];
				if(ShowXYvalues == 0)
				{
					printf("\n x0_5th = x1_6th = "+x0_5th);
					printf( "\n y0_5th = y1_6th = "+y0_5th);
					printf("\n aaa exit = 5");
					printf( "\n");
				}
				if(IsEmpty(ZigzagHiLo[BarCount-bar5]))
				{	x0_5th = x0_4th;
					y0_5th = y0_4th;
					NoValidTrend = NoValidTrend + 1;
				}
				bar5 = BarCount;
			}
			if( DownTrend == 0 AND ZigzagHiLo [BarCount-bar5] < ZigzagHiLo[BarCount-bar5-1] 
					AND ZigzagHiLo [BarCount-bar5-1] > ZigzagHiLo[BarCount-bar5-2] OR DownTrend == 0  AND IsEmpty(ZigzagHiLo[BarCount-bar5]))
			{
				y0_5th = H[ BarCount-bar5-1];
				if(ShowXYvalues == 0)
				{
					printf("\n x0_5th = x1_6th = "+x0_5th);
					printf( "\n y0_5th = y1_6th = "+y0_5th );
					printf("\n bbb exit = 5");
					printf( "\n");
				}
				if(IsEmpty(ZigzagHiLo[BarCount-bar5]))
				{	_x0_5th = x0_5th;
					x0_5th = x0_4th;
					y0_5th = y0_4th;
					NoValidTrend = NoValidTrend + 1;
				}
				bar5 = BarCount;
			}
		}
	}
	if(ReReadPattern == 0)
	{
		x0_6th = x0_5th ;
		y0_6th = y0_5th ;
		x1_6th = x1_5th ;
		y1_6th = y1_5th ;

		x0_5th = x0_4th;
		y0_5th = y0_4th;
		x1_5th = x1_4th;
		y1_5th = y1_4th;

		x0_4th = x0_3rd;
		y0_4th = y0_3rd;
		x1_4th = x1_3rd;
		y1_4th = y1_3rd;

		x0_3rd = x0_2nd;
		y0_3rd = y0_2nd;
		x1_3rd = x1_2nd;
		y1_3rd = y1_2nd;

		x0_2nd = x0_1st;
		y0_2nd = y0_1st;
		x1_2nd = x1_1st;
		y1_2nd = y1_1st;

		x0_1st = x1_1st;
		y0_1st = y1_1st;
		x1_1st = x1_0th;
		y1_1st = y1_0th;
	}

_SECTION_END(); //Eof Last 4 Days Zigzag Lines

_SECTION_BEGIN("Fibonacci Signals");

	Wave_1st = abs(y1_1st - y0_1st) 	;
	Wave_2nd = abs(y0_2nd - y1_2nd)	;
	Wave_3rd = abs(y1_3rd - y0_3rd)	;
	Wave_4th = abs(y0_4th - y1_4th)	;
	Wave_5th = abs(y1_5th - y0_5th)	;

_SECTION_END(); //Eof Fibonacci Signals	 

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

_SECTION_BEGIN("Completed Harmonic Trader");


 	Level_382 = 0.382;
 	Level_500 = 0.500;
 	Level_618 = 0.618;
 	Level_786 = 0.786;
 	Level_886 = 0.886;
 	Level_127 = 1.27;
 	Level_1618 = 1.618;

	xa = Wave_5th ;	ab = Wave_4th ;	bc = Wave_3rd ;	Cd = Wave_2nd ;	ad = y1_5th - y1_2nd ; A_price = y1_5th;
	D_price = Y0_1st;
	ab_of_xa = ab/xa ;
	bc_of_ab = bc/ab ;
	Cd_of_bc = Cd/bc ;
	ad_of_xa = ad/xa ;

	DE = abs(y0_1st - y1_1st);
	showlengthXABCD = ParamToggle("Show Side Length of XABCD ", "Yes|No" );
	if (showlengthXABCD ==0)
	{
		printf("\nCompleted Pattern info:" );
		printf("\nXA = "+xa );
		printf("\nAB = "+ab + "  ("+WriteVal(ab_of_xa,1.2)+"%% of XA)");
		printf("\nBC = "+bc + "  ("+WriteVal(bc_of_ab,1.2)+"%% of AB)");
		printf("\nCD = "+Cd + "  ("+WriteVal(Cd_of_bc,1.2)+"%% of BC)");
		printf("\nAD = "+Cd + "  ("+WriteVal(ad_of_xa,1.2)+"%% of XA)");
		printf("\nDE = "+ WriteVal(de,1.2) + "  ("+WriteVal(de/Cd,1.2)+"%% of CD)\n");
	}
/*-----------------------------------------------------------------------*/
		XX = x0_5th;
		XY = y0_5th;
		AX = x0_4th;
		AY = y0_4th;
		BX = x0_3rd;
		BY = y0_3rd;
		CX = x0_2nd;
		CY = y0_2nd;
		DX = x1_2nd;
		DY = y1_2nd;

	Tolerance = 0.1;
	ButterflyCondition1 = (ab_of_xa  >= Level_786- Tolerance) AND (ab_of_xa <= Level_786+ Tolerance);	
	ButterflyCondition2 = (bc_of_ab  >= Level_382 - Tolerance) AND (bc_of_ab <= Level_886 + Tolerance);	
	ButterflyCondition3 = (-ad_of_xa >= Level_127 ) AND (-ad_of_xa <= Level_1618);	
	ButterflyCondition4 = (-ad_of_xa)> Level_1618;	
	ButterflyCondition5 = (ad_of_xa  >= Level_127 ) AND (ad_of_xa <= Level_1618);	
	ButterflyCondition6 = (ad_of_xa) > Level_1618;	
	CompletedButterflyBearishPattern = ButterflyCondition1 AND ButterflyCondition2 AND ButterflyCondition3 ;
	CompletedButterflyBearishPatternExtended = ButterflyCondition1 AND ButterflyCondition2 AND ButterflyCondition4 ;
	CompletedButterflyBullishPattern = ButterflyCondition1 AND ButterflyCondition2 AND ButterflyCondition5 ;
	CompletedButterflyBullishPatternExtended = ButterflyCondition1 AND ButterflyCondition2 AND ButterflyCondition6 ;
	
	CompletedButterflyTargetPrice1 = IIf(CompletedButterflyBearishPattern OR
											   CompletedButterflyBearishPatternExtended ,
											   D_price - CD * Level_618 , D_price + CD * Level_618) ;
	CompletedButterflyTargetPrice2 = IIf(CompletedButterflyBearishPattern OR
											   CompletedButterflyBearishPatternExtended ,
											   D_price - CD * Level_127 , D_price + CD * Level_127) ;
	CompletedButterflyTargetPrice3 = IIf(CompletedButterflyBearishPattern OR
											   CompletedButterflyBearishPatternExtended ,
											   D_price - CD * Level_1618 , D_price + CD * Level_1618) ;
	CompletedButterflyTargetPricePct1 = 	(CompletedButterflyTargetPrice1 - LastValue(C))/LastValue(C)*100;
	CompletedButterflyTargetPricePct2 = 	(CompletedButterflyTargetPrice2 - LastValue(C))/LastValue(C)*100;
	CompletedButterflyTargetPricePct3 = 	(CompletedButterflyTargetPrice3 - LastValue(C))/LastValue(C)*100;
/*-----------------------------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------------------------*/
	Tolerance = 0.05;
	CrabCondition1 = (ab_of_xa >= Level_382 - Tolerance) AND (ab_of_xa < Level_618 + Tolerance);	
	CrabCondition2 = (bc_of_ab >= Level_382 - Tolerance) AND (bc_of_ab <= Level_886 + Tolerance);	
	CrabCondition3 = (-ad_of_xa >= Level_127 ) AND (-ad_of_xa <= Level_1618 );	
	CrabCondition4 = (-ad_of_xa) > Level_1618 ;	
	CrabCondition5 = (ad_of_xa >= Level_127 ) AND (ad_of_xa <= Level_1618 );	
	CrabCondition6 = (ad_of_xa) > Level_1618 ;	
	CompletedCrabBearishPattern = CrabCondition1 AND CrabCondition2 AND CrabCondition3 ;
	CompletedCrabBearishPatternExtended = CrabCondition1 AND CrabCondition2 AND CrabCondition4 ;
	CompletedCrabBullishPattern = CrabCondition1 AND CrabCondition2 AND CrabCondition5 ;
	CompletedCrabBullishPatternExtended = CrabCondition1 AND CrabCondition2 AND CrabCondition6 ;

	
	CompletedCrabTargetPrice1 = IIf(CompletedCrabBearishPattern OR
											   CompletedCrabBearishPatternExtended ,
											   D_price - CD * Level_618 , D_price + CD * Level_618) ;
	CompletedCrabTargetPrice2 = IIf(CompletedCrabBearishPattern OR
											   CompletedCrabBearishPatternExtended ,
											   D_price - CD * Level_127 , D_price + CD * Level_127) ;
	CompletedCrabTargetPrice3 = IIf(CompletedCrabBearishPattern OR
											   CompletedCrabBearishPatternExtended ,
											   D_price - CD * Level_1618 , D_price + CD * Level_1618) ;
	CompletedCrabTargetPricePct1 = 	(CompletedCrabTargetPrice1 - LastValue(C))/LastValue(C)*100;
	CompletedCrabTargetPricePct2 = 	(CompletedCrabTargetPrice2 - LastValue(C))/LastValue(C)*100;
	CompletedCrabTargetPricePct3 = 	(CompletedCrabTargetPrice3 - LastValue(C))/LastValue(C)*100;
/*-----------------------------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------------------------*/
	Tolerance = 0.05;
	GartleyCondition1 = (ab_of_xa >= Level_618 - Tolerance) AND (ab_of_xa < Level_618 + Tolerance);	
	GartleyCondition2 = (bc_of_ab >= Level_382 - Tolerance) AND (bc_of_ab <= Level_886 + Tolerance);	
	GartleyCondition3 = (-ad_of_xa > Level_786- Tolerance) AND (-ad_of_xa <= Level_786 + Tolerance);	
	GartleyCondition4 = -ad_of_xa > Level_786 AND -ad_of_xa < Level_1618;	
	GartleyCondition5 = (ad_of_xa >= Level_786- Tolerance) AND (ad_of_xa <= Level_786);	
	GartleyCondition6 = ad_of_xa > Level_786 AND ad_of_xa < Level_1618;	
	CompletedGartleyBearishPattern = GartleyCondition1 AND GartleyCondition2 AND GartleyCondition3 ;
	CompletedGartleyBearishPatternExtended = GartleyCondition1 AND GartleyCondition2 AND GartleyCondition4 ;
	CompletedGartleyBullishPattern = GartleyCondition1 AND GartleyCondition2 AND GartleyCondition5 ;
	CompletedGartleyBullishPatternExtended = GartleyCondition1 AND GartleyCondition2 AND GartleyCondition6 ;

	CompletedGartleyTargetPrice1 = IIf(CompletedGartleyBearishPattern OR
											   CompletedGartleyBearishPatternExtended ,
											   D_price - CD * Level_618 , D_price + CD * Level_618) ;
	CompletedGartleyTargetPrice2 = IIf(CompletedGartleyBearishPattern OR
											   CompletedGartleyBearishPatternExtended ,
											   D_price - CD * Level_127, D_price + CD * Level_127) ;
	CompletedGartleyTargetPrice3 = IIf(CompletedGartleyBearishPattern OR
											   CompletedGartleyBearishPatternExtended ,
											   D_price - CD * Level_1618 , D_price + CD * Level_1618) ;
	CompletedGartleyTargetPricePct1 = 	(CompletedGartleyTargetPrice1 - LastValue(C))/LastValue(C)*100;
	CompletedGartleyTargetPricePct2 = 	(CompletedGartleyTargetPrice2 - LastValue(C))/LastValue(C)*100;
	CompletedGartleyTargetPricePct3 = 	(CompletedGartleyTargetPrice3 - LastValue(C))/LastValue(C)*100;
/*-----------------------------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------------------------*/
	Tolerance = 0.1;
	BatCondition1 = (ab_of_xa >= Level_382 - Tolerance) AND (ab_of_xa < Level_500 + Tolerance);	
	BatCondition2 = (bc_of_ab >= Level_382 - Tolerance) AND (bc_of_ab <= Level_886 + Tolerance);	
	BatCondition3 = (-ad_of_xa >= Level_886- Tolerance) AND (-ad_of_xa <= Level_886);	
	BatCondition4 = -ad_of_xa > Level_886 AND -ad_of_xa < Level_127;	
	BatCondition5 = (ad_of_xa >= Level_886- Tolerance) AND (ad_of_xa <= Level_886);	
	BatCondition6 = ad_of_xa > Level_886 AND ad_of_xa < Level_127;	
	CompletedBatBearishPattern = BatCondition1 AND BatCondition2 AND BatCondition3 ;
	CompletedBatBearishPatternExtended = BatCondition1 AND BatCondition2 AND BatCondition4 ;
	CompletedBatBullishPattern = BatCondition1 AND BatCondition2 AND BatCondition5 ;
	CompletedBatBullishPatternExtended = BatCondition1 AND BatCondition2 AND BatCondition6 ;

	
	CompletedBatTargetPrice1 = IIf(CompletedBatBearishPattern OR
											   CompletedBatBearishPatternExtended ,
											   D_price - CD * Level_618 , D_price + CD * Level_618) ;
	CompletedBatTargetPrice2 = IIf(CompletedBatBearishPattern OR
											   CompletedBatBearishPatternExtended ,
											   D_price - CD * Level_127 , D_price + CD * Level_127) ;
	CompletedBatTargetPrice3 = IIf(CompletedBatBearishPattern OR
											   CompletedBatBearishPatternExtended ,
											   D_price - CD * Level_1618 , D_price + CD * Level_1618) ;
	CompletedBatTargetPricePct1 = 	(CompletedBatTargetPrice1 - LastValue(C))/LastValue(C)*100;
	CompletedBatTargetPricePct2 = 	(CompletedBatTargetPrice2 - LastValue(C))/LastValue(C)*100;
	CompletedBatTargetPricePct3 = 	(CompletedBatTargetPrice3 - LastValue(C))/LastValue(C)*100;
/*-----------------------------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------------------------*/
	NoValidCompletedPattern = 

		CompletedButterflyBearishPattern ==0 AND CompletedButterflyBullishPattern ==0 AND 
		CompletedButterflyBearishPatternExtended ==0 AND CompletedButterflyBullishPatternExtended ==0 AND 

		CompletedCrabBearishPattern ==0 AND CompletedCrabBullishPattern ==0 AND 
		CompletedCrabBearishPatternExtended ==0 AND CompletedCrabBullishPatternExtended ==0 AND

		CompletedGartleyBearishPattern ==0 AND CompletedGartleyBullishPattern ==0 AND 
		CompletedGartleyBearishPatternExtended ==0 AND CompletedGartleyBullishPatternExtended ==0 AND

		CompletedBatBearishPattern ==0 AND CompletedBatBullishPattern ==0 AND 
		CompletedBatBearishPatternExtended ==0 AND CompletedBatBullishPatternExtended ==0;

	ShowInvalidCompletedPattern = 0;
	ShowEliotWavelines =0; 
		x = y0_5th;
		y = y0_4th;
		Bear = y0_5th > y0_4th;

		TextPositionX = y0_5th * -.03;
		if(Bear == 1)
			TextPositionX = y0_5th * .01;
			if(TextPositionX > 1)
				TextPositionX = 1;
			if(TextPositionX < -1)
				TextPositionX = -1;

		TextPositionA = y0_4th * .01;
		if(Bear == 1)
			TextPositionA = y0_4th * -.05;
			if(TextPositionA > 1)
				TextPositionA = 1;
			if(TextPositionA < -1.5)
				TextPositionA = -1.5;

		TextPositionB = y0_3rd * -.03;
		if(Bear == 1)
			TextPositionB = y0_3rd * .01;
			if(TextPositionB > 1)
				TextPositionB = 1;
			if(TextPositionB < -1.5)
				TextPositionB = -1.5;

		TextPositionC = y0_2nd * .01;
		if(Bear == 1)
			TextPositionC = y0_2nd * -.05;
			if(TextPositionC > 1)
				TextPositionC = 1;
			if(TextPositionC < -1.5)
				TextPositionC = -1.5;

		TextPositionD = y0_1st * -.03;
		if(Bear == 1)
			TextPositionD = y0_1st * .01;
			if(TextPositionD > 1)
				TextPositionD = 1;
			if(TextPositionD < -1.5)
				TextPositionD = -1.5;

		TextPositionE = y1_1st * .01;
		if(Bear == 1)
			TextPositionE = y1_1st * -.03;
			if(TextPositionE > 1)
				TextPositionE = 1;
			if(TextPositionE < -1.5)
				TextPositionE = -1.5;

		Color1 = ParamColor("Color XABCD Main Line",colorBlue);
		ColorUp = ParamColor("Last Leg (DE) Color if up",colorBrightGreen);
		ColorDown = ParamColor("Last Leg (DE) Color if Down",colorRed);

		ColorXB = ParamColor("Color XB Dashed Line",colorBlack);
		ColorAC = ParamColor("Color AC Dashed Line",colorBlack);
		ColorBD = ParamColor("Color BD Dashed Line",colorBlack);


	if (ShowInvalidCompletedPattern ==1 OR NoValidCompletedPattern ==0)
	{
		PlotText("X",x0_5th , y0_5th +TextPositionX , colorViolet ); 
		PlotText("A",x0_4th , y0_4th +TextPositionA , colorViolet ); 
		PlotText("B",x0_3rd , y0_3rd +TextPositionB , colorViolet ); 
		PlotText("C",x0_2nd , y0_2nd +TextPositionC , colorViolet ); 
		PlotText("D",x0_1st , y0_1st +TextPositionD , colorViolet ); 
		PlotText("E",x1_1st , y1_1st +TextPositionE , colorViolet ); 

		Plot (LineArray(x0_5th , y0_5th , x1_5th , y1_5th ),"XA",Color1 ,Linestyle1 + styleNoTitle); 
		Plot (LineArray(x0_4th , y0_4th , x1_4th , y1_4th ),"AB",Color1 ,Linestyle1 + styleNoTitle); 
		Plot (LineArray(x0_3rd , y0_3rd , x1_3rd , y1_3rd ),"BC",Color1 ,Linestyle1 + styleNoTitle); 
		Plot (LineArray(x0_2nd , y0_2nd , x1_2nd , y1_2nd ),"CD",Color1 ,Linestyle1 + styleNoTitle); 
		Plot (LineArray(x0_1st , y0_1st , x1_1st , y1_1st ),"DE",IIf(y1_2nd > y1_1st,ColorDown ,ColorUp ) ,Linestyle1 + styleNoTitle); 
 		Plot (LineArray(x1_1st , y1_1st , x1_0th , y1_0th ),"DE+",colorViolet ,styleLine +styleNoTitle); 

		Plot (LineArray(x0_4th , y0_4th , x1_3rd , y1_3rd ),"AC",ColorAC , styleDashed +styleNoTitle); 
		Plot (LineArray(x0_3rd , y0_3rd , x1_2nd , y1_2nd ),"BD",ColorBD , styleDashed +styleNoTitle ); 
		Plot (LineArray(x0_5th , y0_5th , x1_4th , y1_4th ),"XB",ColorXB , styleDashed +styleNoTitle); 
		Plot (LineArray(x0_5th , y0_5th , x1_2nd , y1_2nd ),"XD",ColorXB , styleDashed +styleNoTitle); 
	}
	if (ShowEliotWavelines ==1)
	{
		Plot (LineArray(x1_1st , y1_1st , x1_0th , y1_0th ),"1st Top",Color2   ,Linestyle1 + styleNoTitle); 
		Plot (LineArray(x0_1st , y0_1st , x1_1st , y1_1st ),"1st Top",Color3 ,Linestyle1 + styleNoTitle); 
		Plot (LineArray(x0_2nd , y0_2nd , x1_2nd , y1_2nd ),"2nd Top",Color3 ,Linestyle1 + styleNoTitle); 
		Plot (LineArray(x0_3rd , y0_3rd , x1_3rd , y1_3rd ),"3rd Top",Color3 ,Linestyle1 + styleNoTitle); 
		Plot (LineArray(x0_4th , y0_4th , x1_4th , y1_4th ),"4th Top",Color3 ,Linestyle1 + styleNoTitle); 
		Plot (LineArray(x0_5th , y0_5th , x1_5th , y1_5th ),"5th Top",Color3 ,Linestyle1 + styleNoTitle); 
		Plot (LineArray(x0_6th , y0_6th , x1_6th , y1_6th ),"6th Top",Color3 ,Linestyle1 + styleNoTitle); 
		Plot (LineArray(x0_7th , y0_7th , x1_7th , y1_7th ),"7th Top",Color3 ,Linestyle1 + styleNoTitle); 
		Plot (LineArray(x0_8th , y0_8th , x1_8th , y1_8th ),"8th Top",Color3 ,Linestyle1 + styleNoTitle); 
	}
			printf(WriteIf(NoValidCompletedPattern ,"\nNo valid Completed Harmonic Pattern is available","" ) );

Separator = "\n-------------------------------";
	if (ShowInvalidCompletedPattern ==1 OR NoValidCompletedPattern ==0)
	{
		if (ShowLabels ==0 )
		{
			XXDtextPosition = (dx - xx)/2 + xx;
			YXDtextPosition = (dy - xy)/2 + xy;
			XXBtextPosition = (bx - xx)/2 + xx;
			YXBtextPosition = (by - xy)/2 + xy;
			XACtextPosition = (cx - ax)/2 + ax;
			YACtextPosition = (cy - ay)/2 + ay;
			XBDtextPosition = (dx - bx)/2 + bx;
			YBDtextPosition = (dy - by)/2 + by;

			PlotText(WriteIf(ad_of_xa<0, WriteVal(-ad_of_xa*100,1.2),WriteVal(ad_of_xa*100,1.2) ),XXDtextPosition , YXDtextPosition , colorViolet );
			PlotText(WriteVal(ab_of_xa*100,1.1),XXBtextPosition , YXBtextPosition , colorViolet );
			PlotText(WriteVal(bc_of_ab*100,1.1),XACtextPosition , YACtextPosition , colorViolet );
			PlotText(WriteVal(cd_of_bc*100,1.1),XBDtextPosition , YBDtextPosition , colorViolet );
		}

		if (ShowSuppRes1 ==0 )
		{	Plot (LineArray(x0_4th , y0_4th , BarCount , y0_4th ),"SuppResist",Color1 ,Linestyle1 + styleNoTitle); 
			Plot (LineArray(x0_2nd, y0_2nd, BarCount , y0_2nd),"SuppResist",Color1 ,Linestyle1 + styleNoTitle); 
			Plot (LineArray(x0_4th , y0_4th , x1_3rd   , y1_3rd,1 ),"AC",ColorXB , styleDashed + styleNoTitle); 
			PlotText("SR:: "+WriteVal(y0_2nd,1.2),TargetPosition , y0_2nd, colorViolet );
			PlotText("SR:: "+WriteVal(y0_4th ,1.2),TargetPosition , y0_4th , colorViolet );
		}
		if (ShowSuppRes2 ==0 )
		{	Plot (LineArray(x0_3rd , y0_3rd , BarCount , y0_3rd ),"SuppResist",Color1 ,Linestyle1 + styleNoTitle); 
			Plot (LineArray(x0_5th , y0_5th , BarCount , y0_5th ),"SuppResist",Color1 ,Linestyle1 + styleNoTitle); 
			Plot (LineArray(x0_5th , y0_5th , x1_4th , y1_4th ,1 ),"AC",ColorAC , styleDashed + styleNoTitle); 
			PlotText("SR:: "+WriteVal(y0_5th ,1.2),TargetPosition , y0_5th , colorViolet );
			PlotText("SR:: "+WriteVal(y0_3rd ,1.2),TargetPosition , y0_3rd , colorViolet );
		}
/*-----------------------------------------------------------------------------------------------------*/
	if (ShowAnalysisOnMainScreen  ==0 )
	{		if(CompletedButterflyBullishPattern)
			{	GfxSetTextColor(colorGreen); 
				GfxTextOut("Completed Butterfly Bullish (Buy)", 300 , 15); 
			}
			if(CompletedButterflyBearishPattern )
			{	GfxSetTextColor(colorRed); 
				GfxTextOut("Completed Butterfly Bearish (Sell)", 300 , 15); 
			}
			if(CompletedButterflyBullishPatternExtended)
			{	GfxSetTextColor(colorGreen); 
				GfxTextOut("Completed Butterfly Bullish Extended (Buy)", 300 , 15); 
			}
			if(CompletedButterflyBearishPatternExtended )
			{	GfxSetTextColor(colorRed); 
				GfxTextOut("Completed Butterfly Bearish Extended (Sell)", 300 , 15); 
			}
			if(CompletedButterflyBullishPattern OR CompletedButterflyBearishPattern 
						OR CompletedButterflyBullishPatternExtended OR CompletedButterflyBearishPatternExtended)
			{	PlotText("T1: "+WriteVal(CompletedButterflyTargetPrice1,1.2),TargetPosition , CompletedButterflyTargetPrice1, colorViolet );
				PlotText("T2: "+WriteVal(CompletedButterflyTargetPrice2,1.2),TargetPosition , CompletedButterflyTargetPrice2, colorViolet );
				PlotText("T3: "+WriteVal(CompletedButterflyTargetPrice3,1.2),TargetPosition , CompletedButterflyTargetPrice3, colorViolet );
			}

	}
			printf("\n");
			printf(WriteIf(CompletedButterflyBullishPattern ,Separator +"\nCompleted Butterfly Bullish ","" ));
			printf(WriteIf(CompletedButterflyBearishPattern ,Separator +"\nCompleted Butterfly Bearish ","" ));
			printf(WriteIf(CompletedButterflyBullishPatternExtended ,Separator +"\nCompleted Butterfly Bullish(Extended) ","" ));
			printf(WriteIf(CompletedButterflyBearishPatternExtended ,Separator +"\nCompleted Butterfly Bearish(Extended) ","" ));
			printf(WriteIf(CompletedButterflyBullishPattern 
								OR CompletedButterflyBearishPattern 
								OR CompletedButterflyBullishPatternExtended 
								OR CompletedButterflyBearishPatternExtended 
								,"\nClosing Price: "+WriteVal(LastValue(C),1.2)+"\nTarget Price:"
					+"\n1-    "+WriteVal(CompletedButterflyTargetPrice1,1.2 )  + " ("
					+WriteVal(CompletedButterflyTargetPricePct1,1.2) +"%%) "
					+(WriteIf(CompletedButterflyTargetPricePct1 > 0	AND CompletedButterflyBearishPattern , " Price Excceded Target", ""))
					+(WriteIf(CompletedButterflyTargetPricePct1 > 0	AND CompletedButterflyBearishPatternExtended , " Price Excceded Target", ""))
					+(WriteIf(CompletedButterflyTargetPricePct1 < 0	AND CompletedButterflyBullishPattern , " Price Excceded Target", ""))
					+(WriteIf(CompletedButterflyTargetPricePct1 < 0	AND CompletedButterflyBullishPatternExtended , " Price Excceded Target", ""))
					+"\n2-    "+WriteVal(CompletedButterflyTargetPrice2,1.2)  + " ( "
					+WriteVal(CompletedButterflyTargetPricePct2,1.2) +"%%) "
					+(WriteIf(CompletedButterflyTargetPricePct2 > 0	AND CompletedButterflyBearishPattern , " Price Excceded Target", ""))
					+(WriteIf(CompletedButterflyTargetPricePct2 > 0	AND CompletedButterflyBearishPatternExtended , " Price Excceded Target", ""))
					+(WriteIf(CompletedButterflyTargetPricePct2 < 0	AND CompletedButterflyBullishPattern, " Price Excceded Target ", ""))
					+(WriteIf(CompletedButterflyTargetPricePct2 < 0	AND CompletedButterflyBullishPatternExtended , " Price Excceded Target", ""))
					+"\n3-    "+WriteVal(CompletedButterflyTargetPrice3,1.2 ) + " ( "
					+WriteVal(CompletedButterflyTargetPricePct3,1.2) +"%%) "
					+(WriteIf(CompletedButterflyTargetPricePct3 > 0	AND CompletedButterflyBearishPattern , " Price Excceded Target", ""))
					+(WriteIf(CompletedButterflyTargetPricePct3 > 0	AND CompletedButterflyBearishPatternExtended , " Price Excceded Target", ""))
					+(WriteIf(CompletedButterflyTargetPricePct3 < 0	AND CompletedButterflyBullishPattern, " Price Excceded Target", ""))
					+(WriteIf(CompletedButterflyTargetPricePct3 < 0	AND CompletedButterflyBullishPatternExtended , " Price Excceded Target ", "")),""));

/*-----------------------------------------------------------------------------------------------------*/
	if (ShowAnalysisOnMainScreen  ==0 )
	{		if(CompletedCrabBullishPattern)
			{	GfxSetTextColor(colorGreen); 
				GfxTextOut("Completed Crab Bullish (Buy)", 300 , 15); 
			}
			if(CompletedCrabBearishPattern )
			{	GfxSetTextColor(colorRed); 
				GfxTextOut("Completed Crab Bearish (Sell)", 300 , 15); 
			}
			if(CompletedCrabBullishPatternExtended)
			{	GfxSetTextColor(colorGreen); 
				GfxTextOut("Completed Crab Bullish Extended (Buy)", 300 , 15); 
			}
			if(CompletedCrabBearishPatternExtended )
			{	GfxSetTextColor(colorRed); 
				GfxTextOut("Completed Crab Bearish Extended (Sell)", 300 , 15); 
			}
			if(CompletedCrabBullishPattern OR CompletedCrabBearishPattern 
						OR CompletedCrabBullishPatternExtended OR CompletedCrabBearishPatternExtended)
			{	PlotText("T1: "+WriteVal(CompletedCrabTargetPrice1,1.2),TargetPosition , CompletedCrabTargetPrice1, colorViolet );
				PlotText("T2: "+WriteVal(CompletedCrabTargetPrice2,1.2),TargetPosition , CompletedCrabTargetPrice2, colorViolet );
				PlotText("T3: "+WriteVal(CompletedCrabTargetPrice3,1.2),TargetPosition , CompletedCrabTargetPrice3, colorViolet );
			}

	}
			printf(WriteIf(CompletedCrabBullishPattern ,Separator +"\nCompleted Crab Bullish ","" ));
			printf(WriteIf(CompletedCrabBearishPattern ,Separator +"\nCompleted Crab Bearish ","" ));
			printf(WriteIf(CompletedCrabBullishPatternExtended ,Separator +"\nCompleted Crab Bullish(Extended) ","" ));
			printf(WriteIf(CompletedCrabBearishPatternExtended ,Separator +"\nCompleted Crab Bearish(Extended) ","" ));
			printf(WriteIf(CompletedCrabBullishPattern 
								OR CompletedCrabBearishPattern 
								OR CompletedCrabBullishPatternExtended 
								OR CompletedCrabBearishPatternExtended 
								,"\nClosing Price: "+WriteVal(LastValue(C),1.2)+"\nTarget Price:"
					+"\n1-    "+WriteVal(CompletedCrabTargetPrice1,1.2 )  + " ("
					+WriteVal(CompletedCrabTargetPricePct1,1.2) +"%%) "
					+(WriteIf(CompletedCrabTargetPricePct1 > 0 AND CompletedCrabBearishPattern, " Price Excceded Target", ""))
					+(WriteIf(CompletedCrabTargetPricePct1 > 0 AND CompletedCrabBearishPatternExtended, " Price Excceded Target", ""))
					+(WriteIf(CompletedCrabTargetPricePct1 < 0 AND CompletedCrabBullishPattern, " Price Excceded Target", ""))
					+(WriteIf(CompletedCrabTargetPricePct1 < 0 AND CompletedCrabBullishPatternExtended , " Price Excceded Target", ""))
					+"\n2-    "+WriteVal(CompletedCrabTargetPrice2,1.2)  + " ( "
					+WriteVal(CompletedCrabTargetPricePct2,1.2) +"%%) "
					+(WriteIf(CompletedCrabTargetPricePct2 > 0 AND CompletedCrabBearishPattern, " Price Excceded Target", ""))
					+(WriteIf(CompletedCrabTargetPricePct2 > 0 AND CompletedCrabBearishPatternExtended, " Price Excceded Target", ""))
					+(WriteIf(CompletedCrabTargetPricePct2 < 0 AND CompletedCrabBullishPattern, " Price Excceded Target", ""))
					+(WriteIf(CompletedCrabTargetPricePct2 < 0 AND CompletedCrabBullishPatternExtended , " Price Excceded Target", ""))
					+"\n3-    "+WriteVal(CompletedCrabTargetPrice3,1.2 ) + " ( "
					+WriteVal(CompletedCrabTargetPricePct3,1.2) +"%%) "
					+(WriteIf(CompletedCrabTargetPricePct3 > 0 AND CompletedCrabBearishPattern, " Price Excceded Target", ""))
					+(WriteIf(CompletedCrabTargetPricePct3 > 0 AND CompletedCrabBearishPatternExtended, " Price Excceded Target", ""))
					+(WriteIf(CompletedCrabTargetPricePct3 < 0 AND CompletedCrabBullishPattern , " Price Excceded Target", ""))
					+(WriteIf(CompletedCrabTargetPricePct3 < 0 AND CompletedCrabBullishPatternExtended, " Price Excceded Target ", "")),""));

/*-----------------------------------------------------------------------------------------------------*/
	if (ShowAnalysisOnMainScreen  ==0 )
	{		if(CompletedBatBullishPattern)
			{	GfxSetTextColor(colorGreen); 
				GfxTextOut("Completed Bat Bullish (Buy)", 300 , 15); 
			}
			if(CompletedBatBearishPattern )
			{	GfxSetTextColor(colorRed); 
				GfxTextOut("Completed Bat Bearish (Sell)", 300 , 15); 
			}
			if(CompletedBatBullishPatternExtended)
			{	GfxSetTextColor(colorGreen); 
				GfxTextOut("Completed Bat Bullish Extended (Buy)", 300 , 15); 
			}
			if(CompletedBatBearishPatternExtended )
			{	GfxSetTextColor(colorRed); 
				GfxTextOut("Completed Bat Bearish Extended (Sell)", 300 , 15); 
			}
			if(CompletedBatBullishPattern OR CompletedBatBearishPattern 
						OR CompletedBatBullishPatternExtended OR CompletedBatBearishPatternExtended)
			{	PlotText("T1: "+WriteVal(CompletedBatTargetPrice1,1.2),TargetPosition , CompletedBatTargetPrice1, colorViolet );
				PlotText("T2: "+WriteVal(CompletedBatTargetPrice2,1.2),TargetPosition , CompletedBatTargetPrice2, colorViolet );
				PlotText("T3: "+WriteVal(CompletedBatTargetPrice3,1.2),TargetPosition , CompletedBatTargetPrice3, colorViolet );
			}

	}
			printf(WriteIf(CompletedBatBullishPattern ,Separator +"\nCompleted Bat Bullish ","" ));
			printf(WriteIf(CompletedBatBearishPattern ,Separator +"\nCompleted Bat Bearish ","" ));
			printf(WriteIf(CompletedBatBullishPatternExtended ,Separator +"\nCompleted Bat Bullish(Extended) ","" ));
			printf(WriteIf(CompletedBatBearishPatternExtended ,Separator +"\nCompleted Bat Bearish(Extended) ","" ));
			printf(WriteIf(CompletedBatBullishPattern 
								OR CompletedBatBearishPattern 
								OR CompletedBatBullishPatternExtended 
								OR CompletedBatBearishPatternExtended 
								,"\nClosing Price: "+WriteVal(LastValue(C),1.2)+"\nTarget Price:"
					+"\n1-    "+WriteVal(CompletedBatTargetPrice1,1.2 )  + " ("
					+WriteVal(CompletedBatTargetPricePct1,1.2) +"%%) "
					+(WriteIf(CompletedBatTargetPricePct1 > 0 AND CompletedBatBearishPattern, " Price Excceded Target", ""))
					+(WriteIf(CompletedBatTargetPricePct1 > 0 AND CompletedBatBearishPatternExtended, " Price Excceded Target", ""))
					+(WriteIf(CompletedBatTargetPricePct1 < 0 AND CompletedBatBullishPattern, " Price Excceded Target", ""))
					+(WriteIf(CompletedBatTargetPricePct1 < 0 AND CompletedBatBullishPatternExtended , " Price Excceded Target", ""))
					+"\n2-    "+WriteVal(CompletedBatTargetPrice2,1.2)  + " ( "
					+WriteVal(CompletedBatTargetPricePct2,1.2) +"%%) "
					+(WriteIf(CompletedBatTargetPricePct2 > 0 AND CompletedBatBearishPattern, " Price Excceded Target", ""))
					+(WriteIf(CompletedBatTargetPricePct2 > 0 AND CompletedBatBearishPatternExtended, " Price Excceded Target", ""))
					+(WriteIf(CompletedBatTargetPricePct2 < 0 AND CompletedBatBullishPattern, " Price Excceded Target ", ""))
					+(WriteIf(CompletedBatTargetPricePct2 < 0 AND CompletedBatBullishPatternExtended , " Price Excceded Target ", ""))
					+"\n3-    "+WriteVal(CompletedBatTargetPrice3,1.2 ) + " ( "
					+WriteVal(CompletedBatTargetPricePct3,1.2) +"%%) "
					+(WriteIf(CompletedBatTargetPricePct3 > 0 AND CompletedBatBearishPattern, " Price Excceded Target", ""))
					+(WriteIf(CompletedBatTargetPricePct3 > 0 AND CompletedBatBearishPatternExtended, " Price Excceded Target", ""))
					+(WriteIf(CompletedBatTargetPricePct3 < 0 AND CompletedBatBullishPattern, " Price Excceded Target", ""))	
					+(WriteIf(CompletedBatTargetPricePct3 < 0 AND CompletedBatBullishPatternExtended , " Price Excceded Target", "")),""));

/*-----------------------------------------------------------------------------------------------------*/
	if (ShowAnalysisOnMainScreen  ==0 )
	{		if(CompletedGartleyBullishPattern)
			{	GfxSetTextColor(colorGreen); 
				GfxTextOut("Completed Gartley Bullish (Buy)", 300 , 15); 
			}
			if(CompletedGartleyBearishPattern )
			{	GfxSetTextColor(colorRed); 
				GfxTextOut("Completed Gartley Bearish (Sell)", 300 , 15); 
			}
			if(CompletedGartleyBullishPatternExtended)
			{	GfxSetTextColor(colorGreen); 
				GfxTextOut("Completed Gartley Bullish Extended (Buy)", 300 , 15); 
			}
			if(CompletedGartleyBearishPatternExtended )
			{	GfxSetTextColor(colorRed); 
				GfxTextOut("Completed Gartley Bearish Extended (Sell)", 300 , 15); 
			}
			if(CompletedGartleyBullishPattern OR CompletedGartleyBearishPattern 
						OR CompletedGartleyBullishPatternExtended OR CompletedGartleyBearishPatternExtended)
			{	PlotText("T1: "+WriteVal(CompletedGartleyTargetPrice1,1.2),TargetPosition , CompletedGartleyTargetPrice1, colorViolet );
				PlotText("T2: "+WriteVal(CompletedGartleyTargetPrice2,1.2),TargetPosition , CompletedGartleyTargetPrice2, colorViolet );
				PlotText("T3: "+WriteVal(CompletedGartleyTargetPrice3,1.2),TargetPosition , CompletedGartleyTargetPrice3, colorViolet );
			}

	}
			printf(WriteIf(CompletedGartleyBullishPattern ,Separator +"\nCompleted Gartley Bullish ","" ));
			printf(WriteIf(CompletedGartleyBearishPattern ,Separator +"\nCompleted Gartley Bearish ","" ));
			printf(WriteIf(CompletedGartleyBullishPatternExtended ,Separator +"\nCompleted Gartley Bullish(Extended) ","" ));
			printf(WriteIf(CompletedGartleyBearishPatternExtended ,Separator +"\nCompleted Gartley Bearish(Extended) ","" ));
			printf(WriteIf(CompletedGartleyBullishPattern 
								OR CompletedGartleyBearishPattern 
								OR CompletedGartleyBullishPatternExtended 
								OR CompletedGartleyBearishPatternExtended 
								,"\nClosing Price: "+WriteVal(LastValue(C),1.2)+"\nTarget Price:"
					+"\n1-    "+WriteVal(CompletedGartleyTargetPrice1,1.2 )  + " ("
					+WriteVal(CompletedGartleyTargetPricePct1,1.2) +"%%) "
					+(WriteIf(CompletedGartleyTargetPricePct1 > 0 AND CompletedGartleyBearishPattern , " Price Excceded Target", ""))
					+(WriteIf(CompletedGartleyTargetPricePct1 > 0 AND CompletedGartleyBearishPatternExtended , " Price Excceded Target", ""))
					+(WriteIf(CompletedGartleyTargetPricePct1 < 0 AND CompletedGartleyBullishPattern , " Price Excceded Target", ""))
					+(WriteIf(CompletedGartleyTargetPricePct1 < 0 AND CompletedGartleyBullishPatternExtended , " Price Excceded Target", ""))
					+"\n2-    "+WriteVal(CompletedGartleyTargetPrice2,1.2)  + " ( "
					+WriteVal(CompletedGartleyTargetPricePct2,1.2) +"%%) "
					+(WriteIf(CompletedGartleyTargetPricePct2 > 0 AND CompletedGartleyBearishPattern , " Price Excceded Target", ""))
					+(WriteIf(CompletedGartleyTargetPricePct2 > 0 AND CompletedGartleyBearishPatternExtended , " Price Excceded Target", ""))
					+(WriteIf(CompletedGartleyTargetPricePct2 < 0 AND CompletedGartleyBullishPattern, " Price Excceded Target", ""))
					+(WriteIf(CompletedGartleyTargetPricePct2 < 0 AND CompletedGartleyBullishPatternExtended , " Price Excceded Target", ""))
					+"\n3-    "+WriteVal(CompletedGartleyTargetPrice3,1.2 ) + " ( "
					+WriteVal(CompletedGartleyTargetPricePct3,1.2) +"%%) "	
					+(WriteIf(CompletedGartleyTargetPricePct3 > 0 AND CompletedGartleyBearishPattern , " Price Excceded Target", ""))
					+(WriteIf(CompletedGartleyTargetPricePct3 > 0 AND CompletedGartleyBearishPatternExtended , " Price Excceded Target", ""))
					+(WriteIf(CompletedGartleyTargetPricePct3 < 0 AND CompletedGartleyBullishPattern, " Price Excceded Target", ""))
					+(WriteIf(CompletedGartleyTargetPricePct3 < 0 AND CompletedGartleyBullishPatternExtended , " Price Excceded Target", "")),""));
/*-----------------------------------------------------------------------------------------------------*/

	}


_SECTION_END(); //Eof Completed Harmonic Trader
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

_SECTION_BEGIN("Developing Harmonic Trader");
strength = Param("Strength",5,2,15,1);
//bu = ParamToggle("Bullish Pattern","Off|On",1);
//be = ParamToggle("Bearish Pattern","Off|On",1);

bi = Cum(1)-1;

function GetTop(bars) 
	{
		Top = H == HHV(H,2*bars) AND Ref(HHV(H,bars),bars) < H;
		Top = Top AND LastValue(bi)-ValueWhen(Top,bi) > bars;
		return Top;
	}

function GetValley(bars)
	{
		Valley = L == LLV(L,2*bars) AND Ref(LLV(L,bars),bars) > L;
		Valley = Valley AND LastValue(bi)-ValueWhen(Valley,bi) > bars;
		return Valley;
	}


// Build fractals array

P1 = GetTop(strength);
V1 = GetValley(Strength);

P1 = IIf(P1,IIf(ValueWhen(P1,bi,2) < ValueWhen(V1,bi),P1,IIf(ValueWhen(P1,H,2) > H,False,P1)),P1);
//P1 = IIf(P1 AND ValueWhen(P1,bi,0) > bi,IIf(ValueWhen(P1,bi,0) < ValueWhen(V1,bi,0),IIf(ValueWhen(P1,H,0) >= H,False,P1),P1),P1);
P1 = IIf(P1 AND ValueWhen(P1,bi,0) > bi AND NOT(ValueWhen(V1,bi,0) > 0 AND ValueWhen(V1,bi,0)<ValueWhen(P1,bi,0)),IIf(ValueWhen(P1,H)<=ValueWhen(P1,H,0),False,P1),P1);


V1 = IIf(V1,IIf(ValueWhen(V1,bi,2) < ValueWhen(P1,bi),V1,IIf(ValueWhen(V1,L,2)<L,False,V1)),V1);
//V1 = IIf(V1 AND ValueWhen(V1,bi,0) > bi ,IIf(ValueWhen(V1,bi,0) < ValueWhen(P1,bi,0),IIf(ValueWhen(V1,L,0) <= L, False,V1),V1),V1); 
V1 = IIf(V1 AND ValueWhen(V1,bi,0) > bi AND NOT(ValueWhen(P1,bi,0) > bi AND ValueWhen(P1,bi,0)<ValueWhen(V1,bi,0))  , IIf(ValueWhen(V1,L)>=ValueWhen(V1,L,0),False,V1),V1);


//P1H1 = ValueWhen(P1,H);
//P1Bar1 = ValueWhen(P1,bi);
//P1H2 = ValueWhen(P1,H,2);
//P1Bar2 = ValueWhen(P1,bi,2);
//V1L1 = ValueWhen(V1,L);
//V1Bar1 = ValueWhen(V1,bi);
//V1L2 = ValueWhen(V1,L,2);
//V1Bar2 = ValueWhen(V1,bi,2);

 	Level_236 = 0.236;
 	Level_382 = 0.382;
 	Level_500 = 0.500;
 	Level_618 = 0.618;
 	Level_786 = 0.786;
 	Level_886 = 0.886;
 	Level_127 = 1.27;
 	Level_1618 = 1.618;

	xa = Wave_4th ;	ab = Wave_3rd ;	bc = Wave_2nd ;	Cd = Wave_1st ; ad = y1_1st - y1_4th ; 
	A_price = y1_4th; 
	D_price = Y1_1st;
	ab_of_xa = ab/xa ;
	bc_of_ab = bc/ab ;
	Cd_of_bc = Cd/bc ;
	ad_of_xa = ad/xa ;
	showlengthXABCD = ParamToggle("Show Side Length of XABCD ", "Yes|No" );
	if (showlengthXABCD ==0)
	{
		printf(Separator);
		printf("\nDeveloping Pattern info:" );
		printf("\nXA = "+xa );
		printf("\nAB = "+ab + "  ("+WriteVal(ab_of_xa,1.2)+"%% of XA)");
		printf("\nBC = "+bc + "  ("+WriteVal(bc_of_ab,1.2)+"%% of AB)");
		printf("\nCD = "+Cd + "  ("+WriteVal(Cd_of_bc,1.2)+"%% of BC)");
		printf("\nAD = "+Cd + "  ("+WriteVal(ad_of_xa,1.2)+"%% of XA)");
	}

/*-----------------------------------------------------------------------*/

	LastSwingDays = x1_0th - x1_1st;
	HighSwing  = y1_1st ;
	if(LastSwingDays == 0)
		HighSwing  = y1_2nd ;
	LowSwing  =  y1_0th  = LastValue(L);
	if(LowSwing > HighSwing)
		LowSwing  =  y1_0th  = LastValue(H) ;
	if(LastSwingDays == 0 AND LowSwing < HighSwing )
		LowSwing  =  y1_1st = LastValue(L);
	if(LastSwingDays == 0 AND LowSwing > HighSwing )
		LowSwing  =  y1_1st = LastValue(H);

	Wave1 = y1_1st - y1_2nd 	;
	if(LastSwingDays == 0)		
		Wave1 = y1_2nd - y0_2nd 	;

	wave0 = IIf(LowSwing > HighSwing, HighSwing-LowSwing, LowSwing - HighSwing ) ;

	if(LastSwingDays == 0)
		LastSwingDays = x1_1st- x1_2nd ;

	LastSwingDays = LastSwingDays + 1;
	FiboValue = wave0 / Wave1 *100;
	LastSwingPct  = (LowSwing -HighSwing)/HighSwing*100;

		XX = x0_4th;
		XY = y0_4th;
		AX = x0_3rd;
		AY = y0_3rd;
		BX = x0_2nd;
		BY = y0_2nd;
		CX = x0_1st;
		CY = y0_1st;
		DX = x1_1st;
		DY = y1_1st;

	Tolerance = 0.1;
	ButterflyCondition1 = (ab_of_xa >=	 Level_786 - Tolerance) AND (ab_of_xa <= Level_786 + Tolerance);	
	ButterflyCondition2 = (bc_of_ab >= Level_382 - Tolerance) AND (bc_of_ab <= Level_886 + Tolerance);	
	ButterflyCondition3 = (ad_of_xa >= Level_236 - 0) AND (ad_of_xa <= Level_1618 );	
	ButterflyCondition4 = ad_of_xa > Level_1618 ;	
	ButterflyCondition5 = (-ad_of_xa >= Level_382 - Tolerance) AND (-ad_of_xa <= Level_1618 );	
	ButterflyCondition6 = -ad_of_xa > Level_1618 ;	
	DevelopingButterflyBearishPattern = ButterflyCondition1 AND ButterflyCondition2 AND ButterflyCondition3 ;
	DevelopingButterflyBearishPatternExtended = ButterflyCondition1 AND ButterflyCondition2 AND ButterflyCondition4 ;
	DevelopingButterflyBullishPattern = ButterflyCondition1 AND ButterflyCondition2 AND ButterflyCondition5 ;
	DevelopingButterflyBullishPatternExtended = ButterflyCondition1 AND ButterflyCondition2 AND ButterflyCondition6 ;

	DevelopingButterflyTargetPrice1 = IIf(DevelopingButterflyBearishPattern ,
												xa * Level_127 + A_price  , 
												A_price - xa * Level_127) ;
	DevelopingButterflyTargetPrice2 = IIf(DevelopingButterflyBearishPattern ,
												xa * Level_1618 + A_price , 
												A_price - xa * Level_1618)  ;
	DevelopingButterflyTargetPrice3 = IIf(DevelopingButterflyBearishPatternExtended ,
												D_price - CD * Level_618,
												CD * Level_618 + D_price); 
	DevelopingButterflyTargetPrice4 = IIf(DevelopingButterflyBearishPatternExtended ,
												D_price - CD * Level_127,
												CD * Level_127+ D_price); 
	DevelopingButterflyTargetPrice5 = IIf(DevelopingButterflyBearishPatternExtended ,
												D_price - CD * Level_1618,
												CD * Level_1618 + D_price); 
	DevelopingButterflyTargetPricePct1 = 	(DevelopingButterflyTargetPrice1 - LastValue(C))/LastValue(C)*100;
	DevelopingButterflyTargetPricePct2 = 	(DevelopingButterflyTargetPrice2 - LastValue(C))/LastValue(C)*100;
	DevelopingButterflyTargetPricePct3 = 	(DevelopingButterflyTargetPrice3 - LastValue(C))/LastValue(C)*100;
	DevelopingButterflyTargetPricePct4 = 	(DevelopingButterflyTargetPrice4 - LastValue(C))/LastValue(C)*100;
	DevelopingButterflyTargetPricePct5 = 	(DevelopingButterflyTargetPrice5 - LastValue(C))/LastValue(C)*100;

/*-----------------------------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------------------------*/
	Tolerance = 0.05;
	CrabCondition1 = (ab_of_xa >= Level_382 - Tolerance) AND (ab_of_xa < Level_618 + Tolerance);	
	CrabCondition2 = (bc_of_ab >= Level_382 - 0.1) AND (bc_of_ab <= Level_886 + 0.1);	
	CrabCondition3 = (ad_of_xa > Level_786 - 0.1) AND (ad_of_xa < Level_1618 );	
	CrabCondition4 = ad_of_xa > Level_1618;	
	CrabCondition5 = (-ad_of_xa >= Level_786 - Tolerance) AND (-ad_of_xa <= Level_1618 );	
	CrabCondition6 = -ad_of_xa > Level_1618;	
	DevelopingCrabBearishPattern = CrabCondition1 AND CrabCondition2 AND CrabCondition3 ;
	DevelopingCrabBearishPatternExtended = CrabCondition1 AND CrabCondition2 AND CrabCondition4 ;
	DevelopingCrabBullishPattern = CrabCondition1 AND CrabCondition2 AND CrabCondition5 ;
	DevelopingCrabBullishPatternExtended = CrabCondition1 AND CrabCondition2 AND CrabCondition6 ;
	DevelopingCrabTargetPrice1 = IIf(DevelopingCrabBearishPattern ,
											xa * Level_127 + A_price  , 
											A_price - xa * Level_127) ;
	DevelopingCrabTargetPrice2 = IIf(DevelopingCrabBearishPattern ,
											xa * Level_1618 + A_price , 
											A_price - xa * Level_1618)  ;
	DevelopingCrabTargetPrice3 = IIf(DevelopingCrabBearishPatternExtended ,
											D_price - CD * Level_618,
											CD * Level_618+ D_price); 
	DevelopingCrabTargetPrice4 = IIf(DevelopingCrabBearishPatternExtended ,
											D_price - CD * Level_127 ,
											CD * Level_127 + D_price); 
	DevelopingCrabTargetPrice5 = IIf(DevelopingCrabBearishPatternExtended ,
											D_price - CD * Level_1618,
											CD * Level_1618 + D_price); 
	DevelopingCrabTargetPricePct1 = 	(DevelopingCrabTargetPrice1 - LastValue(C))/LastValue(C)*100;
	DevelopingCrabTargetPricePct2 = 	(DevelopingCrabTargetPrice2 - LastValue(C))/LastValue(C)*100;
	DevelopingCrabTargetPricePct3 = 	(DevelopingCrabTargetPrice3 - LastValue(C))/LastValue(C)*100;
	DevelopingCrabTargetPricePct4 = 	(DevelopingCrabTargetPrice4 - LastValue(C))/LastValue(C)*100;
	DevelopingCrabTargetPricePct5 = 	(DevelopingCrabTargetPrice5 - LastValue(C))/LastValue(C)*100;


	
/*-----------------------------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------------------------*/
	Tolerance = 0.05;
	GartleyCondition1 = (ab_of_xa >= Level_618 - Tolerance) AND (ab_of_xa < Level_618 + Tolerance);	
	GartleyCondition2 = (bc_of_ab >= Level_382 - 0.1) AND (bc_of_ab <= Level_886 + 0.1);	
	GartleyCondition3 = (ad_of_xa > Level_236 - 0) AND (ad_of_xa < Level_786);	
	GartleyCondition4 = ad_of_xa > Level_786 AND ad_of_xa < Level_1618;	
	GartleyCondition5 = (-ad_of_xa >= Level_382 - Tolerance) AND (-ad_of_xa <= Level_786);	
	GartleyCondition6 = -ad_of_xa > Level_786 AND -ad_of_xa < Level_1618 ;	
	DevelopingGartleyBearishPattern = GartleyCondition1 AND GartleyCondition2 AND GartleyCondition3 ;
	DevelopingGartleyBearishPatternExtended = GartleyCondition1 AND GartleyCondition2 AND GartleyCondition4 ;
	DevelopingGartleyBullishPattern = GartleyCondition1 AND GartleyCondition2 AND GartleyCondition5 ;
	DevelopingGartleyBullishPatternExtended = GartleyCondition1 AND GartleyCondition2 AND GartleyCondition6 ;
	DevelopingGartleyTargetPrice1 = IIf(DevelopingGartleyBearishPattern ,
											xa * Level_786+ A_price  , 
											A_price - xa * Level_786) ;
	DevelopingGartleyTargetPrice3 = IIf(DevelopingGartleyBearishPatternExtended ,
											D_price - CD * Level_618,
											CD * Level_618 + D_price); 
	DevelopingGartleyTargetPrice4 = IIf(DevelopingGartleyBearishPatternExtended ,
											D_price - CD * Level_127,
												CD * Level_127+ D_price); 
	DevelopingGartleyTargetPrice5 = IIf(DevelopingGartleyBearishPatternExtended ,
											D_price - CD * Level_1618,
											CD * Level_1618 + D_price); 
	DevelopingGartleyTargetPricePct1 = 	(DevelopingGartleyTargetPrice1 - LastValue(C))/LastValue(C)*100;
	DevelopingGartleyTargetPricePct3 = 	(DevelopingGartleyTargetPrice3 - LastValue(C))/LastValue(C)*100;
	DevelopingGartleyTargetPricePct4 = 	(DevelopingGartleyTargetPrice4 - LastValue(C))/LastValue(C)*100;
	DevelopingGartleyTargetPricePct5 = 	(DevelopingGartleyTargetPrice5 - LastValue(C))/LastValue(C)*100;


/*-----------------------------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------------------------*/
	Tolerance = 0.05;
	BatCondition1 = (ab_of_xa >= Level_382 - Tolerance) AND (ab_of_xa < Level_500 + Tolerance);	
	BatCondition2 = (bc_of_ab >= Level_382 - 0.1) AND (bc_of_ab <= Level_886 + 0.1);	
	BatCondition3 = (ad_of_xa> Level_236 - 0) AND (ad_of_xa < Level_886);	
	BatCondition4 = ad_of_xa > Level_886  AND ad_of_xa < Level_1618;	
	BatCondition5 = (-ad_of_xa >= Level_382 - Tolerance) AND (-ad_of_xa <= Level_886);	
	BatCondition6 = -ad_of_xa > Level_886  AND -ad_of_xa < Level_1618 ;	
	DevelopingBatBearishPattern = BatCondition1 AND BatCondition2 AND BatCondition3 ;
	DevelopingBatBearishPatternExtended = BatCondition1 AND BatCondition2 AND BatCondition4 ;
	DevelopingBatBullishPattern = BatCondition1 AND BatCondition2 AND BatCondition5 ;
	DevelopingBatBullishPatternExtended = BatCondition1 AND BatCondition2 AND BatCondition6 ;
	DevelopingBatTargetPrice1 = IIf(DevelopingBatBearishPattern ,
											xa * Level_886+ A_price  , 
											A_price - xa * Level_886) ;
	DevelopingBatTargetPrice3 = IIf(DevelopingBatBearishPatternExtended ,
										D_price - CD * Level_618 ,
										CD * Level_618 + D_price); 
	DevelopingBatTargetPrice4 = IIf(DevelopingBatBearishPatternExtended ,
										D_price - CD * Level_127,
										CD * Level_127+ D_price); 
	DevelopingBatTargetPrice5 = IIf(DevelopingBatBearishPatternExtended ,
										D_price - CD * Level_1618,
										CD * Level_1618+ D_price); 
	DevelopingBatTargetPricePct1 = 	(DevelopingBatTargetPrice1 - LastValue(C))/LastValue(C)*100;
	DevelopingBatTargetPricePct3 = 	(DevelopingBatTargetPrice3 - LastValue(C))/LastValue(C)*100;
	DevelopingBatTargetPricePct4 = 	(DevelopingBatTargetPrice4 - LastValue(C))/LastValue(C)*100;
	DevelopingBatTargetPricePct5 = 	(DevelopingBatTargetPrice5 - LastValue(C))/LastValue(C)*100;


	NoValidDevelopingPattern = 

		DevelopingButterflyBearishPattern ==0 AND DevelopingButterflyBullishPattern ==0 AND 
		DevelopingButterflyBearishPatternExtended ==0 AND DevelopingButterflyBullishPatternExtended ==0 AND 

		DevelopingCrabBearishPattern ==0 AND DevelopingCrabBullishPattern ==0 AND 
		DevelopingCrabBearishPatternExtended ==0 AND DevelopingCrabBullishPatternExtended ==0 AND

		DevelopingGartleyBearishPattern ==0 AND DevelopingGartleyBullishPattern ==0 AND 
		DevelopingGartleyBearishPatternExtended ==0 AND DevelopingGartleyBullishPatternExtended ==0 AND

		DevelopingBatBearishPattern ==0 AND DevelopingBatBullishPattern ==0 AND 
		DevelopingBatBearishPatternExtended ==0 AND DevelopingBatBullishPatternExtended ==0;

		ShowInvalidDevelopingPattern = ParamToggle("Show Also Invalid Pattern", "Show Pattern|Hide Pattern" );
		x = y0_4th;
		y = y0_3rd;
		Bear = y0_4th > y0_3rd;
		TextPositionX = y0_4th * -.03;
		if(Bear == 1)
			TextPositionX = y0_4th * .01;
			if(TextPositionX > 1)
				TextPositionX = 1;
			if(TextPositionX < -1)
				TextPositionX = -1;

		TextPositionA = y0_3rd * .01;
		if(Bear == 1)
			TextPositionA = y0_3rd * -.05;
			if(TextPositionA > 1)
				TextPositionA = 1;
			if(TextPositionA < -1.5)
				TextPositionA = -1.5;

		TextPositionB = y0_2nd * -.03;
		if(Bear == 1)
			TextPositionB = y0_2nd * .01;
			if(TextPositionB > 1)
				TextPositionB = 1;
			if(TextPositionB < -1.5)
				TextPositionB = -1.5;

		TextPositionC = y0_1st * .01;
		if(Bear == 1)
			TextPositionC = y0_1st * -.05;
			if(TextPositionC > 1)
				TextPositionC = 1;
			if(TextPositionC < -1.5)
				TextPositionC = -1.5;

		TextPositionD = y1_1st * -.03;
		if(Bear == 1)
			TextPositionD = y1_1st * .01;
			if(TextPositionD > 1)
				TextPositionD = 1;
			if(TextPositionD < -1.5)
				TextPositionD = -1.5;

		Color1 = ParamColor("Color XABCD Main Line",colorGreen);
		ColorXB = ParamColor("Color XB Dashed Line",colorBlack);
		ColorAC = ParamColor("Color AC Dashed Line",colorBlack);
		ColorBD = ParamColor("Color BD Dashed Line",colorBlack);
	if (ShowInvalidDevelopingPattern ==0 OR NoValidDevelopingPattern ==0)
	{

 		plus = 0;
		if(ShowInvalidCompletedPattern ==1 OR NoValidCompletedPattern ==0)	
			plus = 0;
		else 
		{

			PlotText("X",x0_4th , y0_4th +TextPositionX , colorViolet ); 
			PlotText("A",x0_3rd , y0_3rd +TextPositionA , colorViolet ); 
			PlotText("B",x0_2nd , y0_2nd +TextPositionB , colorViolet ); 
			PlotText("C",x0_1st , y0_1st +TextPositionC , colorViolet ); 
			PlotText("D",x1_1st , y1_1st +TextPositionD , colorViolet ); 

		}

		Plot (LineArray(x0_4th + plus , y0_4th , x1_4th + plus , y1_4th ),"XA Top",Color1 ,Linestyle1 + styleNoTitle); 
		Plot (LineArray(x0_3rd + plus , y0_3rd , x1_3rd + plus , y1_3rd ),"AB",Color1 ,Linestyle1 + styleNoTitle); 
		Plot (LineArray(x0_2nd + plus , y0_2nd , x1_2nd + plus , y1_2nd ),"BC",Color1,Linestyle1 + styleNoTitle); 
		Plot (LineArray(x0_1st + plus , y0_1st , x1_1st + plus , y1_1st ),"CD",Color1 ,Linestyle1 + styleNoTitle); 
		Plot (LineArray(x1_1st + plus , y1_1st , x1_0th + plus , y1_0th ),"DE",colorViolet ,styleLine + styleNoTitle); 

		Plot (LineArray(x0_4th         , y0_4th , x1_3rd       , y1_3rd ),"XB",ColorXB , styleDashed + styleNoTitle); 
	}
	printf(WriteIf(NoValidDevelopingPattern ,"\n\nNo valid Developing Harmonic Pattern is available","" ) );

	HeaderTextPosition = 15;
	XXBtextPosition = (bx - xx)/2 + xx;
	YXBtextPosition = (by - xy)/2 + xy ;
	XACtextPosition = (cx - ax)/2 + ax;
	YACtextPosition = (cy - ay)/2 + ay;
	XBDtextPosition = (dx - bx)/2 + bx;
	YBDtextPosition = (dy - by)/2 + by;
	XXDtextPosition = (dx - xx)/2 + xx;
	YXDtextPosition = (dy - xy)/2 + xy;

	if(NoValidTrend >= 2 OR NoValidTrend == 1 AND _x0_5th == 0 )
	{	GfxSetTextColor(colorRed); 
		GfxTextOut("No Valid Pattern or Trend ", 300 , 15); 
	}

	if (ShowAnalysisOnMainScreen  ==0 )
	{	if(NoValidCompletedPattern ==1 AND NoValidDevelopingPattern ==1)
		{	GfxSetTextColor(colorRed); 
			GfxTextOut("No Valid Pattern or Trend", 300 , 15); 
		}
	}
	if (ShowInvalidDevelopingPattern ==0 OR NoValidDevelopingPattern ==0)
	{
		if (ShowLabels ==0 )
		{
			PlotText(WriteVal(ab_of_xa*100,1.1),XXBtextPosition , YXBtextPosition , colorViolet );
			PlotText(WriteVal(bc_of_ab*100,1.1),XACtextPosition , YACtextPosition , colorViolet );
			PlotText(WriteVal(cd_of_bc*100,1.1),XBDtextPosition , YBDtextPosition , colorViolet );
		}
/*-----------------------------------------------------------------------------------------------------*/
			printf(WriteIf(DevelopingButterflyBullishPattern ,Separator +"\nDeveloping Butterfly Bullish (Sell)","" ));
			printf(WriteIf(DevelopingButterflyBearishPattern ,Separator +"\nDeveloping Butterfly Bearish (Buy)","" ));
			printf(WriteIf(DevelopingButterflyBullishPatternExtended ,Separator +"\nDeveloping Butterfly Bullish(Extended) (Buy)","" ));
			printf(WriteIf(DevelopingButterflyBearishPatternExtended ,Separator +"\nDeveloping Butterfly Bearish(Extended) (Sell)","" ));
			printf(WriteIf(DevelopingButterflyBullishPattern 
						  OR DevelopingButterflyBearishPattern 
								,"\nClosing Price: "+WriteVal(LastValue(C),1.2)+"\nTarget Price:"
					+"\n1-    "+WriteVal(DevelopingButterflyTargetPrice1,1.2 )  + " ("
					+WriteVal(DevelopingButterflyTargetPricePct1,1.2) +"%%) ",""));
					printf(WriteIf(LastValue(C) < DevelopingButterflyTargetPrice1 AND DevelopingButterflyBullishPattern ,
							 " Price Excceded Target", ""));					
					printf(WriteIf(LastValue(C) > DevelopingButterflyTargetPrice1 AND DevelopingButterflyBearishPattern ,
							 " Price Excceded Target", ""));

			printf(WriteIf(DevelopingButterflyBullishPattern 
						  OR DevelopingButterflyBearishPattern 
					,"\n2-    "+WriteVal(DevelopingButterflyTargetPrice2,1.2 )  + " ("
					+WriteVal(DevelopingButterflyTargetPricePct2,1.2) +"%%) ",""));
					printf(WriteIf(LastValue(C) < DevelopingButterflyTargetPrice2 AND DevelopingButterflyBullishPattern ,
							 " Price Excceded Target", ""));					
					printf(WriteIf(LastValue(C) > DevelopingButterflyTargetPrice2 AND DevelopingButterflyBearishPattern ,
							 " Price Excceded Target", ""));
			printf(WriteIf(DevelopingButterflyBullishPatternExtended 
								OR DevelopingButterflyBearishPatternExtended 
								,"\nClosing Price: "+WriteVal(LastValue(C),1.2)+"\nTarget Price:"
					+"\n1-    "+WriteVal(DevelopingButterflyTargetPrice3,1.2 )  + " ("
					+WriteVal(DevelopingButterflyTargetPricePct3,1.2) +"%%) "
					+WriteIf(LastValue(C) < DevelopingButterflyTargetPrice3 AND DevelopingButterflyBearishPatternExtended ,
							 " Price Excceded Target", "")
					+WriteIf(LastValue(C) > DevelopingButterflyTargetPrice3 AND DevelopingButterflyBullishPatternExtended ,
							 " Price Excceded Target", "")
					+"\n2-    "+WriteVal(DevelopingButterflyTargetPrice4,1.2)  + " ( "
					+WriteVal(DevelopingButterflyTargetPricePct4,1.2) +"%%) "
					+WriteIf(LastValue(C) < DevelopingButterflyTargetPrice4 AND DevelopingButterflyBearishPatternExtended ,
							 " Price Excceded Target", "")
					+WriteIf(LastValue(C) > DevelopingButterflyTargetPrice4 AND DevelopingButterflyBullishPatternExtended ,
							 " Price Excceded Target", "")
					+"\n3-    "+WriteVal(DevelopingButterflyTargetPrice5,1.2 ) + " ( "
					+WriteVal(DevelopingButterflyTargetPricePct5,1.2) +"%%) "
					+WriteIf(LastValue(C) < DevelopingButterflyTargetPrice5 AND DevelopingButterflyBearishPatternExtended ,
							 " Price Excceded Target", "")
					+WriteIf(LastValue(C) > DevelopingButterflyTargetPrice5 AND DevelopingButterflyBullishPatternExtended ,
							 " Price Excceded Target", ""),""));
/*-------------------------------------------*/


	if (ShowSuppRes1 ==0 )
	{	Plot (LineArray(x0_4th + plus , y0_4th , BarCount , y0_4th ),"SuppResist",Color1 ,Linestyle1 + styleNoTitle); 
		Plot (LineArray(x0_2nd + plus , y0_2nd , BarCount , y0_2nd ),"SuppResist",Color1 ,Linestyle1 + styleNoTitle); 
		Plot (LineArray(x0_4th        , y0_4th , x1_3rd   , y1_3rd,1 ),"XB",ColorXB , styleDashed + styleNoTitle); 
		PlotText("SR:: "+WriteVal(y0_2nd,1.2),TargetPosition , y0_2nd, colorViolet );
		PlotText("SR:: "+WriteVal(y0_4th ,1.2),TargetPosition , y0_4th , colorViolet );
	}

	if(y1_1st > y1_3rd AND y1_2nd < y1_1st OR y1_1st < y1_3rd AND y1_2nd > y1_1st OR ShowSuppRes1 ==1)
		Plot (LineArray(x0_2nd + plus  , y1_3rd , x1_1st+ plus , y1_1st ),"BD",ColorBD, styleDashed + styleNoTitle); 

	if(y1_1st < y1_3rd AND y1_2nd > y1_1st OR y1_1st > y1_3rd AND y1_2nd < y1_1st OR ShowSuppRes2 ==1)
		Plot (LineArray(x0_3rd , y0_3rd , x1_2nd , y1_2nd ),"AC",ColorAC , styleDashed + styleNoTitle); 

	if(y1_1st <= y1_3rd AND y1_5th <= y1_3rd AND y1_1st < y1_2nd  OR y1_1st >= y1_3rd AND y1_5th >= y1_3rd AND y1_1st > y1_2nd )
	{	Plot (LineArray(x0_4th , y0_4th , x1_1st , y1_1st ),"XD",ColorXB , styleDashed +styleNoTitle); 
		if(ShowLabels ==0  )
		PlotText(WriteIf(ad_of_xa<0, WriteVal(-ad_of_xa*100,1.2),WriteVal(ad_of_xa*100,1.2) ),XXDtextPosition , YXDtextPosition , colorViolet );
	}

	if (ShowSuppRes2 ==0 )
	{	Plot (LineArray(x0_3rd + plus , y0_3rd , BarCount , y0_3rd ),"SuppResist",Color1 ,Linestyle1 + styleNoTitle); 
		Plot (LineArray(x0_1st + plus , y0_1st , BarCount , y0_1st ),"SuppResist",Color1 ,Linestyle1 + styleNoTitle); 
		Plot (LineArray(x0_3rd , y0_3rd , x1_2nd , y1_2nd,1 ),"AC",ColorAC , styleDashed + styleNoTitle); 
		PlotText("SR:: "+WriteVal(y0_1st ,1.2),TargetPosition , y0_1st , colorViolet );
		PlotText("SR:: "+WriteVal(y0_3rd ,1.2),TargetPosition , y0_3rd , colorViolet );
	}
	if (ShowAnalysisOnMainScreen  ==0 )
	{		if(DevelopingButterflyBullishPattern)
			{	GfxSetTextColor(colorRed); 
				GfxTextOut("Developing Butterfly Bullish (Sell)", 300 , 15); 
			}
			if(DevelopingButterflyBearishPattern )
			{	GfxSetTextColor(colorGreen); 
				GfxTextOut("Developing Butterfly Bearish (Buy)", 300 , 15); 
			}
			if(DevelopingButterflyBullishPatternExtended)
			{	GfxSetTextColor(colorGreen); 
				GfxTextOut("Developing Butterfly Bullish Extended (Buy)", 300 , 15); 
			}
			if(DevelopingButterflyBearishPatternExtended )
			{	GfxSetTextColor(colorRed); 
				GfxTextOut("Developing Butterfly Bearish Extended (Sell)", 300 , 15); 
			}
			if(DevelopingButterflyBullishPattern OR DevelopingButterflyBearishPattern )
				PlotText("T1: "+WriteVal(DevelopingButterflyTargetPrice1,1.2),TargetPosition , DevelopingButterflyTargetPrice1, colorViolet );
			if(DevelopingButterflyBullishPattern OR DevelopingButterflyBearishPattern )
				PlotText("T2: "+WriteVal(DevelopingButterflyTargetPrice2,1.2),TargetPosition , DevelopingButterflyTargetPrice2, colorViolet );
			if(DevelopingButterflyBullishPatternExtended OR DevelopingButterflyBearishPatternExtended )
			{	PlotText("T1: "+WriteVal(DevelopingButterflyTargetPrice3,1.2),TargetPosition , DevelopingButterflyTargetPrice3, colorViolet );
				PlotText("T2: "+WriteVal(DevelopingButterflyTargetPrice4,1.2),TargetPosition , DevelopingButterflyTargetPrice4, colorViolet );
				PlotText("T3: "+WriteVal(DevelopingButterflyTargetPrice5,1.2),TargetPosition , DevelopingButterflyTargetPrice5, colorViolet );
			}

	}
/*-----------------------------------------------------------------------------------------------------*/
			printf(WriteIf(DevelopingCrabBullishPattern ,Separator +"\nDeveloping Crab Bullish (Sell)","" ));
			printf(WriteIf(DevelopingCrabBearishPattern ,Separator +"\nDeveloping Crab Bearish (Buy)","" ));
			printf(WriteIf(DevelopingCrabBullishPatternExtended ,Separator +"\nDeveloping Crab Bullish(Extended) (Buy)","" ));
			printf(WriteIf(DevelopingCrabBearishPatternExtended ,Separator +"\nDeveloping Crab Bearish(Extended) (Sell)","" ));
			printf(WriteIf(DevelopingCrabBullishPattern 
						  OR DevelopingCrabBearishPattern 
								,"\nClosing Price: "+WriteVal(LastValue(C),1.2)+"\nTarget Price:"
					+"\n1-    "+WriteVal(DevelopingCrabTargetPrice1,1.2 )  + " ("
					+WriteVal(DevelopingCrabTargetPricePct1,1.2) +"%%) ",""));
					printf(WriteIf(LastValue(C) < DevelopingCrabTargetPrice1 AND DevelopingCrabBullishPattern ,
							 " Price Excceded Target", ""));					
					printf(WriteIf(LastValue(C) > DevelopingCrabTargetPrice1 AND DevelopingCrabBearishPattern ,
							 " Price Excceded Target", ""));
			printf(WriteIf(DevelopingCrabBullishPattern 
						  OR DevelopingCrabBearishPattern 
					,"\n2-    "+WriteVal(DevelopingCrabTargetPrice2,1.2 )  + " ("
					+WriteVal(DevelopingCrabTargetPricePct2,1.2) +"%%) ",""));
					printf(WriteIf(LastValue(C) < DevelopingCrabTargetPrice2 AND DevelopingCrabBullishPattern ,
							 " Price Excceded Target", ""));					
					printf(WriteIf(LastValue(C) > DevelopingCrabTargetPrice2 AND DevelopingCrabBearishPattern ,
							 " Price Excceded Target", ""));
			printf(WriteIf(DevelopingCrabBullishPatternExtended 
								OR DevelopingCrabBearishPatternExtended 
								,"\nClosing Price: "+WriteVal(LastValue(C),1.2)+"\nTarget Price:"
					+"\n1-    "+WriteVal(DevelopingCrabTargetPrice3,1.2 )  + " ("
					+WriteVal(DevelopingCrabTargetPricePct3,1.2) +"%%) "
					+WriteIf(LastValue(C) < DevelopingCrabTargetPrice3 AND DevelopingCrabBearishPatternExtended ,
							 " Price Excceded Target", "")
					+WriteIf(LastValue(C) > DevelopingCrabTargetPrice3 AND DevelopingCrabBullishPatternExtended ,
							 " Price Excceded Target", "")
					+"\n2-    "+WriteVal(DevelopingCrabTargetPrice4,1.2)  + " ( "
					+WriteVal(DevelopingCrabTargetPricePct4,1.2) +"%%) "
					+WriteIf(LastValue(C) < DevelopingCrabTargetPrice4 AND DevelopingCrabBearishPatternExtended ,
							 " Price Excceded Target", "")
					+WriteIf(LastValue(C) > DevelopingCrabTargetPrice4 AND DevelopingCrabBullishPatternExtended ,
							 " Price Excceded Target", "")
					+"\n3-    "+WriteVal(DevelopingCrabTargetPrice5,1.2 ) + " ( "
					+WriteVal(DevelopingCrabTargetPricePct5,1.2) +"%%) "
					+WriteIf(LastValue(C) < DevelopingCrabTargetPrice5 AND DevelopingCrabBearishPatternExtended ,
							 " Price Excceded Target", "")
					+WriteIf(LastValue(C) > DevelopingCrabTargetPrice5 AND DevelopingCrabBullishPatternExtended ,
							 " Price Excceded Target", ""),""));
/*-------------------------------------------*/
	if (ShowAnalysisOnMainScreen  ==0 )
	{	if(DevelopingCrabBullishPattern)
			{	GfxSetTextColor(colorRed); 
				GfxTextOut("Developing Crab Bullish (Sell)", 300 , 15); 
				HeaderTextPosition = 30;
			}
			if(DevelopingCrabBearishPattern )
			{	GfxSetTextColor(colorGreen); 
				GfxTextOut("Developing Crab Bearish (Buy)", 300 , 15); 
				HeaderTextPosition = 30;
			}
			if(DevelopingCrabBullishPatternExtended)
			{	GfxSetTextColor(colorGreen); 
				GfxTextOut("Developing Crab Bullish Extended (Buy)", 300 , 15); 
			}
			if(DevelopingCrabBearishPatternExtended )
			{	GfxSetTextColor(colorRed); 
				GfxTextOut("Developing Crab Bearish Extended (Sell)", 300 , 15); 
			}
			if(DevelopingCrabBullishPattern OR DevelopingCrabBearishPattern )
				PlotText("T1: "+WriteVal(DevelopingCrabTargetPrice1,1.2),TargetPosition , DevelopingCrabTargetPrice1, colorViolet );
			if(DevelopingCrabBullishPattern OR DevelopingCrabBearishPattern )
				PlotText("T2: "+WriteVal(DevelopingCrabTargetPrice2,1.2),TargetPosition , DevelopingCrabTargetPrice2, colorViolet );
			if(DevelopingCrabBullishPatternExtended OR DevelopingCrabBearishPatternExtended )
			{	PlotText("T1: "+WriteVal(DevelopingCrabTargetPrice3,1.2),TargetPosition , DevelopingCrabTargetPrice3, colorViolet );
				PlotText("T2: "+WriteVal(DevelopingCrabTargetPrice4,1.2),TargetPosition , DevelopingCrabTargetPrice4, colorViolet );
				PlotText("T3: "+WriteVal(DevelopingCrabTargetPrice5,1.2),TargetPosition , DevelopingCrabTargetPrice5, colorViolet );
			}

	}
/*-----------------------------------------------------------------------------------------------------*/
			printf(WriteIf(DevelopingGartleyBullishPattern ,Separator +"\nDeveloping Gartley Bullish (Sell)","" ));
			printf(WriteIf(DevelopingGartleyBearishPattern ,Separator +"\nDeveloping Gartley Bearish (Buy)","" ));
			printf(WriteIf(DevelopingGartleyBullishPatternExtended ,Separator +"\nDeveloping Gartley Bullish(Extended) (Buy)","" ));
			printf(WriteIf(DevelopingGartleyBearishPatternExtended ,Separator +"\nDeveloping Gartley Bearish(Extended) (Sell)","" ));
			printf(WriteIf(DevelopingGartleyBullishPattern 
						  OR DevelopingGartleyBearishPattern 
								,"\nClosing Price: "+WriteVal(LastValue(C),1.2)+"\nTarget Price:"
					+"   "+WriteVal(DevelopingGartleyTargetPrice1,1.2 )  + " ("
					+WriteVal(DevelopingGartleyTargetPricePct1,1.2) +"%%) ",""));
					printf(WriteIf(LastValue(C) < DevelopingGartleyTargetPrice1 AND DevelopingGartleyBullishPattern ,
							 " Price Excceded Target", ""));					
					printf(WriteIf(LastValue(C) > DevelopingGartleyTargetPrice1 AND DevelopingGartleyBearishPattern ,
							 " Price Excceded Target", ""));
/*-------------------------------------------*/
	if (ShowAnalysisOnMainScreen  ==0 )
	{	if(DevelopingGartleyBullishPattern)
			{	GfxSetTextColor(colorRed); 
				GfxTextOut("Developing Gartley Bullish (Sell)", 300 , HeaderTextPosition ); 
			}
			if(DevelopingGartleyBearishPattern )
			{	GfxSetTextColor(colorGreen); 
				GfxTextOut("Developing Gartley Bearish (Buy)", 300 , HeaderTextPosition ); 
			}
			if(DevelopingGartleyBullishPattern OR DevelopingGartleyBearishPattern )
				PlotText("T: "+WriteVal(DevelopingGartleyTargetPrice1,1.2),TargetPosition , DevelopingGartleyTargetPrice1, colorViolet );
	}
/*-----------------------------------------------------------------------------------------------------*/
			printf(WriteIf(DevelopingBatBullishPattern ,Separator +"\nDeveloping Bat Bullish (Sell)","" ));
			printf(WriteIf(DevelopingBatBearishPattern ,Separator +"\nDeveloping Bat Bearish (Buy)","" ));
			printf(WriteIf(DevelopingBatBullishPatternExtended ,Separator +"\nDeveloping Bat Bullish(Extended) (Buy)","" ));
			printf(WriteIf(DevelopingBatBearishPatternExtended ,Separator +"\nDeveloping Bat Bearish(Extended) (Sell)","" ));
			printf(WriteIf(DevelopingBatBullishPattern 
						  OR DevelopingBatBearishPattern 
								,"\nClosing Price: "+WriteVal(LastValue(C),1.2)+"\nTarget Price:"
					+"   "+WriteVal(DevelopingBatTargetPrice1,1.2 )  + " ("
					+WriteVal(DevelopingBatTargetPricePct1,1.2) +"%%) ",""));
					printf(WriteIf(LastValue(C) < DevelopingBatTargetPrice1 AND DevelopingBatBullishPattern ,
							 " Price Excceded Target", ""));					
					printf(WriteIf(LastValue(C) > DevelopingBatTargetPrice1 AND DevelopingBatBearishPattern ,
							 " Price Excceded Target", ""));
				
	}
/*-------------------------------------------*/
	if (ShowAnalysisOnMainScreen  ==0 )
	{	if(DevelopingBatBullishPattern)
			{	GfxSetTextColor(colorRed); 
				GfxTextOut("Developing Bat Bullish (Sell)", 300 , HeaderTextPosition ); 
			}
			if(DevelopingBatBearishPattern )
			{	GfxSetTextColor(colorGreen); 
				GfxTextOut("Developing Bat Bearish (Buy)", 300 , HeaderTextPosition ); 
			}
			if(DevelopingBatBullishPattern OR DevelopingBatBearishPattern )
				PlotText("T: "+WriteVal(DevelopingBatTargetPrice1,1.2),TargetPosition , DevelopingBatTargetPrice1, colorViolet );
	}
/*-----------------------------------------------------------------------------------------------------*/

	dispFiboSwing=0;
	if(dispFiboSwing==1)	
	{	printf("\n\nLast Swing analysis: ");
		printf("\nLength (Bars) = "+LastSwingDays );
		printf("\nFiboValue  = "+WriteVal(FiboValue,1.2)  );
		printf("\nPct  = "+ WriteVal(LastSwingPct,1.2)+"%%");
	}
/*-----------------------------------------------------------------------------------------------------*/

plotFractals = ParamToggle("Plot Fractals","Off|On",1);
if(PlotFractals)
{
	PlotShapes(shapeSmallCircle*P1,colorRed,0,H,10);
	PlotShapes(shapeSmallCircle*V1,colorBlue,O,L,-10);
}

_SECTION_END(); //Eof Developing Harmonic Trader
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	Filter = 1 ;//BuyBBand  OR sellBBand ;

	P  =  ((H + L + C) / 3);
	R1  =  ((2 * P) - L);
	S1  =  ((2 * P)  - H);
	R2  =  ((P - S1) + R1);
	S2  =  (P - (R1 - S1));
	AddTextColumn( FullName(), "Name");
	AddColumn( Close, "Close" );
	AddTextColumn(WriteVal(ZigzagChange,1.0)+WriteIf(FindLastTrueHiLow,"N","Y")+WriteIf(ReReadPattern ,"N","Y") , "Zig" );
//	AddColumn( Date() , "date" );
//FindLastTrueHiLow = ParamToggle("Find Last True Hi Low ", "Yes|No" );
//ReReadPattern = ParamToggle("Re-Read Pattern ", "Yes|No" );

AddTextColumn(
					WriteIf(DevelopingButterflyBullishPattern ,"S Butter Fly Bull", 
					WriteIf(DevelopingButterflyBearishPattern ,"B Butter Fly Bear",
					WriteIf(DevelopingButterflyBullishPatternExtended ,"B Butter Fly Bull Extended",
					WriteIf(DevelopingButterflyBearishPatternExtended  ,"S Butter Fly Bear Extended",

					WriteIf(DevelopingGartleyBullishPattern ,"S Gartley Bull", 
					WriteIf(DevelopingGartleyBearishPattern ,"B Gartley Bear",
					WriteIf(DevelopingBatBullishPattern ,"S Bat Bull", 
					WriteIf(DevelopingBatBearishPattern ,"B Bat Bear",
					WriteIf(DevelopingCrabBullishPattern ,"S Crab Bull", 
					WriteIf(DevelopingCrabBearishPattern ,"B Crab Bear",
					WriteIf(DevelopingCrabBullishPatternExtended ,"B Crab Bull Extended",
					WriteIf(DevelopingCrabBearishPatternExtended ,"S Crab Bear Extended",
					"")))))))))))),"Developing Gartley",1.2,
					IIf(
					DevelopingButterflyBullishPattern OR DevelopingButterflyBearishPatternExtended  OR
					DevelopingCrabBearishPatternExtended OR DevelopingCrabBullishPattern OR 
					DevelopingGartleyBullishPattern OR DevelopingGartleyBearishPatternExtended OR
					DevelopingBatBullishPattern OR DevelopingBatBearishPatternExtended ,colorRed,colorGreen));

	AddTextColumn(
					WriteIf(CompletedButterflyBullishPattern ,"B Butter Fly Bull", 
					WriteIf(CompletedButterflyBearishPattern ,"S Butter Fly Bear",
					WriteIf(CompletedButterflyBullishPatternExtended ,"B Butter Fly Bull Extended",
					WriteIf(CompletedButterflyBearishPatternExtended  ,"S Butter Fly Bear Extended",

					WriteIf(CompletedCrabBullishPattern ,"B Crab Bull", 
					WriteIf(CompletedCrabBearishPattern ,"S Crab Bear",
					WriteIf(CompletedCrabBullishPatternExtended ,"B Crab Bull Extended",
					WriteIf(CompletedCrabBearishPatternExtended ,"S Crab Bear Extended",

					WriteIf(CompletedGartleyBullishPattern ,"B Gartley Bull", 
					WriteIf(CompletedGartleyBearishPattern ,"S Gartley Bear",
					WriteIf(CompletedGartleyBullishPatternExtended ,"B Gartley Bull Extended",
					WriteIf(CompletedGartleyBearishPatternExtended ,"S Gartley Bear Extended",

					WriteIf(CompletedBatBullishPattern ,"B Bat Bull", 
					WriteIf(CompletedBatBearishPattern ,"S Bat Bear",
					WriteIf(CompletedBatBullishPatternExtended ,"B Bat Bull Extended",
					WriteIf(CompletedBatBearishPatternExtended ,"S Bat Bear Extended",
					"")))))))))))))))),"Completed Gartley",1.2,
					IIf(
					CompletedButterflyBullishPattern OR CompletedButterflyBearishPatternExtended  OR
					CompletedCrabBullishPattern OR CompletedCrabBearishPatternExtended OR
					CompletedGartleyBullishPattern OR CompletedGartleyBearishPatternExtended OR
					CompletedBatBullishPattern OR CompletedBatBearishPatternExtended ,colorRed,colorGreen));

_SECTION_BEGIN("Basic Chart");
if(BringPatternToFront ==0)
{
Plot( C, "Close", ParamColor("Color", colorBlack ),ParamStyle("Style") | GetPriceStyle() ); 
}
_SECTION_END(); //Eof Basic Chart

_SECTION_BEGIN("Volume");
PlotVol = ParamToggle("Plot Volume ", "Yes|No" );
VolumeHeight = 7 - Param("Volume Height", 4, 0, 6, 0.1);
if(PlotVol ==0)
Plot( Volume, _DEFAULT_NAME(), ParamColor("Color", colorLightGrey ), styleNoTitle | ParamStyle( "Style", styleHistogram | styleOwnScale | styleThick | styleNoLabel, maskHistogram  ), VolumeHeight );
_SECTION_END();
Kind regards
Derek
 

Similar threads