Hi everyone!

I was wondering if you guys have tried to code an Harmonic Pattern indicator in Zorro. I guess the easiest way would be to use the zigzag indicator, however, it would be necessary to include multiple zigzags to capture big and small swings. So far, I have coded this, but it's not working as I thought, do you have any suggestions on how to code it?


static int D=0,C=0,B=0,A=0,X=0;
static var XA,AB,BC,CD,AD,pAB,pBC,pCD,pAD,pXA;

function run()
{
set(PLOTNOW);
StartDate = 2010;
//EndDate = 20140101;
LookBack = 0;

vars Price = series(priceClose());
ZigZag(Price,20*PIP,5,RED+TRANSP);

X = A;
A = B;
B = C;
C = D;
D = rPeak;

XA = abs(priceClose(X) - priceClose(A));
AB = abs(priceClose(A) - priceClose(B));
BC = abs(priceClose(B) - priceClose(C));
CD = abs(priceClose(C) - priceClose(D));
AD = abs(priceClose(A) - priceClose(D));

pAB = abs(AB / XA) * 100;
pBC = abs(BC / AB) * 100;
pCD = abs(CD / BC) * 100;
pAD = abs(AD / AB) * 100;
pXA = abs(AD / XA) * 100;

var gartley = pAB >= 61.8 and pAB <= 78.6 and pBC >= 38.2 and pBC <= 88.6 and pAD >= 127.2 and pAD <= 161.8 and pXA >= 78.6 and pXA < 100;
var Bull_gartley = rSign == 1 and gartley == true;
var Bear_gartley = rSign == -1 and gartley == true;

var bat = pAB >= 50 and pAB <= 61.8 and pBC >= 38.2 and pBC <= 88.6 and pAD >= 161.8 and pAD <= 261.8 and pXA >= 88.6 and pXA < 100;
var Bull_bat = rSign == 1 and bat == true;
var Bear_bat = rSign == -1 and bat == true;

var butterfly = pAB >= 78.6 and pAB <= 88.6 and pBC >= 38.2 and pBC <= 88.6 and pAD >= 161.8 and pAD <= 261.8 and pXA >= 127.2 and pXA < 161.8;
var Bull_butterfly = rSign == 1 and butterfly == true;
var Bear_butterfly = rSign == -1 and butterfly == true;

var crab = pAB >= 38.2 and pAB <= 78.6 and pBC >= 38.2 and pBC <= 88.6 and pAD >= 224 and pAD <= 361.8 and pXA >= 161.8 and pXA < 178.6;
var Bull_crab = rSign == 1 and crab == true;
var Bear_crab = rSign == -1 and crab == true;

if(Bull_crab == true or Bull_butterfly == true or Bull_bat == true or Bull_gartley == true){
Stop = 2*ATR(100);
TakeProfit = Stop;
enterLong();
}

if(Bear_crab == true or Bear_butterfly == true or Bear_bat == true or Bear_gartley == true){
Stop = 2*ATR(100);
TakeProfit = Stop;
enterShort();
}

plot("rSign",rSign,NEW+BARS+LBL2,BLACK);
/* plot("Gartley",gartley,NEW+BARS+LBL2,BLACK);
plot("Bat",bat,NEW+BARS+LBL2,RED);
plot("Butterfly",bat,NEW+BARS+LBL2,GREEN);
plot("Crab",bat,NEW+BARS+LBL2,ORANGE); */
}