Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 16

 

Hello, can you please help me find the price of the larger fractal, from the first - near top four fractals.

 
mila.com:

Hello, can you please help me find the price of the larger fractal, from the first - near top four fractals.

void OnTick()
{
   Comment("Min = ",MaxMinFractal(MODE_LOWER, 4),"; Max = ",MaxMinFractal(MODE_UPPER, 4));
}

//===============================================================================================
//--------------------------------- Возвращает Max/Min фрактала --------------------------------+
//===============================================================================================
double MaxMinFractal(int mode=MODE_UPPER, int nf=4) {
string symb=Symbol();
double f=0,min=9999999,max=0;
int kf=0;
  for(int i=3; i<iBars(symb, 0); i++) {
   if(mode==MODE_LOWER){
    f=iFractals(symb, 0, MODE_LOWER, i);
    if(f!=0) {
      kf++;
      if(min>iLow(symb,0,i)) min=iLow(symb,0,i);
      if(kf>=nf) return(min);
     }}
    if(mode==MODE_UPPER){
    f=iFractals(symb, 0, MODE_UPPER, i);
    if(f!=0) {
      kf++;
      if(max<iHigh(symb,0,i)) max=iHigh(symb,0,i);
      if(kf>=nf) return(max);
    }}}
  return(-1);
}
 
mila.com:

Hello, can you please help me find the price of the larger fractal, from the first - near top four fractals.

#property strict

void OnStart()
  {
   int i=1,cnt=1;
   double lastupfr=0;

   while(cnt<5)
     {
      double upfr=iFractals(_Symbol,0,1,i);
      if(upfr!=0)
        {
         if(upfr>lastupfr) lastupfr=upfr;
         cnt++;
        }
      i++;
     }
   Comment("Biggest UpFractal = ",lastupfr);
  }
 
Vitaly Muzichenko:
Not to compare fractals, but to find the maximum, up to a bar with a fractal,...that simple, Thank you.
 
Vitalie Postolache:

Even shorter ) Thank you.

And how, of these, customisable, fractals, do you choose the maximum one?

//|    nl - количество баров слева                                             |
//|    nr - количество баров справа                                            |
//+----------------------------------------------------------------------------+
double GetNearestUpFractal(string sy="0", int tf=0, int nl=2, int nr=2) {
  bool f;
  int  fb, i, nb=-1;

  if (sy=="" || sy=="0") sy=Symbol();
  if (nl<1) nl=1;
  if (nr<1) nr=1;

  fb=nr;
  while (nb<0) {
    fb++;
    f=True;
    for (i=fb; i>fb-nr; i--) {
      if (iHigh(sy, tf, i)<iHigh(sy, tf, i-1)) { f=False; break; }
    }
    if (f) {
      for (i=fb; i<fb+nl; i++) {
        if (iHigh(sy, tf, i)<iHigh(sy, tf, i+1)) { f=False; break; }
      }
      if (f) { nb=fb; break; }
    }
  }

  return(iHigh(sy, tf, nb));
}
 
mila.com:

Even shorter ) Thank you.

And how, of these, customisable, fractals, do you choose the maximum one?

//|    nl - количество баров слева                                             |
//|    nr - количество баров справа                                            |
//+----------------------------------------------------------------------------+
double GetNearestUpFractal(string sy="0", int tf=0, int nl=2, int nr=2) {
  bool f;
  int  fb, i, nb=-1;

  if (sy=="" || sy=="0") sy=Symbol();
  if (nl<1) nl=1;
  if (nr<1) nr=1;

  fb=nr;
  while (nb<0) {
    fb++;
    f=True;
    for (i=fb; i>fb-nr; i--) {
      if (iHigh(sy, tf, i)<iHigh(sy, tf, i-1)) { f=False; break; }
    }
    if (f) {
      for (i=fb; i<fb+nl; i++) {
        if (iHigh(sy, tf, i)<iHigh(sy, tf, i+1)) { f=False; break; }
      }
      if (f) { nb=fb; break; }
    }
  }

  return(iHigh(sy, tf, nb));
}
#property strict

void OnStart()
  {
   int i=1,cnt=1;
   double lastupfr=0;

   while(cnt<5)
     {
      double upfr=GetNearestUpFractal(_Symbol,0,2,2);
      if(upfr!=0)
        {
         if(upfr>lastupfr) lastupfr=upfr;
         cnt++;
        }
      i++;
     }
   Comment("Biggest UpFractal = ",lastupfr);
  }
//-----------
//|    nl - количество баров слева                                             |
//|    nr - количество баров справа                                            |
//+----------------------------------------------------------------------------+
double GetNearestUpFractal(string sy="0", int tf=0, int nl=2, int nr=2) {
  bool f;
  int  fb, i, nb=-1;

  if (sy=="" || sy=="0") sy=Symbol();
  if (nl<1) nl=1;
  if (nr<1) nr=1;

  fb=nr;
  while (nb<0) {
    fb++;
    f=True;
    for (i=fb; i>fb-nr; i--) {
      if (iHigh(sy, tf, i)<iHigh(sy, tf, i-1)) { f=False; break; }
    }
    if (f) {
      for (i=fb; i<fb+nl; i++) {
        if (iHigh(sy, tf, i)<iHigh(sy, tf, i+1)) { f=False; break; }
      }
      if (f) { nb=fb; break; }
    }
  }

  return(iHigh(sy, tf, nb));
}
Like this.
 
Alekseu Fedotov:

Like this

So returns the price of the nearest fractal.

How do I find the maximum of the four configurable fractals?

 
mila.com:

So returns the price of the near fractal.

How do I find the maximum of the four configurable fractals?

Um... you need to select 4 tunable fractals, and by blowing away the worthless lower fractals, leave one maximal:)
 
Alexey Kozitsyn:
Um... You need to select the 4 fractals set up for selection, and by blowing away the worthless inferior fractals, leave one Maximka:)
How to do that?
 
mila.com:
How do you do it?
In a loop.