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

 
Hello, could you please tell me how I can programmatically understand that the price has approached a circular level?
 
profitnik:
Hello, could you please tell me how to programmatically understand that the price has approached a circular level?
Normalize the price to the required number of decimal places, NormalizeDouble().
 

Can you tell me how to correctly return multiple values from a function?

Let's say I have an ABC function - I want to get the values of three variables at once, how do I do this?


int ABC()
  {
   int A=1;
   int B=1;
   int C=1;

  return (A,B,C)
 }
 
-Aleks-:

Can you tell me how to correctly return multiple values from a function?

Let's say I have an ABC function - I want to get the values of three variables at once, how do I do this?

//int a, b, c;

OnTick()
 {
 //int a, b, c;
 ABC(a, b, c);
 Print(a," | ", b," | ", c);
 }

void ABC(int &A,int &B,int &C)
  {
   A=1;
   B=1;
   C=1;
 }
Like this
 
Vitaly Muzichenko:
I think so.

Thank you.

But I don't get it, if my input is 2 variables for calculation, and output should be 3 (with different int and double types ), what should I do?

 
-Aleks-:

Thank you.

But I don't know, if my input is 2 variables for calculation, but the output should be 3 (with different int and double types ), what should I do?


OnTick()
 {
   double x,y,c;

   int    q=5;
   double w=0.1;
   ABC(q,w);

   Print(x," | ", y," | ", c);
 }

void ABC(int A,double B)
  {
   x=A+B;
   y=A-B;
   c=A*B;
  }
 
-Aleks-:

Thank you.

But I don't know, if my input is 2 variables for calculation, but the output should be 3 (with different int and double types ), what should I do?

int a, b;
double c;

OnTick()
 {
 a=11; b=3;
 ABC(a, b, c);
 Print(a," | ",b," | ",c);
 }

void ABC(int &A,int &B,double &C)
  {
   A=B+4;
   B=A-2;
   C=(double)A/B;
 }
 

I apologise for the obtuseness, but I'd rather use my example to understand how to organise this - there is a function that is called many times in code in different places - now it returns one value, but I also need, say, 2 _High and _Low - how should this be done?


int BarPeresek_iMAf(int PeriodMA)
  {
   int TFT=0;
   int shiftMAT=0;
   int typeMAT=0;
   int priceMAT=0;
   int BarPeresek=0;
   if(Bars>PeriodMA)
     {
      for(int X=1;X<1000; X++)
        {
         double MAT=NormalizeDouble(iMA(Symbol(),TFT,PeriodMA,shiftMAT,typeMAT,priceMAT,X),Digits);
         if((Low[X]>MAT && High[X]>MAT) || 
            (Low[X]<MAT && High[X]<MAT))BarPeresek++;
         else {BarPeresek++; break;}
        }

     }
   double _High=High[BarPeresek]; //Надо получить сразу из функции
   double _Low=Low[BarPeresek];   //Надо получить сразу из функции
   return BarPeresek;
  }
 
-Aleks-:

I apologise for the obtuseness, but I'd rather use my example to understand how to organise it - there's a function which is called many times in code in different places - now it returns one value, but I also need, say, 2 _High and _Low - how should this be done?



OnTick()
{
   double _High=High[BarPeresek_iMAf(Per_MA)];
   double _Low=Low[BarPeresek_iMAf(Per_MA)];
} 

int BarPeresek_iMAf(int PeriodMA)
  {
   int TFT=0;
   int shiftMAT=0;
   int typeMAT=0;
   int priceMAT=0;
   int BarPeresek=0;
   if(Bars>PeriodMA)
     {
      for(int X=1;X<1000; X++)
        {
         double MAT=NormalizeDouble(iMA(Symbol(),TFT,PeriodMA,shiftMAT,typeMAT,priceMAT,X),Digits);
         if((Low[X]>MAT && High[X]>MAT) || 
            (Low[X]<MAT && High[X]<MAT))BarPeresek++;
         else {BarPeresek++; break;}
        }
     }
   return BarPeresek;
  }

 
Nikolay Gaylis:

No, I need to get the value from the function - _High and _Low is just an example...
Reason: