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

 
mila.com:

the advisor was made to check the possibility itself, it opens correctly, but in the indicator it does not see the values of the near two buffers of the "Arrow v.3" indicator at all

So you have an indicator outside the array in the loop. Look at what limit, and what il values are in the nested loops. Where does index il refer to when limit == rates_total-2 ?

 
mila.com:

How do you see it?

See your code

 
Artyom Trishkin:

See what the limit is, and what il values are in the nested cycles.

prints the bar number of the first and second arrows, alternately

  for(int i=limit; i>=0; i--) 
     {
     for(int il=i+1;il<=i+300;il++)
        {
         if(NormalizeDouble(iCustom(NULL,0,"Arrow v.3",0,il),Digits)!=EMPTY_VALUE
            )
           {
            num_buy=il;
            Print(il);
           // break;
           }
        }
//
      if(num_buy==60)
        {
         BufferUP[i+1]=low[i+1]-distance*MyPoint;
         
        }
    }
 
Artyom Trishkin:

Check your code

I've been looking at it for three days now, I don't know what's wrong.)

Help me out
 
mila.com:

prints the bar number of the first and second arrows, alternately

What kind of weird cycle is this anyway?

Why do you go from the beginning of the story to the end and keep going back three hundred bars in a nested loop at each iteration of the first loop?

You are probably saved by iCustom(), which does not give out values outside the history data.

Well, take a look for yourself. Suppose you have a history of only 1000 bars: rates_total in this case you have 1000. Limit, 1000-2=998. So, the first history bar is excluded from the loop. Don't worry about it.

You first put an index on the bar with number 998 (rates_total-2 = 1000-2 = 998),

and then what do you do? Then you embed the loop starting from value i, equal to 998+1=999 - this is the first bar of history - there is nothing more to the left - it's empty. And you do the loop from 999 to 999+300. There is no data there - this is going outside the array.

So, limit in this situation should be such, that the embedded loop at the very beginning will reach bar 999. This is rates_total-2-300. Then, since you start the nested loop from i+1, that's when you won't go beyond the array: i=1000-2-300 = 698. In the nested loop, li=i+1 = 698+1=699, and up to li=i+300 = 698+300=998. Again the very first bar is excluded from the calculation. But there is no overrun of the array.

Apparently, you do not quite know what you are doing.

This is indicated by a very strange loop in general.

You don't need nested loops there. If you are looking for a certain number of values in the buffer of the custom indicator, then make the cycle from zero to a certain value. But not more than rates_total.

 
Artyom Trishkin:

What kind of weird cycle is this anyway?

Why do you go from the beginning of the story to the end and keep going back three hundred bars in a nested loop at each iteration of the first loop?

You are probably saved by iCustom(), which does not give out values outside the history data.

Well, take a look for yourself. Suppose you have a history of only 1000 bars: rates_total in this case you have 1000. Limit, 1000-2=998. Well, the first history bar is excluded from the loop. Let it be.

You first put an index on the bar with number 998 (rates_total-2 = 1000-2 = 998),

and then what do you do? Then you embed the loop starting from value i, equal to 998+1=999 - this is the first bar of history - there is nothing more to the left - it's empty. And you do the loop from 999 to 999+300. There is no data there - this is going outside the array.

So, limit in this situation should be such, that the embedded loop at the very beginning will reach bar 999. This is rates_total-2-300. Then, since you start the nested loop from i+1, that's when you won't go beyond the array: i=1000-2-300 = 698. In the nested loop, li=i+1 = 698+1=699, and up to li=i+300 = 698+300=998. Again the very first bar is excluded from the calculation. But there is no overrun of the array.

Apparently, you do not quite know what you are doing.

This is indicated by a very strange loop in general.


Thank you, that's very clear.

 
Artyom Trishkin:

This is indicated by a very strange loop in general.

You don't need nested loops there. If you are looking for a certain number of custom indicator buffer values, then do a loop from zero to a certain value. But not more than rates_total.

Why from zero?

I need to put a point if on the third or "N" bar there is an arrow of the called indicator. On the whole history

What is the correct cycle?

 
mila.com:

Why from zero?

I need to dot if there is an arrow on the third or "N" bar of the indicator to be called. On the whole history.

What is the correct cycle?

Where should this be done? In an indicator? In an EA?

 
Artyom Trishkin:

Where should this be done? In an indicator? In an EA?

In an indicator

 
mila.com:

In the indicator

So read iCustom() right by the first loop index.

Another question is that you need data from current bar to the left. That's why I say - read from zero to the found one, but no more than rates_total-1.

And read only when limit>1

Otherwise, there is no new data and the index of the bar you need will not change.

Reason: