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

 
Alexey Viktorov:

1. I said check, not replace. iFractals returns 0 if there is no fractal. I don't use it regularly and naturally I don't clog the not-dry remnants of memory with such trivia.

2. The function, although horribly written, still works properly.

3. The last value is displayed in Comment. Replace it with.

and see how many times it prints

A lot, but never false. As if the condition is always fulfilled. But it should be false.

 
Ghabo:

A lot, but never false. It's as if the condition is always fulfilled. But it should be false, in the screenshot, the situation contradicts the condition, but true.


In the screenshot the first fractal and the second one are marked. But according to the condition the function searches further until it finds the one below the first one. And the fourth fractal is lower than the first... Which is what the condition says.

If the condition is supplemented with

      if(f!=0) 
        {
        fr2=NormalizeDouble(f, d);
        if(fr2<fr1)
         return(true);
          else break;
        }

It will print false too.

 
Alexey Viktorov:

The first fractal and the second fractal are marked in the screenshot. But according to the condition, the function searches further until it finds the one below the first one. And the fourth fractal is lower than the first... Which is what the condition says.

If the condition is added

It will print false too.

Reversed the condition
 if(fr2>fr1) return(true);
        else break;

Prints false, but the condition is met.

aqa1

 

The second cycle always returns the price of the fractal found in the first cycle.

   for(i=nf+ num_bar; i<k; i++) 
     {
      fx=iFractals(sy,tf,MODE_UPPER,i);
      if(fx!=EMPTY_VALUE) 
        {
        fr2=NormalizeDouble(fx, d);
        return(NormalizeDouble(fr2, d));
        //if(fr2>fr1) return(true);
        //else break;
        }
     }
 
Ghabo:

The second cycle always returns the price of the fractal found in the first cycle.

You seem to have a problem with logic.

Try to describe the order of search in simple words. Think about whether you have written everything correctly. And then make a search function that will return the price of the found fractal by its serial number. As soon as you do it, and it returns the correct price for the fractal you specified by its sequence number, begin to make logic for finding the price of the next fractal (you will already have a function that returns its price at that moment). And then all that's left is to compare those prices.

And you make a heap of everything at once.

 

Maybe I misunderstand how it works?

First I find a fractal, the first one above the MA - (marked #1 in the screenshot),

int    i,k=iBars(sy,tf),kf,num_bar;

   for(i=nf+2; i<k; i++) 
     {
      f=iFractals(sy,tf,MODE_UPPER,i);
      MA=iMA(NULL,0,35,0,MODE_EMA,PRICE_CLOSE,i);
      if(f!=EMPTY_VALUE) 
        {
        // kf++;
         if(f>MA) {num_bar=i; fr1=NormalizeDouble(f, d);break;}
         
        }
     }

I look from it, further into history, the first fractal (marked #2 in the screenshot). If fractal No. 2 is greater than fractal No. 1, I return true.

      for(i=nf+ num_bar; i<k; i++) 
     {
      fx=iFractals(sy,tf,MODE_UPPER,i);
      if(fx!=EMPTY_VALUE) 
        {
        fr2=NormalizeDouble(fx, d);
        if(fr2>fr1) return(true);
        else break;
        }
     }

Is all correct?

aq11

 
Artyom Trishkin:

will return the price of the fractal found by its sequence number.

Not by number, I search by condition that the fractal is above the MA, the ordinal number can be any. The price of this fractal in the first loop is written into the variable "fr1" correctly.

The problem is in the second loop, if I understand correctly of course. Why the price of fractal number 2 is not found is unclear.

 
Ghabo:

Not by number, I search by condition that the fractal is above the MA, the ordinal number can be any. The price of this fractal in the first cycle is written into the variable "fr1" correctly.

The problem is in the second loop, if I understand correctly of course. I don't understand why the price of fractal number 2 cannot be found.

I have to retell the entire logic to you. Is there anything you can think of on your own?

1. In the first loop, we find the fractal above the MA. The number of the bar is written into the num_bar variable (bar #11 on the screenshot).

2. In the second loop we start searching for the second fractal that satisfies the condition. We start searching from num_bar... i.e. from bar #11 because nf is zero.

3. The fractal is found. The value is equal to the previous one. The condition will not be fulfilled as the condition contains > then < but not equal. If we set ==, the same gibberish will occur, but from the other side.

Probably, we should search for the second fractal from the next bar num_bar+1 or even +2.

 
Alexey Viktorov:

All the logic has to be retold to you. Is there anything you can think of on your own?

1. In the first cycle we find a fractal above the MA. The number of the bar is written into the num_bar variable (bar number 11 on the screenshot).

2. In the second loop, start searching for the second fractal that satisfies the condition. We start searching from the num_bar... i.e. from the bar #11 because nf equals zero.

3. The fractal is found. The value is equal to the previous one. The condition will not be fulfilled, because in the condition > then < but not equal. If we set ==, the same rubbish will occur but from the other side.

Probably, we should look for the second fractal from the next bar num_bar+1 or even +2.

In general, the action in first two paragraphs, I have voiced it).

For "num_bar+1" thanks.

I can't find the minimum.

The condition is not fulfilled, the arrow is set, fulfilled is not set.

The condition is as follows: if the distance from the minimum of the candle crossed by the MA to the minimumof the iLowest is greater than or equal to 100, I put the arrow.

   if(limit>60)limit=60;
   for(int i=limit; i>0; i--)
     {
      M11=iMA(NULL,0,period,shift_,method,price,i+1);
      if(open[i+1]>M11 && close[i+1]<M11){time_1=time[i+1];}

      indexS1=iBarShift(NULL,PERIOD_CURRENT,time_1,false);

      if(open[i+1]<M11 && close[i+1]>M11){time_2=time[i+1];}

      indexS2=iBarShift(NULL,PERIOD_CURRENT,time_2,false);

      //
      double val=0;
      //--- расчет минимального значения цены на indexS1 последовательных барах 
      //--- с индекса indexS2 по индекс indexS1 включительно на текущем графике 
      int val_index=iLowest(NULL,0,MODE_LOW,indexS1,i+indexS2);
      if(val_index!=-1) val=Low[val_index];
      else PrintFormat("Ошибка вызова iLowest. Код ошибки=%d",GetLastError());

      if(low[indexS1]-val>=100*Point)
        {
        BufferPointDn1[i]=high[i];
        }
      //
     }

From B to A I find the minimum of C.

A-C=100 pips at point B, should put the arrow.

Why does it not?

low1

 
Ghabo:

In general, the actions in the first two paragraphs, I said so)

A little bit wrong about the second point. You haven't defined where we start to look and when we will get what value. And this is what makes you think you should search a bit farther.

Ghabo:

The minimum cannot be found.

The condition is not fulfilled, the arrow is set, the condition is not fulfilled.

The condition is that if the distance from the minimum of the candle crossed the MA to the minimum of the iLowest is greater than or equal to 100 between the price crossovers and the MA, I put the arrow.

From B to A I find the minimum of C.

A-C=100 pips at point B, should put the arrow.

Why doesn't it put it?

There is something about this code that is hard to grasp the logic too.

At a minimum we need to know where and how variables indexS1 and indexS2 are defined and whether they are reset on every tick.

And what will happen if the МА crossing is caught in a gap?


And one more question: do you know how to use the debugger?

Reason: