Ah vedi ....anche a me è venuta la stessa idea (il codice che ho postato nella prima parte in pratica ricrea uno zig-zag basato sui minimi e i massimi) solo che questo approccio presenta un limite che sta proprio nel capire quale deve essere la distanza minima (in percentuale nel mio caso) tra i punti del wolfe....
Angio, se ti ricordi, quale fu il problema maggiore che aveva riscontrato Zweifel e che lo ha fatto desistere???
Perchè è più semplice cercarli a "occhio" almeno con Amibroker
------------------------------------------------------------------
Title="ZWolfe Bearish Wolfe Pattern";
//* Detecting double tops AND bottoms*/
percdiff = Param("percentuale",500,1,1000,1);; /* peak detection threshold */
fwdcheck = 3; /* forward validity check */
mindistance = 4;
Plot(C,"close",16,64);
startpoint = BarCount-Param( "Startpoint", 350, 1, 1000, 1 );
// Patterns
COLOR=1;
function FillLine( startbar, startval, endbar, endval )
{
global ZigArray;
for( j = startbar; j <= endbar; j++ )
{
ZigArray[ j ] = startval + ( j - startbar) * (endval-
startval)/( endbar -startbar );
}
return;
}
WavePcnt = Optimize("Percent",0.001,1.0,100,0.1);
RP = ( High[0] + Low[0] )/2.0;
RPPoint = 0;
RP0 = RPPoint;
RP1 = RP;
RPPoint1 = RPPoint;
fires = 0;
for(i=0; i<BarCount; i++)
{
ZigArray
= -1.0E10;
// Swing High
if( i>0 AND i<BarCount-2 AND H>=H[i-1] AND H>=H[i+1] )
SH = H;
else
SH = -1;
// Swing Low
if( i>0 AND i<BarCount-2 AND L<=L[i-1] AND L<=L
[i+1] )
SL = L;
else
SL = -1;
// ZigZag
if( SH != 0 )
{
if(fires != 1 AND SH >= RP*(1+0.001*WavePcnt) )
{
RPPoint1 = RPPoint;
RP1 = RP;
RPPoint = i;
RP = SH;
FillLine( RPPoint1, RP1, RPPoint, RP );
fires = 1;
}
else
if(fires == 1 AND SH >= RP)
{
RPPoint = i;
RP = SH;
FillLine( RPPoint1, RP1, RPPoint,
RP );
}
}
if( SL != -1 )
{
if(fires != -1 AND SL <= RP*(1-0.001*WavePcnt) )
{
RPPoint1 = RPPoint;
RP1 = RP;
RPPoint = i;
RP = SL;
FillLine( RPPoint1, RP1, RPPoint, RP );
fires = -1;
}
else
if(fires == -1 AND SL <= RP )
{
RPPoint = i;
RP = SL;
FillLine( RPPoint1, RP1, RPPoint,
RP );
}
}
}
// Last line segment
RPPoint1 = RPPoint;
RP1 = RP;
RPPoint = BarCount - 1;
if(fires == -1) RP = LastValue(High);
if(fires == 1) RP = LastValue(Low);
FillLine( RPPoint1, RP1, RPPoint, RP );
H=L=Hilo=ZigArray ;
//Plot(Hilo,"",11,1);
perc=1;
do
{
validdiff = perc/100/400;
PK= Peak( H, perc/100, 1 ) == High;
TR= Trough( L, perc/100, 1 ) == Low;
x = Cum( 1 );
XPK1 = ValueWhen( PK, x, 1 );
XPK2 = ValueWhen( PK, x, 2 );
XPK3 = ValueWhen( PK, x, 3 );
yPK1 = ValueWhen( PK, H, 1 );
yPK2 = ValueWhen( PK, H, 2 );
yPK3 = ValueWhen( PK, H, 3 );
xTR1 = ValueWhen( Tr, x, 1 ) ;
xTr2 = ValueWhen( Tr, x, 2 );
xTr3 = ValueWhen( Tr, x, 3 );
xTr4 = ValueWhen( Tr, x, 4 );
yTR1 = ValueWhen( Tr, L, 1 );
yTr2 = ValueWhen( Tr, L, 2 );
yTr3 = ValueWhen( Tr, L, 3 );
yTr4 = ValueWhen( Tr, L, 4 );
Cond1= ypk3<ypk2 AND ypk1<ypk2 AND ytr1<ytr2 AND ytr2<ytr3 AND ypk1>ytr3 ;
Cond1= ytr3>ytr2 AND ytr1>ytr2 AND ypk1>ypk2 AND ypk2>ypk3 AND ytr1<ypk3 ;
Cond12= ytr4<ytr3;
Cond12= 1;
pendPK21=(ypk1-ypk2 )/(xpk1-xpk2);
pendtr23=(ytr2-ytr3 )/(xtr2-xtr3 );
pendtr12=(ytr1-ytr2 )/(xtr1-xtr2 );
pendtr21=(ytr1-ytr2 )/(xtr1-xtr2);
pendpk23=(ypk2-ytr3 )/(xpk2-xpk3 );
pendpk12=(ypk1-ypk2 )/(xpk1-xpk2 );
Cond2= pendtr21>pendpk23 AND pendpk12 >pendpk23 ;
Cond3=(Xpk1 -Xpk2)>mindistance AND (Xpk2 -Xpk3)>mindistance AND (Xtr1 -Xtr2)>mindistance;
Cond=Cond1 +Cond2 +Cond12;
Color++;
per=percdiff ;
Plot(Zig(Hilo,per),"zig",16,4);
Plot(IIf(Cond>2, C,Null),"cond",colorLavender,styleArea);
PlotShapes( IIf(cond>2 AND x==xpk1, shapeDigit5, Null), Color, layer = 0, yposition = L ,offset = -3);
PlotShapes( IIf(ValueWhen( pk, cond , -1 )>2 AND ValueWhen( pk, H, 1 )==H, shapeDigit1, Null), Color, layer = 0, yposition = H ,offset = -3);
PlotShapes( IIf(ValueWhen( pk, cond , 0)>2 AND ValueWhen( pk, H, 1 )==H, shapeDigit3, Null), Color, layer = 0, yposition = H ,offset = -3);
PlotShapes( IIf(ValueWhen( pk, cond , -1 )>2 AND ValueWhen( tr, L, 1 )==L, shapeDigit2, Null), Color, layer = 0, yposition = L ,offset = 3);
PlotShapes( IIf(ValueWhen( pk, cond , 0)>2 AND ValueWhen( tr, L, 1 )==L, shapeDigit4, Null), Color, layer = 0, yposition = L,offset = 3);
s1=L;
s11=H;
if( Cond=3)
{
pS = TroughBars( s1, perc/100, 1 ) == 0;
endt= (ValueWhen( pS, x, 2 ));
startt=(ValueWhen( pS, x, 3 ));
endS = (ValueWhen( pS, s1, 2 ) );
startS = ( ValueWhen( pS, s1, 3 ));
dtS =endt-startt;
aS = (endS-startS)/dtS;
bS = endS;
trendlineS = aS * ( x -endt ) + bS;
pR = PeakBars( s11, perc/100, 1 ) == 0;
endt1= (ValueWhen( pR, x, 1 ));
startt1=(ValueWhen( ps, x, 3 ));
endR = (ValueWhen( pR, s11, 1 ) );
startR = ( ValueWhen( ps, s1, 3 ));
DTR=ENDT1-STARTT1;
aR = (endR-startR)/dtR;
bR = endR;
trendlineR = aR * ( x -endt1 ) + bR;
BEGIN=STARTT; finish= Max(endt,endt1);
TRS = IIf(x>BEGIN-0 AND x<finish+20,trendlineS,-1e10);
TRR = IIf(x>BEGIN AND x<finish+20,trendlineR,-1e10);
}
perc++;perc++;perc++;perc++;perc++;perc++;perc++;perc++;perc++;perc++;
} while ( perc < percdiff );