PPZ calculation - help to refine - page 2

 
It's a bit heavy for an EA, but it's a good idea. Maybe we can make it lighter, but I doubt it will do much for visual trading as additional analysis.
 
As for optimization. In my opinion, you should sort the resulting array Fr0[j] and then dance on it, the result will be only one pass.
 

This code does not account for bars with two fractals at the same time:


j=0;
for(i = loopbegin; i > Nfirst; i--) {
f0 = -1.0;
f0 = iFractals(NULL,0,MODE_UPPER,i);
if (f0<=0.0 ) f0 = iFractals(NULL,0,MODE_LOWER,i);
if (f0>0.0) {
Fr0[j]=f0;
Ind0[j]=i;
j++;
}
}
Nmax = j;


And here you don't need to go through all fractals, you don't care if you compare fractal #1 with #2 or #2 with #1.
The way to fix it is this:


for(i = 0; i < Nmax; i++) {
f0 = Fr0[i];
for(j = i+1; j < Nmax; j++) {
f1=Fr0[j];
if(MathAbs(Ind0[i]-Ind0[j])>minBars) {
for(k = j+1; k < Nmax; k++) {
f2 = Fr0[k];
if(MathAbs(Ind0[i]-Ind0[k])>minBars && MathAbs(Ind0[k]-Ind0[j])>minBars) {
for(l = k+1; l < Nmax; l++) {
f3 = Fr0[l];
if (MathAbs(Ind0[i]-Ind0[l])>minBars && MathAbs(Ind0[j]-Ind0[l])>minBars && MathAbs(Ind0[k]-Ind0[l])>minBars) {
p0 = (f0+f1+f2+f3)/4.0;
s0 = (f0-p0)*(f0-p0)+(f1-p0)*(f1-p0)+(f2-p0)*(f2-p0)+(f2-p0)*(f2-p0);
if (s0<smin) {
smin=s0;
pmin=p0;
imin=i;
jmin=j;
kmin=k;
lmin=l;
}
}
}
}
}
}
}
}

And this code should be put into the function and used 4 times instead of copying the code. The fractals in Fr0 should be zeroed, so that they don't take part in the next pass.



 

Why go through fractals at every iteration? Isn't it easier to do it once and then analyse it later? Besides, the comparison should converge to a triangle, not to a square (there is no sense in comparing fractal 1 and 2 twice, and then 2 and 1). I did it a little differently - the indicator is sequentially looking for divergence from 0 pips and above until it finds four levels. I did not limit the distance between the levels:


Files:
 
Scriptong писал(а) >>

Why go through fractals at every iteration? Isn't it easier to do it once and then analyse it later? Besides, the comparison should converge to a triangle, not to a square (there is no sense in comparing fractal 1 and 2 twice, and then 2 and 1). I did it a little differently - the indicator is sequentially looking for divergence from 0 pips and above until it finds four levels. I did not limit the distance between the levels:

Great! The speed is totally different... :)

May I also save the values of received levels in the buffers of the indicator? In order to process them later from Expert Advisor.

 

I am going to make an expert myself. I have some ideas. But maybe someone has more interesting ideas? I'll make one and post it in Code Base.

 
Scriptong писал(а) >>

I am going to make an expert myself. I have some ideas. But maybe someone has more interesting ideas? I will make and post them in Code Base.

You may try to add it in this way:

if (period == 0) {period = WindowBarsPerChart();}
And display somewhere on the screen the number of bars to calculate...

 
mikola2 >>:

if (period == 0) {period = WindowBarsPerChart();}
И выводить где-нибудь на экране количество баров для расчета...

That's not what I meant :)

Ideas about the Expert Advisor. It is clear that there is a lot more to add to the indicator itself

 
Any ideas, make it into a function, I mean the logic of the turkey, can you do it?
 
qwerewq >>:
Идеи есть, сделайте его в виде функции, логику индюка имею в виду, сможете?


it's already in the form of functions...