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

 
Artyom Trishkin:

In the loop, when n==0 print the time of bar n - you will immediately understand where the loop starts from.

It seems to show everything correctly.


 
void OnTick()
  {
   if (CopyBuffer(CrossAD, 1, 0, period_find, Buf_Arrow_Buy) != period_find)
      {  
         Print("НЕ удалось правильно скопировать данные из 1-го буфера индикатора iCrossAD, error code %d",GetLastError());
         return;
      }
         for(int n=0; n<(int)period_find; n++)
            {
               if(Buf_Arrow_Buy[n]==EMPTY_VALUE)
                  Print("Last_Arrow_Buy_index n==",n," Last_Arrow_Buy_time = ",iTime(_Symbol,0,n));
               if(Buf_Arrow_Buy[n]!=EMPTY_VALUE)
               {
                  Last_Arrow_Buy_volume = iOpen(_Symbol,_Period,n);
                  Last_Arrow_Buy_time   = iTime(_Symbol,0,n);
                  Last_Arrow_Buy_index  = n;
                  Print("Last_Arrow_Buy_volume = ",Last_Arrow_Buy_volume,", Last_Arrow_Buy_index = ",Last_Arrow_Buy_index,", Last_Arrow_Buy_time = ",Last_Arrow_Buy_time);
                  break;
               }   
            }
         
   if (CopyBuffer(CrossAD, 2, 0, period_find, Buf_Arrow_Sell) != period_find)
      {  
         Print("НЕ удалось правильно скопировать данные из 2-го буфера индикатора iCrossAD, error code %d",GetLastError());
         return;
      }
         for(int n=0; n<(int)period_find; n++)
            {
               if(Buf_Arrow_Sell[n]==EMPTY_VALUE)
                  Print("Last_Arrow_Sell_index n==",n," Last_Arrow_Sell_time = ",iTime(_Symbol,0,n));
               if(Buf_Arrow_Sell[n]!=EMPTY_VALUE)
               {
                  Last_Arrow_Sell_volume = iOpen(_Symbol,_Period,n);
                  Last_Arrow_Sell_time   = iTime(_Symbol,0,n);
                  Last_Arrow_Sell_index  = n;
                  Print("Last_Arrow_Sell_volume = ",Last_Arrow_Sell_volume,", Last_Arrow_Sell_index = ",Last_Arrow_Sell_index,", Last_Arrow_Sell_time = ",Last_Arrow_Sell_time);
                  break;
               }
            }
      
Comment("-------------------------", 
         "\n Last_Arrow_Buy_volume     = ",Last_Arrow_Buy_volume,
         "\n Last_Arrow_Buy_index        = ",Last_Arrow_Buy_index,
         "\n Last_Arrow_Buy_time         = ",Last_Arrow_Buy_time,
         "\n ---------------------- ",
         "\n Last_Arrow_Sell_volume     = ",Last_Arrow_Sell_volume,
         "\n Last_Arrow_Sell_index        = ",Last_Arrow_Sell_index,
         "\n Last_Arrow_Sell_time         = ",Last_Arrow_Sell_time
         ); 
  }
 

Starts inspection with the current candle and ends as soon as it finds a non-empty value.

 
Sergey Voytsekhovsky:
if(n==0)
   Print("Last_Arrow_Sell_index n==",n," Last_Arrow_Sell_time = ",iTime(_Symbol,0,n));
 
Sergey Voytsekhovsky:

Starts inspection with the current candle and ends as soon as it finds a non-empty value.

What's wrong then?

 
Artyom Trishkin:

What's wrong then?

 
Sergey Voytsekhovsky:
What is it?
 

With the scans everything is fine, it looks where it needs to go and when it needs to go.

But there is already a new arrow on the chart, but it is not yet visible in the comments, in the prints.


 
Artyom Trishkin:
What's there?

It is highlighted in blue that it polls both according to your option (n==0) and to mine (right after yours) - from the beginning of a new candle. It is correct, I think.

But there is already a down arrow three candlesticks back, and the indexes of the candlesticks with the outermost arrows 12 and 57 on the prints and the comments.

 
Sergey Voytsekhovsky:

With the scans everything is fine, it looks where it needs to go and when it needs to go.

But there is already a new arrow on the graph, but it is not yet visible in the comments, in the prints.


At what time is this new arrow and at what time does the cycle start?

You have to deal with your own code. Either you print all values and understand where they are coming from, or you put a breakpoint and go to debugger and see all values at each step. But I don't think you need the debugger yet...

Reason: