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

 
Taras Slobodyanik:

the comment format may vary from broker to broker.

I have not seen the absence of "To" and "From"
 
Artyom Trishkin:
Didn't see the absence of "To" and "From"
Artem, look up my question above....
 

Good day to you all!

Can you please tell me if there is a function in MQL4 (or in MQL5, but working in MQL4) that converts array LoY[2][7] into array LoY[7][2] and vice versa. Something like transposition. Below is a sample of transformation I need. I want to have exactly the function. I already know how to convert an array in a loop.

Thank you for your help.

 
ANDREY:

Good day to you all!

Can you please tell me if there is a function in MQL4 (or in MQL5, but working in MQL4) that converts array LoY[2][7] into array LoY[7][2] and vice versa. Something like transposition. Below is a sample of transformation I need.

Thanks for your help.

Just for reference : in classic algorithms (IT in general) such operation is called zip,

I can't find such a function in the library. It is terribly wasteful and inefficient. It is easier and faster to change indexes in the algorithm/program or use indirect accesses than to rearrange ALL data in arrays.

 
Maxim Kuznetsov:

It is easier and faster to change indexes in the algorithm/program or use indirect accesses than to rearrange ALL the data in the arrays.

Thank you very much for your reply. Unfortunately, I'm not as advanced in programming as you are. I would be very grateful to you if you could write some mql4 code that changes array indices to solve my problem. And if you give an example of indirect reference, I will be doubly grateful.

I will understand your thought process more accurately and learn something new and useful to me thanks to you.

 
ANDREY:

Thank you very much for your reply. Unfortunately, I'm not as advanced in programming as you are. I would be very grateful to you if you could write some mql4 code to change array indices to solve my problem. And if you give an example of indirect reference, I will be doubly grateful.

I will understand your thought process more accurately and learn something new and useful to me thanks to you.

void Convert_7x2_2x7 (const double &src[7][2],double &dst[2][7]) {

   for(int i=0;i<7;i++)

   for(int j=0;j<2;j++) {

dst[j][i]=src[i][j];

   }

}

It's short, but it's the worst thing you can do :-) two nested loops and element-by-element copying of arrays.

When you inside your algorithm you can just rename the indexes. Just change i to j in your code and vice versa...

 
Maxim Kuznetsov:

void Convert_7x2_2x7 (const double &src[7][2],double &dst[2][7]) {

   for(int i=0;i<7;i++)

   for(int j=0;j<2;j++) {

dst[j][i]=src[i][j];

   }

}

short, but it's the worst thing you can do :-)

Thank you very much. And an example of the best??? :-).... so that I have a full understanding.

Element-by-element copying is long and energy consuming...especially for large arrays...... if I'm not mistaken.

 
Andrei, why would you want to do that? If the data is already collected in an array, you can find a way to just use it as it is without moving anything. Or preassemble them into an array in the right order. What do you want to get?
 
Aleksei Stepanenko:
Andrei, why do you need it? If the data is already collected in an array, you can find a way to just use it as it is without moving anything. Or you can assemble them into an array in the right order beforehand. What do you want to get?

Here is my simple code to illustrate what I need.

double LoY[2][31],LoU,LoU1;
int S,S1,S2;

void OnTick()
{
//*************************************************** БЛОК 1
if (Minute()==20&&Minute()!=S1)
{
ArrayFill(LoY,0,10,0.5555);

S1=Minute();
}
//*************************************************** БЛОК 2
if (Minute()!=S)
{
LoY[0][S2]=Bid;
ArraySort(LoY,WHOLE_ARRAY,0,MODE_ASCEND);
Print("----LoY[0][1]-- Г ---  [0]  ",  LoY[0][0],"  [1] ",   LoY[0][1],"  [2] ",   LoY[0][2],"  [3] ",   LoY[0][3],"  [4] ",   LoY[0][4],"  [26] ",   LoY[0][26],"  [27] ",   LoY[0][27],"  [28] ",   LoY[0][28],"  [30] ",   LoY[0][30],"  [60] ",   LoY[0][60]);
Print("----LoY[1][0]-- В ---  [0]  ",  LoY[0][0],"  [1] ",   LoY[1][0],"  [2] ",   LoY[2][0],"  [3] ",   LoY[3][0],"  [4] ",   LoY[4][0],"  [26] ",   LoY[26][0],"  [27] ",   LoY[27][0],"  [28] ",   LoY[28][0],"  [30] ",   LoY[30][0],"  [60] ",   LoY[60][0]);
S2++;
if (S2==62)
{
S2=0;
}
S=Minute();
}
}

In block 1, ArrayFill(LoY,0,10,0.5555) runs and assigns the first 10 elements of the array the value 0.5555. After that, I need to sort the entire null row from column 0 to column 31.

I want to sort it in block 2, using ArraySort(LoY,WHOLE_ARRAY,0,MODE_ASCEND); But I can't sort it because this function sorts a two-dimensional array by its first dimension, i.e. by rows. And I have a string to sort only 1. ArraySort() on the second dimension, ie, the columns does not sort two-dimensional arrays (only one-dimensional).

So I thought, maybe I should convert LoY[2][31] after first block to LoY[31][2], so ArraySort() could sort the values I need in block 2. And I need to sort all values from zero row after ArrayFil() changed first 10 of them.

Can I sort two-dimensional arrays by the second dimension, i.e. by columns, using some other function, or something else?
Sorry... I don't know how to delete the code. So i will just say that there is an error in line 180 instead of LoY[S2][0]=Bid; we need LoY[0][52]=Bid;

Thanks for your help.

 
Do you want to sort the values in both rows or just the first?
Reason: