Questions from Beginners MQL5 MT5 MetaTrader 5 - page 732

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
What if after sorting you change the indexing order using ArraySetAsSeries?
ArraySetAsSeries does not apply to multidimensional arrays.
Yes, it does not apply. And who knows what applies, please answer.
Yes, it does not apply. And who knows what applies, please answer.
Sometimes I use bubble sorting on a two-dimensional array. You can choose the direction and dimension by which to sort
Come to your house for the code, or post it, if you don't mind)
Added: How resource-consuming is it?, might as well invert the loop, which I don't want to do.
Come to your house for the code, or post it if you don't mind)
I just do not remember what dimension of the array you wrote - maybe you do not need it, and I'll shove ...
//| Пузырьковая сортировка двумерного массива |
//+------------------------------------------------------------------+
template<typename T>
void ArraySortBubbleTwoDims(T& array[][TWO_DIM], int sort_dimension=0, int sort_direction=0) {
T t=0;
int k=ArrayRange(array,1); // Количество колонок
int n=ArrayRange(array,0); // Количество строк
//---
if(sort_dimension<0) sort_dimension=0;
if(sort_dimension>k) sort_dimension=k;
//---
for(int i=n-1; i>0; i--) {
for(int j=0; j<i; j++) {
//--- по возрастанию
if(sort_direction==0) {
if(array[j][sort_dimension]>array[j+1][sort_dimension]) {
for(int e=0; e<k; e++) {
t=array[j][e];
array[j][e]=array[j+1][e];
array[j+1][e]=t;
}
}
}
//--- по убыванию
else {
if(array[j][sort_dimension]<array[j+1][sort_dimension]) {
for(int e=0; e<k; e++) {
t=array[j][e];
array[j][e]=array[j+1][e];
array[j+1][e]=t;
}
}
}
}
}
}
//+------------------------------------------------------------------+
Well, grab a beer and come visit ;)
I just do not remember what dimension of the array you wrote - maybe you don't need it, and I'll put it here ...
It's winter, but the skis won't go
{
double m[][3];
if(условия)
{
// много кода
c++;
ArrayResize(m, c);
m[c-1][0]= Lots();
m[c-1][1]= Ticket();
m[c-1][2]= Profit();
}
BySort(m); // передаём в функцию "BySort"
}
void BySort(double &mas[][3])
{
// Сортируем по размеру лота от большего к меньшему
ArraySort(mas);
ArraySetAsSeries(mas,true); // при такой записи mql5 ругается, в mql4 работает
... здесь работа с уже сортированным массивом и основной код
}
Error: "'m' - parameter conversion not allowed e.mq5 2076 20"
It's winter, but the skis won't go
{
double m[][3];
if(условия)
{
// много кода
c++;
ArrayResize(m, c);
m[c-1][0]= Lots();
m[c-1][1]= Ticket();
m[c-1][2]= Profit();
}
BySort(m); // передаём в функцию "BySort"
}
void BySort(double &mas[][3])
{
// Сортируем по размеру лота от большего к меньшему
ArraySort(mas);
ArraySetAsSeries(mas,true); // при такой записи mql5 ругается, в mql4 работает
... здесь работа с уже сортированным массивом и основной код
}
Error: "'m' - parameter conversion not allowed e.mq5 2076 20"
Note
The AS_SERIES flag cannot be set for multidimensional arrays and for static arrays (i.e., arrays whose size in square brackets is already specified at compile time).
And what prevents you from sorting it with the function I suggest?
It's written in the help:
Note
The AS_SERIES flag cannot be set for multidimensional arrays and static arrays (i.e. arrays whose size in square brackets is specified at compile time).
But what prevents you from sorting it out using the function I suggest?
Exactly the same error when transferring to a function
Which one?
To your"ArraySortBubbleTwoDims".
Anyway, I've expanded the loop and the issue is solved. But I'd still like to see a normal solution in the form of a standard function