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

 

Hello all, I have a question about MQL4

By default, the array is indexed from 0 and in ascending order

Q&A

With which function, or language construct, can the above array be indexed by 10 values with arbitrary integer values and in any order? For example, as below. I would be very grateful if you could demonstrate this method with appropriate code.

Thank you.

 
ANDREY:

Hello all, I have a question about MQL4

By default, the array is indexed from 0 and in ascending order

Q:

With which function, or language construct, can I index the above array to 10 values with arbitrary integer values and in any order? For example, as below. I would be very grateful if you could demonstrate this method with appropriate code.

Thank you.

Shuffle randomly, buffer or indexes(MathRand)

 
Valeriy Yastremskiy:

In the indicator in the Alert structure. The 5th line from the bottom isAlert(b);

This appears to be the number of milliseconds since the system started)

Thank you!
 
Taras Slobodyanik:

Shuffle randomly, buffer or indexes (MathRand)

Regarding arrangement of indexes in random sequence, I understand that this is done using the MathRand() function.

My question is what function can help me replace index values, which are on default (0,1,2,3,4,5,6...9) with necessary for me index values, for example ( 45,90,119,120,234,336,338,564,607,901). I do not need this operation to write an indicator.

Thank you.

 
ANDREY:

Regarding arrangement of indexes in arbitrary sequence, I understand that it is done with MathRand() function.

The question And with help of which function I can replace index values, which are on default (0,1,2,3,4,5,6...9) with necessary for me index values, for example ( 45,90,119,120,234,336,338,564,607,901). I do not need this operation to write an indicator.

Thank you.

Create a second buffer - index buffer.
Fill it with mixed values, from 0 to size_buffer - that's the indexes)

..or just take a random number and use it to get the buffer value.
 
Taras Slobodyanik:

Create a second buffer - an index buffer.
Fill it with shuffled values, from 0 to size_buffer - that's the indexes)

..or just take a random number and use it to get the buffer value.

Thanks for the help.

Here is a simple code

double MaX[10];
int a;
void OnTick()
{
if (Minute()!=Min)
{
if (a==9)
{
a=0;
}
a++;
MaX[a]=Bid;
Min=Minute();
}
}

In 10 minutes the array will be filled with price values with indexes from 0 to 9.
If you don't mind, please change the code so that the array is filled with the same values, but the indexes of this array are in the following order 45,90,119,120,234,336,338,564,607,901

No need to shuffle the index values yet.
Thanks for the help.

I just don't have any indicators in my strategies. I am not familiar with buffers. As far as I understand the buffer is an element of an indicator.

 
ANDREY:

Thank you for your help.

Here is a simple code

In 10 minutes the array will be filled with price values with indexes from 0 to 9.
If you don't mind, please change the code so that the array is filled with the same values, but the indexes of this array are as follows: 45,90,119,120,234,336,338,564,607,901

No need to shuffle the index values yet.
Thanks for the help.

I just don't have any indicators in my strategies. I am not familiar with buffers. As far as I understand the buffer is an element of an indicator.

Index 901 means there are 902 elements in the array.
Mass[45]=Max[0].....Mass[901]=Max[9]
 
Valeriy Yastremskiy:
Index 901 means there are 902 elements in the array.
Mass[45]=Max[0].....Mass[901]=Max[9]

No ... There are 10 elements in the array. And these 10 indexes of these 10 elements must be denoted by these values in this sequence (0)45, (1) 90, (2) 119, (3) 120, (4) 234, (5) 336, (6) 338, (7) 564, (8) 607, (9) 901

In parentheses are the former index values. They should be replaced with new values without brackets.

of array elements can be indexed by any sequence of numbers, and not in the order 0,1,2,3,4........100

Документация по MQL5: Основы языка / Переменные
Документация по MQL5: Основы языка / Переменные
  • www.mql5.com
Переменные должны быть объявлены перед их использованием. Для идентификации переменных используются уникальные имена. Описания переменных используются для их определения и объявления типов. Описание не является оператором. Индексом массива может быть только целое число. Допускаются не более чем четырехмерные массивы. Нумерация элементов массива...
 
ANDREY:

No ... there are 10 elements in the array. And these 10 indexes of these 10 elements must be denoted by these values in this sequence (0)45, (1) 90, (2) 119, (3) 120, (4) 234, (5) 336, (6) 338, (7) 564, (8) 607, (9) 901

In brackets are the former values of the indices. They should be replaced with new values without brackets.


That is, I can index any number of elements in an array by an arbitrary sequence of numbers, not in the order 0,1,2,3,4........100

Anindex(lat.index means a list, registry, indexer, or index finger) is a number, letter, or other combination of symbols that indicates where an item is located in an array.

Index 45 indicates the 45th element in the list, index 90 indicates the 90th element.

 
ANDREY:

No ... there are 10 elements in the array. And these 10 indexes of these 10 elements must be denoted by these values in this sequence (0)45, (1) 90, (2) 119, (3) 120, (4) 234, (5) 336, (6) 338, (7) 564, (8) 607, (9) 901

In parentheses are the former index values. They should be replaced with new values without brackets.


That is, I can index any number of array elements by any sequence of numbers, and not in the order 0, 1, 2, 3, 4........100

I don't get it, the array index is an index from 0 to N. And what you want is more like a dictionary with hashes. I don't know how to do it in an array and I don't think you can do it in a regular array. There's a Generic class library with dictionaries in MT. That should help.

Библиотека Generic классов - ошибки, описание, вопросы, особенности использования и предложения
Библиотека Generic классов - ошибки, описание, вопросы, особенности использования и предложения
  • 2017.12.07
  • www.mql5.com
С 6 декабря 2017 года в стандартную поставку MetaTrader 5 стали входить так называемые Generic-классы, реализующие эффективные алгоритмы для хранен...
Reason: