[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 720

 
artmedia70:
I see you're already coming to a decision yourself
I am coming to the decision... But it's like a dog: I understand what I understand, but I can't say it, that is, I can't represent it in the code.)
Maybe it's the heat that makes my brain melt.)
 
Shuba:
I am approaching the solution... It's like a dog: I understand what I understand, but I can't say it, i.e. I can't represent it in the code.)
Maybe it's the heat that makes my brain melt.)
How do you look for fractals?
 
artmedia70:
How do you search for fractals?

I look for fractals using the ZIGZAG-FRACTALS indicator with this function:

void GetSignal()
  {
  int UpCount = 0, DnCount = 0;                                        // счетчик пиков ЗЗ
  int i = 0;                                                              // счетчик баров
  double ZZFirst = 0;                            // Значение первого найденного экстремума
  ArrayInitialize(ZZVUp, 0);                       // Значения верхних экстремумов зигзага
  ArrayInitialize(ZZVDn, 0);                         //Значения нижних экстремумов зигзага
  
  while(i < Bars && (UpCount < 2 || DnCount < 2))
    {
    double ZZCur = iCustom(NULL,0,"BW ZIGZAG-FRACTALS_2",0,i);
    if(ZZCur != 0)                                                   // найден экстремум
      {
      if(ZZFirst != 0)                             // Это не первый найденный экстремум
        {
        if(ZZCur == High[i] && UpCount < 2)
          {
          ZZVUp[UpCount] = ZZCur;
          ZZNUp[UpCount] = i;
          UpCount++;
          }         
          if(ZZCur == Low[i] && DnCount < 2)
            {
            ZZVDn[DnCount] = ZZCur;
            ZZNDn[DnCount] = i;
            DnCount++;
            }         
        }
      else
        ZZFirst = ZZCur; 
      }
    i++;
    } 
  if(i == Bars) return;                           // Последний посчитанный бар запоминаем
  
  }
 

Now I have added to the lines: if(ZZCur == High[i] && UpCount < 2) and if(ZZCur == Low[i] && DnCount < 2) checking for the next fractal higher or lower than the first one found.

We have the following lines

if(ZZCur == High[i] && ZZCur > ZZFirst && UpCount < 2) and

if(ZZCur == Low[i] && ZZCur < ZZFirst && DnCount < 2)

But in the end the search is somehow inadequate :(

In the picture a thick white line shows how it should be and a thin green line shows how it is done...


 
Shuba:

I search for fractals using the ZIGZAG-FRACTALS indicator with this function:

Try searching with this function:

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 13.08.2008                                                     |
//|  Описание : Возвращает номер бара фрактала по его номеру.                  |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента        ("" или NULL - текущий символ)     |
//|    tf - таймфрейм                       (    0       - текущий ТФ)         |
//|    nf - номер фрактала                  (    0       - последний)          |
//+----------------------------------------------------------------------------+
int GetFractalBar(string sy="0", int tf=0, int nf=0) {
  if (sy=="" || sy=="0") sy=Symbol();
  double f=0;
  int    i, k=iBars(sy, tf), kf;

  for (i=2; i<k; i++) {
    f=iFractals(sy, tf, MODE_LOWER, i);
    if (f!=0) {
      kf++;
      if (kf>nf) return(i);
    }
    f=iFractals(sy, tf, MODE_UPPER, i);
    if (f!=0) {
      kf++;
      if (kf>nf) return(i);
    }
  }
  Print("GetFractalBar(): Фрактал не найден");
  return(-1);
}

This function returns the bar number of the fractal. First you call it with parameter nf = 0 - the last fractal will be found, and then you call this function in the loop, where nf = cycle counter from 1 to ... as long as necessary. In the loop body, check if the next found fractal matches the criteria you need and if it does, exit the loop. After the analysis you will have the bar numbers of two fractals you need and do with them what you want.

 
artmedia70:

Try searching with this function:

The function returns the bar number of the fractal. First you call it with parameter nf = 0 - the last fractal will be found, and then you call this function in the loop, where nf = cycle counter from 1 to ... as long as necessary. In the loop body, check if the next found fractal matches the criteria you need and if it does, exit the loop. After the analysis you will have the bar numbers of two fractals you need and do with them what you want.


Thank you) I'll give it a try now.
 
Vinin:


In the tester or on the demo?

In the tester the point on the other instruments will be 0


It was in the tester,... I have not got any information about it, but I'm sure it will be useful for me. So, as a result, I made a lot of trouble with my trawl code and took KimIV's trawl pairs monitoring function. Now everything works on demo ))

Thanks for your help everyone, your explanations are very helpful.

 

Seems to have solved the problem, but the question remains...

How do I deinitialise a variable for reuse?

 

You can't, when you initialize a variable, it just allocates an area of RAM, so why reassign it? Just reset the variable to zero, and use it as many times as you like. As a matter of fact, what's the problem? Why deinitialise a variable? It just doesn't make sense.

 
ToLik_SRGV:

Why deinitialise a variable?



The condition if

for(int a=0;a<8;a++)

here we do something

otherwise if another condition

for(int a=0;a<8;a++)

do something else.

The point is not to multiply variables, lots of conditions and counters.