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

 
Aleksei Stepanenko:

You need to check, it's not certain that you have bars_quantity there

Changed the code, still array out of range in the same place

double GetExtremumZigZagPriceHigh(string symbol="",ENUM_TIMEFRAMES timeframe=0,int extremum_number=0)//,int depth=12,int deviation=5,int backstep=3)
  {
   if(symbol=="") //Если symbol = "" , то..
      symbol=Symbol(); //Присвоить переменной symbol значение текущего символа на графике.

//Объявить необходимые переменные:
   double price[];                                                 //Цена экстремума выбранная из массива таймсерии.
//datetime time[];
   int    count;                                                   //Счетчик цикла.
int bars_quantity=1000; //Количество баров на графике.
int extremum_count=0;                                           //Счетчик экстремумов.

   ArraySetAsSeries(price,true);                   //Устанавить флаг, чтобы индексация массива производилась как в таймсериях.
  
   if(CopyBuffer(handle,1,0,bars_quantity,price)<=0) return(0);     //Скопировать в динамический массив price[] цены указанного количества баров.


   for(count=1; count<bars_quantity; count++) //Запустить цикл, который будет бежать по каждому бару.
     {
      if(price[count]!=0) //Если Цена Зигзага есть, то есть не равна нулю, то..
        {
         extremum_count++;        //Увеличить счетчик экстремумов на одну единицу.

         if(extremum_count>extremum_number) //Если счетчик экстремумов превысил значение указанного номера экстремума, то..
            return(price[count]);                 //Вернуть эту цену.
        }
     }
     
//Print("GetExtremumZigZagPrice(): Экстремум ЗигЗага ",extremum_number," не найден"); //А до тех пор, пока ЗигЗаг не показывает цену,
   return(0);                                                                          //Печатать Print, и возвращать ноль.
  }
 

If there is no error, it does not mean that all the data quantity is present. The bars_quantity is just your order and what will give is another matter.

int elements=CopyBuffer(handle,1,0,bars_quantity,price);
for(count=1; count<elements; count++) 
 
Aleksei Stepanenko:

If there is no error, it does not mean that all the data quantity is present. The bars_quantity is just your order and what will give is another matter.

Thank you
 

Good day to you all!

There is a simple code in MQL4 that initializes each value of an array and on each iteration prints the value of each element of the array in the Print() function. At the end of this loop, Print() will print 30 times in the log.

int P1;
double LoY[31];
void OnTick()
{
if (P1==0)
{
for(int r=0; r<31;r++)
{
LoY[r]=1.6104+(r*2)*0.0001;
Print("-------------------------------------LoY[r]--------------=",  LoY[r]);
P1=1;
}
}
}

QUESTION .

Which language construct in MQL4 or function in MQL4 in above code Print() will print() only 1 time at the end of the loop, with all array elements filled in one line, i.e. it will take the following form

Print("---LoY[0]--", 1.6104, "---LoY[1]--". , 1.6106,"---LoY[2]--", 1.6108,"---LoY[3]--", 1.6110,"---LoY[4]--", 1.6112,................"---LoY[30]--", 1.6164);

I would be very grateful if you could write an example of such code and not just explain it in words.
Thanks for your help.

 
string str="";

for(int r=0; r<31;r++)
   {
   LoY[r]=1.6104+r*0.0001;
   str+="--LoY["+IntegerToString(r)+"]--, "+DoubleToString(LoY[r],4)+", ";
   }
Print(str);
 
ANDREY:

Good day to you all!

There is a simple code in MQL4 that initializes each value of an array and prints the value of each element of the array in the Print() function at each iteration. At the end of this loop, Print() will print 30 times in the log.

QUESTION .

Which language construct in MQL4 or function in MQL4 in above code Print() will print() only 1 time after the end of loop with all elements of the array filled to the same line, i.e. it will take the following form

Print("---LoY[0]--", 1.6104, "---LoY[1]--". , 1.6106,"---LoY[2]--", 1.6108,"---LoY[3]--", 1.6110,"---LoY[4]--", 1.6112,................"---LoY[30]--", 1.6164);

I would be very grateful if you could write an example of such code and not just explain it in words.
Thanks for your help.

int P1 = 0; // Несмотря ни на что не забывайте инициализировать переменные
string stroka = "";
double LoY[31];
void OnTick()
{
if (P1==0)
{
for(int r=0; r<31;r++)
{
LoY[r]=1.6104+r*0.0001;
stroka += "---LoY[r] = "+DoubleToString(LoY[r], 4);
//Print("-------------------------------------LoY[r]--------------=",  LoY[r]);
P1=1;
}
Print(stroka);
}
}
 
Aleksei Stepanenko:

How many seconds ahead of me? ))))

 
More helpers today
 
Alexey Viktorov:

Thank you for your help

 
Aleksei Stepanenko:

Thank you for your help.

Reason: