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

 

Got it, changed it.

   uint n=0;

the errors are gone. Thank you.

 
Sergey Voytsekhovsky:

Got it, changed it.

the errors are gone. Thank you.

These are not errors, they are warnings.

Forum on trading, automated trading systems & strategy testing

Any questions from newbies on MQL4 and MQL5, help and discussion on algorithms and codes

Artyom Trishkin, 2019.05.20 15:16

What are the types of variables n and period_find ? The most important thing and didn't show...

Try it:

for(n=0; n<(int)period_find; n++)

And in general - why do you declare a loop variable at OnTick() handler level ?

You can do it this way:

for(int n=0; n<(int)period_find; n++)

You can remove n declaration from OnTick() - we don't need it there.


 
Artyom Trishkin:

These are not mistakes, they are warnings.


Great, I'll fix it.

If you don't mind my saying so, please give me a hint how I can get the values of the prices on which the Arrows were created. Assuming I already have their indexes. ???

 

Now it's cursing in a different way:

'n' - undeclared identifier Test_iCustom.mq5 82 48

Probably because n is used outside the loop, as a found index ???
 
         for(int n=0; n<(int)period_find; n++)
            {
               if(Buf_Arrow_Buy[n]!=EMPTY_VALUE)break;
            }
         Last_Arrow_Buy_volume = Buf_Arrow_Buy[n];
         Last_Arrow_Buy_index  = n;
 
Sergey Voytsekhovsky:

Great, I'll fix it.

If you don't mind my saying so, please give me a hint how I can get the values of the prices on which the Arrows were created. Assuming I already have their indexes. ???

Either iOpen(), or CopyOpen(), or CopyRates() if getting several prices at once.

In my opinion, in the indicator the arrows are placed on the chart at the open prices of the bars.

Документация по MQL5: Доступ к таймсериям и индикаторам / iOpen
Документация по MQL5: Доступ к таймсериям и индикаторам / iOpen
  • www.mql5.com
Значение цены открытия бара (указанного параметром shift) соответствующего графика или 0 в случае ошибки. Для получения дополнительной информации об ошибке необходимо вызвать функцию GetLastError(). Функция всегда возвращает актуальные данные, для этого она при каждом вызове делает запрос к таймсерии по указанным символу/периоду. Это означает...
 
Artyom Trishkin:

Either iOpen(), or CopyOpen(), or CopyRates() if getting multiple prices at once.

In my opinion, the indicator puts arrows on the chart at open prices of bars.

Yes, it says so there:

SetArrow(prefix+"ChartArrowUP_"+TimeToString(time[i]),InpColorBullishArrow,time[i],open[i],(char)241,ANCHOR_TOP,InpArrowSize);

I'll tryiOpen().

And instead of n I add another variable, or it can be this way:?

   int n=0;
   
   if (CopyBuffer(CrossAD, 1, 0, period_find, Buf_Arrow_Buy) != period_find)
      {  
         Print("НЕ удалось правильно скопировать данные из 1-го буфера индикатора iCrossAD, error code %d",GetLastError());
         return;
      }
         for(n=0; n<(int)period_find; n++)
            {
               if(Buf_Arrow_Buy[n]!=EMPTY_VALUE)break;
            }
         Last_Arrow_Buy_volume = Buf_Arrow_Buy[n];
         Last_Arrow_Buy_index  = n;
         Print("Last_Arrow_Buy_volume = ",Last_Arrow_Buy_volume,", Last_Arrow_Buy_index = ",Last_Arrow_Buy_index);
 
Sergey Voytsekhovsky:

The scope of a loopvariable is limited to the loop body. Assign the required values before break:

//+------------------------------------------------------------------+
for(int i=0; i<(int)period_find; i++)
  {
   if(Buf_Arrow_Buy[i]!=EMPTY_VALUE)
     {
      Last_Arrow_Buy_volume = Buf_Arrow_Buy[i];
      Last_Arrow_Buy_index  = i;
      break;
     }
  }
//+------------------------------------------------------------------+
 
Artyom Trishkin:

The scope of a loopvariable is limited to the loop body. Assign the required values before break:

Got it, it works both ways, no warnings.

Please tell me how to do it kosher, with calculations in the loop body, beforebreak; or it's better to take calculations out of the loop ???

 
Sergey Voytsekhovsky:

Got it, it works both ways, no warnings.

Please tell me what is more kosher, with calculations in the body of the loop, beforebreak; or it is better to take calculations out of the loop ???

Which calculations?

Reason: