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

 
Alexey Viktorov:

Read the documentation and example code carefully. Your loop is not organised correctly.

Don't tell me that for and while loops work the same way. That's not the problem, it's the highlighted lines.

Thanks, I've read it (that's where I started)

Everything works in my code, just a glitch in MT4, charts 8 but sees 7(

2021.03.10 11:59:23.914 Label EURCAD,M15: 9/
2021.03.10 11:59:23.914 Label EURCAD,M15: 8/
2021.03.10 11:59:23.914 Label EURCAD,M15: 7/
2021.03.10 11:59:23.914 Label EURCAD,M15: 6/EURUSD
2021.03.10 11:59:23.914 Label EURCAD,M15: 5/EURUSD
2021.03.10 11:59:23.914 Label EURCAD,M15: 4/EURUSD
2021.03.10 11:59:23.914 Label EURCAD,M15: 3/EURUSD
2021.03.10 11:59:23.914 Label EURCAD,M15: 2/EURUSD
2021.03.10 11:59:23.914 Label EURCAD,M15: 1/EURUSD
2021.03.10 11:59:23.914 Label EURCAD,M15: 0/EURUSD
 
Unlikely. As many times as I have sinned about the platform, I have always turned out to be wrong myself.
 
Aleksei Stepanenko:
Unlikely. How many times have I blamed the platform, it always turns out to be wrong myself.
Can't see one particular chart, can see all the others and if I add new ones, can see them
 
long currChart=ChartFirst();
int i=0;
while(currChart>=0)
  {
  Print(i,ChartSymbol(currChart)," ID =",currChart);
  currChart=ChartNext(currChart); // на основании предыдущего получим новый график
  i++;// не забудем увеличить счетчик
  }

Why don't you try this?

 
Aleksei Stepanenko:

Why don't you try this?

Same thing.

2021.03.10 12:45:48.434 Label EURCAD,M15: 8/
2021.03.10 12:45:48.434 Label EURCAD,M15: 7/EURUSD
2021.03.10 12:45:48.434 Label EURCAD,M15: 6/EURUSD
2021.03.10 12:45:48.434 Label EURCAD,M15: 5/EURUSD
2021.03.10 12:45:48.434 Label EURCAD,M15: 4/EURUSD
2021.03.10 12:45:48.434 Label EURCAD,M15: 3/EURUSD
2021.03.10 12:45:48.434 Label EURCAD,M15: 2/EURUSD
2021.03.10 12:45:48.434 Label EURCAD,M15: 1/EURUSD
 

Why is the printing different? Different code?

Print(i,ChartSymbol(currChart)," ID =",currChart);
2021.03.10 12:45:48.434 Label EURCAD,M15: 1/EURUSD

How many charts are open, which ones? Symbol, period.

Unfolded/unfolded?
 
MakarFX:

Thanks, that's what I read (that's where I started).

Everything works in my code, just a glitch in MT4, charts 8 but sees 7(

Very bad reading. Probably like forced reading at school. I've read it but nothing has been imprinted on my brain.

Here 's an example. The purpose is different there, but still the enumeration of open charts doesn't change depending on the purpose of the enumeration.

Or here is the code

/********************Script program start function*******************/
void OnStart()
 {
  long prevChart = 0;
  int i = 0;
  do
   {
    prevChart = ChartNext(prevChart);
    ChartSetInteger(prevChart, CHART_BRING_TO_TOP, 0, true);
    Sleep(200);
    i++;
   }
  while(prevChart >= 0);
 }/*******************************************************************/
Особенности языка mql5, тонкости и приёмы работы
Особенности языка mql5, тонкости и приёмы работы
  • 2021.01.15
  • www.mql5.com
В данной теме будут обсуждаться недокументированные приёмы работы с языком mql5, примеры решения тех, или иных задач...
 
Aleksei Stepanenko:

Why is the printing different? Different code?

How many charts are open, which ones? Symbol, period.

Unfolded/unfolded?
Alexey Viktorov:

Very bad reading. Must have been like forced reading at school. I mean, I read it, but nothing stuck in my head.

Here 's an example. The goal is different there, but still the enumeration of open charts does not change depending on the purpose of this enumeration.

Or here is the code

The issue is removed, the problem is solved by restarting the terminal

 

Help me avoid array out of range in this code

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);                   //Устанавить флаг, чтобы индексация массива производилась как в таймсериях.
   CopyBuffer(handle,1,0,bars_quantity,price);     //Скопировать в динамический массив 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, и возвращать ноль.
  }

It's this location that's getting thrown out.

if(price[count]!=0)
 
CopyBuffer

Возвращаемое значение

Number of copied array elements or -1 in case of error .

Note

When requesting data from an indicator, if the requested timeseries have not been built yet or need to be downloaded from the server, the function will immediately return -1, but the loading/building process itself will be initiated.

When requesting data from the Expert Advisor or a script, the loading from the server will be initiated if the terminal does not have these data locally, or the building of the required timeseries will begin if the data can be built from the local history, but they are not ready yet. The function will return the amount of data that will be ready when the timeout expires.

Check if you have bars_quantity there

Reason: