Errors, bugs, questions - page 1437

 
Документация по MQL5: Математические функции / MathIsValidNumber
Документация по MQL5: Математические функции / MathIsValidNumber
  • www.mql5.com
Математические функции / MathIsValidNumber - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
The behaviour is different, due to a more aggressive optimiser for MQL5 code.
 
Ilyas:
MathIsValidNumber
Thank you, I didn't know
 
Ilyas:
The behaviour is different because of more aggressive optimizer for MQL5 code.
Also MT4 was smarter and gave a "integral constant overflow" warning, while MT5 was silent.
 
Ilya Malev:

1. Why in MT4 and MT5 does this code lead to different results (and more logical in MT4)?

Read documentation

What does EMPTY_VALUE mean in MQL4?

Прочие константы - Документация на MQL4
  • docs.mql4.com
Прочие константы - Документация на MQL4
 
Сергей Таболин:

Can you tell me why the following line (when first accessed) gives an "out of range" error:

Declare - declared, but who will fill buffer buf_ldn[ldn]?
 
Сергей Таболин:

Look at the values of pr_open and pr_close the first time they are accessed.
 
Сергей Таболин:

that's the fill-in, isn't it?

Or am I missing something?

You declared an array but didn't specify an array size...

Static exampleint buf_lup[1000], buf_ldn[20000];

 
Сергей Таболин:

that's the fill-in, isn't it?

Or am I missing something?

No, it's not an array fill. Besides, if ldn = 0;, by putting 0 into [ ] you've declared 0 elements in the array, i.e. there's not even one element there. Read the article Arrays in MQL5: Fundamentals of MQL5 Programming.
 
Сергей Таболин:

that's the fill-in, isn't it?

Or am I missing something?

You have to set the size of the array before you fill it. (ArrayRezise). A simple example:

//+------------------------------------------------------------------+
//|                                                         Test.mq5 |
//|                              Copyright © 2015, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2015, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.00"
#property script_show_inputs
input bool show_error=true; // true - выполнить с ишибкой
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   int buf_ldn[]; // объявили динамический массив.
   Print("Размер массива buf_ldn[]=",ArraySize(buf_ldn)); // выведем на печать размер массива
   if(show_error)
     {
      //--- попытка присвоить значение элементу массива с индексом "0" вызовет ошибку:
      //--- Test (EURUSD,M15)   array out of range in 'Test.mq5' (22,14)
      buf_ldn[0]=1;
     }
   else
     {
      //--- установим новый размер массива:
      ArrayResize(buf_ldn,1);
      //--- попытка присвоить значение элементу массива с индексом "0" НЕ вызовет ошибку:
      buf_ldn[0]=1;
      //--- выведем на печать размер массива и значение элемента с индексом "0"
      Print("Размер массива buf_ldn[]=",ArraySize(buf_ldn),", элемент с индексом ""0"" имеет значение:",buf_ldn[0]);
     }
  }
//+------------------------------------------------------------------+
Files:
Test.mq5  2 kb