iFractals returned values conundrum

 

Hello all. So, I've been messing with the iFractals indicator for like 7 hours straight now and it's driving me nuts. The visual arrows that are placed on the chart by the indicator are exactly what I'd like to use/obtain. What I have posted below works about 90% or so, but the logic also returns an up/down fractal value for bars that don't have an arrow and that also have empty "fractal up"/"fractal down" fields in the data window as well. I'm running the strat tester on a 15 minute chart and iterating through both the MODE_UPPER and MODE_LOWER enumerations. With the posted code below, which I have tried all sorts of different code iterations, the fractal arrows on the chart are exactly where I want them, but the returned values I get from my print statements/logic ends up returning values on candles where there are no visible fractal arrows. I just can't for the life of me figure out how to get the data I want back from it. If the source was available I could grab the data from the buffer, because even the indicator fields in the data window perform exactly as I desire (no value in the fields(s) means no fractal signal). This indicator has zero parameters that can be set or changed other than how many bars to shift through. The way it runs visually on the chart is precisely what I want as far as fractal signals, but the actual data being returned does not line up with that. Any ideas? This seems like such a trivial flaw in the source logic. I mean, if there was a way to just simply return "up" or "down" exactly in line with the drawn arrows, I'd be ecstatic. Any ideas or help here would be greatly appreciated. Thanks in advance.



double valBear = 0; //have tried with and without initializing this with a value
double valBull = 0; //have tried with and without initializing this with a value
bearFractal = false;
bullFractal = false;

for(int i=0;true;i++) //have tried starting the loop from i=1, and have tried setting a fixed value for iteration count as opposed to the bool eval
{
   valBear = iFractals(NULL,0,MODE_UPPER,i);
   valBull = iFractals(NULL,0,MODE_LOWER,i);
   Print("valBear ", valBear, " valBull ", valBull);
   if(valBear>0) //would basically like this statement to only execute if a visible up arrow exists
   {
      bearFractal = true;
      Print("bearFractal ", bearFractal, " bullFractal ", bullFractal);
      Print("bear i ", i); 
      break;
   }
   if(valBull>0) //would basically like this statement to only execute if a visible down arrow exists
   {
      bullFractal = true;
      Print("bearFractal ", bearFractal, " bullFractal ", bullFractal);
      Print("bull i ", i);
      break;
   }
}
 

I see at least two issues:

1. The iFractals returns the indicator handle not indicator value. Use CopyBuffer to access indicator value.(in case this is a Mql5 question)

2. The indicator value holds EMPTY_VALUE when there is no arrows. You assume it holds zero.

 
Yashar Seyyedin #:

I see at least two issues:

1. The iFractals returns the indicator handle not indicator value. Use CopyBuffer to access indicator value.(in case this is a Mql5 question)

2. The indicator value holds EMPTY_VALUE when there is no arrows. You assume it holds zero.

I appreciate your input. I for got to mention this is MQL4 I'm using, so using CopyBuffer is not possible. The function to call the indicator returns a numerical value (double). That's why this seems like such a weird implementation of the iFractals calls on MQL4. It looks like the the actual buffers in the data window are accessing value/empty_value, but because this indicators source is wrapped in the program somewhere, it can not be accessed through iCustom either, as it will return something like "failed to load /iFractals.ex4.
 

I can't reproduce the problem.

I simplified your code (but kept the fractal detection logic) and set it to print all fractals for the last 1000 bars. Everything is working correctly for me

void OnStart()
  {
   int limit = Bars;
   if(limit > 1000)
      limit = 1000;
   for(int i=0; i < limit; i++)
     {
      double valBear = iFractals(NULL,0,MODE_UPPER,i);
      double valBull = iFractals(NULL,0,MODE_LOWER,i);
      if(valBear>0 || valBull>0)
         PrintFormat("Fractal on bar# %i (%s). Values: upper %s, lower %s.", i, TimeToString(Time[i]), prcToStr(valBear), prcToStr(valBull));
     }
  }

string prcToStr(double price)
  {
   return(DoubleToString(price, Digits()));
  }
 
Vladislav Boyko #:

I simplified your code (but kept the fractal detection logic) and set it to print all fractals for the last 1000 bars. Everything is working correctly for me

Run this script and show the log for those bars on which you get false fractals

 
Vladislav Boyko #:

Run this script and show the log for those bars on which you get false fractals

Your logic is working for me! Really strange. Trying to figure out what exactly is different in yours than what I had done. I had many different iterations of code I had tried. In the one I had posted above, I was explicitly setting the valBear and valBull to zero beforehand as I was trying different things to achieve the result I was looking for. In another, I had an || operator I was using, pretty much exactly like you are. However, I took yours and tested it and then modified it just slightly, but it appears to working exactly as desired for me. Thanks a bunch mate! I really appreciate it.

void fractal()
{
   for(int i=0;true; i++)
   {
      double valBear = iFractals(NULL,0,MODE_UPPER,i);
      double valBull = iFractals(NULL,0,MODE_LOWER,i);
      if(valBear>0 || valBull>0)
      {
         PrintFormat("Fractal on bar# %i (%s). Values: upper %s, lower %s.", i, TimeToString(Time[i]), prcToStr(valBear), prcToStr(valBull));
         break;
      }
   }
}
string prcToStr(double price)
{

   return(DoubleToString(price, Digits()));
}