problem when identifying fractal formed

 

Hi I tried to create an EA using fractal indi. Since my EA only works every new bar, fractal only formed at least 3 bars later. In here I tried to find a fractal through looping.

int CheckOpenPosition(int shift=0)
  {
   int result=0;
   for(int i=0; i<shift; i++)
     {
      if(fractalDown(i)==EMPTY_VALUE && fractalUp(i)==EMPTY_VALUE)
         continue;
      if(fractalDown(i)<Open[i])
         result=1;
      if(fractalUp(i)>Open[i])
         result=2;
     }
   return result;
  }

After testing it I found some problem:

1. Since fractal only formed after 3 bars later, the signal should form 3 bars later. e.g. if fractal occurred at 14:30 than the signal should be triggered at 16:00 (M30). Instead of that, the signal happened when the fractal formed (image attached, signal should be occurred at the arrow).

2. Since I'm only trying to find when the fractal formed. When fractal isn't formed strategy tester shouldn't print any signal, but instead of that it prints as a "buy signal".

is there anyone can help with these problem?

Files:
Capture.PNG  94 kb
Test.mq4  3 kb
 
Luandre Ezra:

Hi I tried to create an EA using fractal indi. Since my EA only works every new bar, fractal only formed at least 3 bars later. In here I tried to find a fractal through looping.

After testing it I found some problem:

1. Since fractal only formed after 3 bars later, the signal should form 3 bars later. e.g. if fractal occurred at 14:30 than the signal should be triggered at 16:00 (M30). Instead of that, the signal happened when the fractal formed (image attached, signal should be occurred at the arrow).

2. Since I'm only trying to find when the fractal formed. When fractal isn't formed strategy tester shouldn't print any signal, but instead of that it prints as a "buy signal".

is there anyone can help with these problem?

If I am right:

  • You are mistaking the signal at 14:30 should be triggered at 15:30 with a probability of repainting (to erase it, if not confirmed);
  • At 14:30, in the log it is logging the up fractal from 13:30
 
  1.       if(fractalUp(i)>Open[i])

    This will not work as EMPTY_VALUE is always greater than any price.

  2. Why are you checking bars zero through two? You won't ever have a fractal on them.

  3. Your code
    int CheckOpenPosition(int shift=0)
      {
       int result=0;
       for(int i=0; i<shift; i++)
         {
          if(fractalDown(i)==EMPTY_VALUE && fractalUp(i)==EMPTY_VALUE)
             continue;
          if(fractalDown(i)<Open[i])
             result=1;
          if(fractalUp(i)>Open[i])
             result=2;
         }
       return result;
      }
    simplified
    int CheckOpenPosition(int shift=3)
      {
       while(true)
         {
          if(fractalDown(shift) != EMPTY_VALUE) return 1;
          if(fractalUp(shift)   != EMPTY_VALUE) return 2;
          ++shift;
         }
       return 0; /*NOT REACHED*/
      }

 
William Roeder #:
simplified
int CheckOpenPosition(int shift=3)
  {
   while(true)
     {
      if(fractalDown(shift) != EMPTY_VALUE) return 1;
      if(fractalUp(shift)   != EMPTY_VALUE) return 2;
      ++shift;
     }
   return 0; /*NOT REACHED*/
  }
this code only return buy condition only.

    I change the code and it looks like this.

    double fractalPrice=0; //variable to store last fractal price
    int CheckFractal(int shift=5)
      {
       int result=0;
       for(int i=1; i<shift; i++) //start from 1, cause in strat tester there's a fractal formed on 1 bars before
         {
          double fractalUp = iFractals(Symbol(),PERIOD_CURRENT,MODE_UPPER,i);
          double fractalDown = iFractals(Symbol(),PERIOD_CURRENT,MODE_LOWER,i);
          if(fractalDown==0 && fractalUp==0)
             continue;
          if(fractalDown>0)
            {
             Print("fractal down formed"); /test if fractal formed
             if(fractalDown==fractalPrice) //when new bar formed, if there's new fractal then break
               {
                Print("it is the last fractal down");
                break;
               }
             if(fractalDown!=fractalPrice)
               {
                result=1;
                fractalDown=fractalPrice;
               }
            }
          if(fractalUp>0)
            {
             Print("fractal up formed"); //test if fractal formed
             if(fractalUp==fractalPrice) //when new bar formed, if there's new fractal then break
               {
                Print("it is the last fractal up");
                break;
               }
             if(fractalUp!=fractalPrice)
               {
                result=2;
                fractalUp=fractalPrice;
               }
            }
         }
       return result;
      }

    here the code is somewhat working but there's a bug that prints this line of code twice even though EA only working once per bar. Second problem is that it prints a open trade condition even though there isn't fractal formed.