Newbie coder question: Fractal EA Scalper trading logic. A little help please...

 

Hello,

I am a beginner MT4 coder who needs some help. Luckily, it is not going to take too long to explain my problem.
I am trying to create a Fractal EA Scalper that takes 5 pips from every fractal that displays itself on the screen. But I cannot get the trading logic to work as I would like.

Here it is for a SELL trade:
if (iCustom(NULL, NULL, "Fractals[1]",0,0) > Ask)

And here it is for a BUY trade:
if (iCustom(NULL, NULL, "Fractals[1]",1,0) < Ask)

Because the "Fractal[1]" indicator is imported into the EA, I thought all I had to do was add the trading logic. I have tried many permeations using Close[0] instead of Ask. But to no avail.

Can someone tell me where I am going wrong?
Thank you in advance.
davefx

 
What timeframe is NULL ?
 
RaptorUK:
What timeframe is NULL ?


Hi,

NULL means the EA will operate on any TF. and any FX pair.

Thanks.

davefx

 
I don't think a fractal will ever appear on bar 0 or bar 1. It takes 3 to fractal...
 
serpentsnoir:
I don't think a fractal will ever appear on bar 0 or bar 1. It takes 3 to fractal...


Hi,

if (iCustom(NULL, NULL, "Fractals[1]",0*,0**) > Ask)

* This is the buffer index.

** This is the "shift".

Thanks.

davefx

 

that is correct. and you have hard-coded 0 for the shift. you don't get a fractal appearing before bar 2 because the first fractal to appear can only show after the hi/lo of the two bars before and two bars after are known.

I also think the NULL is not a valid time frame, 0 is tho.

 
serpentsnoir:

that is correct. and you have hard-coded 0 for the shift. you don't get a fractal appearing before bar 2 because the first fractal to appear can only show after the hi/lo of the two bars before and two bars after are known.

I also think the NULL is not a valid time frame, 0 is tho.


Hi,

So is it the "shift" that I need to change?

Thanks.

davefx

 

basically, with a fractal, you don't know where the last one is... you have to loop backward one bar (shift) at a time until you find it (it will be not NULL). you have to do this for each buffer (zero and one). Also, even if you find one on bar 2, later it might not be there because it depends on the nature of bar 0.

also, you don't need to use a custom indicator for fractals there is one built-in, see iFractats in the documentation.

for example:

double val=iFractals(NULL, 0, MODE_UPPER, 3);

 
davefx:


Hi,

NULL means the EA will operate on any TF. and any FX pair.

Nope, check the documentation.
 

You can Search for the Fractals. Here's an example of searching for the last fractal.

double Last_Fractal(){
    int i=0; while(i<Bars){
        double Last_Up_Fractal; double Last_Dn_Fractal;
        Last_Up_Fractal=iFractals(Symbol(),0,MODE_UPPER,i);
        Last_Dn_Fractal=iFractals(Symbol(),0,MODE_LOWER,i);
        double Last_Fractal=MathMax(Last_Up_Fractal,Last_Dn_Fractal);
        if(Last_Fractal>0){return(Last_Fractal);}
        i++;
}   }

Therefore it becomes_________if ( Last_Fractal()>Ask ){ Do_Something; }

Function not tested, given for example only.

 
ubzen:

You can Search for the Fractals. Here's an example of searching for the last fractal.

Therefore it becomes_________if ( Last_Fractal()>Ask ){ Do_Something; }

Function not tested, given for example only.


Thanks guys, I have identified the problem.

Take care,

Bye!

davefx