Download MetaTrader 5

Fractal EA different than Fractal indicator

To add comments, please log in or register
Duarte Silva
127
Duarte Silva  

Hi,

 I have used iFractal function in an EA and when it detects a fractal it prints an up/down arrow on the bar. the problem is when tester finish testing it displays the fractal indicator and the and arrow doesn't match with the indicator!

 I think that iFractal its well configured the For cycle is only for the two last candles... 

 

Previous_Bars is zero in "OnInit" :

   if (NewBarDetection())
      {
      if (Bars <0) Print("Erro na contagem de barras");
      
      Unchecked_Bars = Bars - Previous_Bars;
      Previous_Bars = Bars;
      Print("Nº de barras a ler: ", Unchecked_Bars, "Nº de barras total: ", Bars); 
           
      for(int i=1; i<Unchecked_Bars + 2;i++)
        {
         Fractal_Lower = iFractals(NULL, 0, MODE_LOWER, i);    
         if(Fractal_Lower!=NULL)
           {
            Print("Fractal Lower: ", NormalizeDouble(Fractal_Lower,3));
            if(!ObjectCreate("ARROW SELL Obj: "+TimeToString(TimeCurrent(),TIME_DATE|TIME_SECONDS), OBJ_ARROW_DOWN, 0, Time[i], High[i]))
               {
                  Print("Erro impressão objecto - Lower: ", GetLastError());
               }
            }      
         Fractal_Upper = iFractals(NULL, 0, MODE_UPPER, i);
         if(Fractal_Upper != NULL)
           {
            Print("Upper Fractal: ", NormalizeDouble(Fractal_Upper,3));
            if(!ObjectCreate("ARROW BUY Obj: "+TimeToString(TimeCurrent(),TIME_DATE|TIME_SECONDS), OBJ_ARROW_UP, 0, Time[i], Low[i]))
               {
                  Print("Erro impressão objecto - Upper: ", GetLastError());
               }
           }
        }

 the result is this:

 

 

Whats wrong?? 

Ernst Van Der Merwe
5001
Ernst Van Der Merwe  
iFractals() calculates 2 bars after the fact. So when a lower low/higher high is formed on the current bar, it cancels the lowest/highest of 2 bars back. Also known as redrawing.
Duarte Silva
127
Duarte Silva  
pipPod:
iFractals() calculates 2 bars after the fact. So when a lower low/higher high is formed on the current bar, it cancels the lowest/highest of 2 bars back. Also known as redrawing.

Hi pipPod,

 After some days triyng to implement what you have said I think I have made it. The only question is if you work with the current bar or you check the Lower low/higher high after the close of the current bar...

At the moment I'm doing:

      Control_Bars = Bars - UpperBarIndex; //UpperBarIndex its the bar number where it occured the last fractal (higher high in this case). Its the middle bar.
      if(High[Control_Bars] > High[Control_Bars+2] && High[Control_Bars] >= High[Control_Bars+1] && High[Control_Bars] >= High[Control_Bars-1] && High[Control_Bars] > High[Control_Bars-2])

 The result of my code is the same output of the indicator.

 final result

 

The code goes in attachment. Probably it isn't the best way to do it, but thanks.

Marco vd Heijden
Moderator
5128
Marco vd Heijden  
Duarte Silva:

Hi pipPod,

 After some days triyng to implement what you have said I think I have made it. The only question is if you work with the current bar or you check the Lower low/higher high after the close of the current bar...

At the moment I'm doing:

 The result of my code is the same output of the indicator.

 

 

The code goes in attachment. Probably it isn't the best way to do it, but thanks.

Bar number goes up as they get older starting by bar 0 at the right.

So if you skip bar 0 and calculate up until the highest bar you are scanning backwards in time from bar 1 to the outer bar on the left side, the one with the biggest number.

To add comments, please log in or register