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

 
Aleksei Stepanenko:
Do you want to sort the values in both lines or just the first line?

Only in the first one. There's an error in the code.

I'm sorry... I don't know how to delete the code. So I will just say that in block 2 instead of LoY[S2][0]=Bid; you need LoY[0][52]=Bid;

 

Why can't I swap rows and columns at once?

double LoY[31][2];
 

If you do the right order at once, can you name the numbers of the cells you want to fill with the value 0.5555?


 
Aleksei Stepanenko:

Why can't I swap rows and columns at once?

Then ArrayFill(LoY,0,10,0.5555); will not work. But it needs array elements in which it changes values to go *in sequence*. But if I feed it LoY[31][2]
, then the elements of the array where I want to change the value will go through 1. In this case, it will first "add" the 31 lines of the array into one line in order.

 
Aleksei Stepanenko:

If you want to do it in the right order, can you tell me the numbers of the cells you want to fill with 0.5555?


The first row contains cells one through ten. But once you've filled them with 0.5555, the whole first row has to be sorted... let's say in ascending order. ArrayFill(LoY,0,10,0.5555) instead of ArrayFill(LoY,0,10,0.5555) doesn't suit me.

I corrected the errors in the code

 

here's the script:

void OnStart()
   {
   int arr[31,2]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,
                  31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61};
   //до заполнения              
   string str="";
   for(int i=0; i<31; i++) for(int j=0; j<2; j++) str+=(string)arr[i,j]+", ";
   printf(str);
   //после заполнения
   str="";
   ArrayFill(arr, 0, 10, 555); 
   for(int i=0; i<31; i++) for(int j=0; j<2; j++) str+=(string)arr[i,j]+", ";
   printf(str);
   }

result:

2021.03.20 19:42:26.602 primer AUDUSD,H1: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 

2021.03.20 19:42:26.602 primer AUDUSD,H1: 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 

is it or isn't it?

 
Aleksei Stepanenko:

here's the script:

result:

Is it or isn't it?

Thank you very much. This looks like what I need. But I would appreciate it if you could put this code not as a script but into my code. This way I'll understand and assimilate new information faster. Only I have price values in the array instead of integers.

Thanks again for your help.

 
if you need to fill in differently, then instead of
ArrayFill()

use

for(int i=0; i<10; i++) arr[i,0]=555;
 
Aleksei Stepanenko:
If it needs to be filled in differently, then instead of

use

Ok. Today I hope to absorb some new information for me. And I'll let you know the results tomorrow.

Thanks again.

 
ANDREY:

code not as a script, but paste it into my code.

I didn't write anything else, I just repeated your code.

Visually the numbers are not arranged correctly (in two lines, instead of 31), and you thought that's what you need.

Most likely, you may have needed to assign 0.5555 to the loop instead of ArrayFill. Try it.

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

void OnTick()
{
//*************************************************** БЛОК 1
if (Minute()==20&&Minute()!=S1)
{
for(int i=0; i<10; i++) LoY[i,0]=0.555;
S1=Minute();
}
//*************************************************** БЛОК 2
if (Minute()!=S)
{
LoY[S2][0]=Bid;
ArraySort(LoY,WHOLE_ARRAY,0,MODE_ASCEND);
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();
}
}
Reason: