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

 

Can anyone suggest a scheme for how to get from an array like this

int array[15]= {0,0,5,5,5,1,9,9,9,0,2,2,1,0,0};

get the digits of which there are 3 or more in a row in the array, i.e. the values "5" and "9" fit

need to get the type of

value1=9;

value2=5;

or array value[]={9,5};

I have been puzzling with while do for two days now and can't figure out the scheme

 
Fast235:

can anyone suggest a scheme for how to get from an array like this

get the digits of which there are 3 or more in a row in the array, i.e. the values "5" and "9" fit

need to get the type of

value1=9;

value2=5;

or array value[]={9,5};

day two I can't figure out the while do scheme

sketched it out, but it solved it head-on, it works in general, but didn't like my solution:

//+------------------------------------------------------------------+
void OnStart()
{
   int array[15] = {0, 0, 5, 5, 5, 1, 9, 9, 9, 0, 2, 2, 1, 0, 0};
   int arrrepeat[];
   getRepeatNumbers(array, arrrepeat);
   ArrayPrint(arrrepeat);
}
//+------------------------------------------------------------------+
void getRepeatNumbers(const int &inArr[], int &result[])
{
   ArrayFree(result);
   for(int i = 0; i < ArraySize(inArr) - 1; i++)
   {
      if(getRepeatCount(inArr, i) > 1)
      {
         int sz = ArraySize(result);
         ArrayResize(result, sz + 1);
         result[sz] = inArr[i];
      }
   }
}
//+------------------------------------------------------------------+
int getRepeatCount(const int &arr[], const int pos)
{
   int result = 0;
   for(int i = pos + 1; i < ArraySize(arr) - 1 && arr[i] == arr[pos]; i++)
   {
      result++;
   }
   return(result);
}
//+------------------------------------------------------------------+

2020.09.10 11:51:26.323 tst (EURUSD,M5) 5 9

 
Igor Makanu:

sketched out, but decided head-on, works in general, but didn't like my solution:

2020.09.10 11:51:26.323 tst (EURUSD,M5) 5 9

Thanks, too much action

I would like to find a solution in the loop. I will try to use continue; and break; operators

it has to be taken from the indicator buffer at every new bar prev_calculate-100 approximately

 
Fast235:

Thanks, too much action

I would like to find a solution in the loop. I will try to use continue; and break; operators

it must be taken from the indicator buffer on each new bar prev_calculate-100 or so

it is not cumbersome, I did not like it as I did not look for other variants - I always do it that way

add the loop from the second function.... to the body of the first function there will be less bodily effort


whether withor without break - this problem will be solved in 2 loops anyway.... but it is not exact! - decide ;)

 
Igor Makanu:

not cumbersome, didn't like it because I didn't look for other options - I always do it this way

introduce the loop from the second function.... into the body of the first function there will be less bodily effort


whether withor without break - this problem will be solved in 2 loops anyway.... but it is not exact! - decide ;)

I'll try to mess around, I'll write if I get it

 
Fast235:

I'll give it a go and let you know if it works

It's all solved in one pass)))
 
Igor Makanu:

not cumbersome, didn't like it because I didn't look for other options - I always do it this way

introduce the loop from the second function.... into the body of the first function there will be less bodily effort


whether withor without break - this problem will be solved in 2 loops anyway.... but it is not exact! - decide ;)

error, if there will be four "9's" in the queue, instead of 3, the result will be

5 9 9 2


 
Fast235:

error, if there are four "9's" in the queue rather than 3, the result is

5 9 9 2


i told you i didn't like my solution (((

Too lazy to write again.

Google "array find repetitions" - I think you'll find something

 
Fast235:

can anyone suggest a scheme for how to get from an array like this

get the digits of which there are 3 or more in a row in the array, i.e. the values "5" and "9" fit

need to get the type of

value1=9;

value2=5;

or array value[]={9,5};

i can't figure out the scheme for the second day

int qty[10]; // счётчики по цифрам

int total; // всего элементов в исходном массиве arr[]

int code=arr[0]; // текущая цифра

int count=1; // кол-во повторов

for(int i=1;i<total;i++) {

if (arr[i]!=code) { if (count>qty[code]) qty[code]=count;  code=arr[i]; count=1;}

        else count++;

}

if (count>qty[code]) qty[code]=count; 

/// в массиве qty - требуемое

add additional checks about permissibility of elements arr[] (that they are digits) to taste

 

Good day everyone!
I am testing the algorithm in MT-4 tester using mql4. I need Print() function to output the Bid price in log with 5 (five) decimal places. But it would only print 4 (four) decimal places. I used NormalizeDouble(Bid,Digits) function to add the fifth digit.

Please tell me how to fix my mistake if it exists.
Here is my code.

void OnTick()
{
Print("=======Bid ======= ",NormalizeDouble(Bid,Digits) );

}


At the same time, if I print () the opening and closing price of an order ( by SL and TP), Print() prints the price with 5 (five) digits, even without the help of NormalizeDouble() and without the help of any other functions.
Thank you all for your help.