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

 
Andrey Sokolov #:

Thank you.

It turns out that there are different functions with the same name, but youcan't make it possible to pass a different number of parameters?

It can, but it is less than the parameters, the example button has many parameters, but
//+------------------------------------------------------------------+ 
//| Создает кнопку                                                   | 
//+------------------------------------------------------------------+ 
bool ButtonCreate(const long              chart_ID=0,               // ID графика 
                  const string            name="Button",            // имя кнопки 
                  const int               sub_window=0,             // номер подокна 
                  const int               x=0,                      // координата по оси X 
                  const int               y=0,                      // координата по оси Y 
                  const int               width=50,                 // ширина кнопки 
                  const int               height=18,                // высота кнопки 
                  const ENUM_BASE_CORNER  corner=CORNER_LEFT_UPPER, // угол графика для привязки 
                  const string            text="Button",            // текст 
                  const string            font="Arial",             // шрифт 
                  const int               font_size=10,             // размер шрифта 
                  const color             clr=clrBlack,             // цвет текста 
                  const color             back_clr=C'236,233,216',  // цвет фона 
                  const color             border_clr=clrNONE,       // цвет границы 
                  const bool              state=false,              // нажата/отжата 
                  const bool              back=false,               // на заднем плане 
                  const bool              selection=false,          // выделить для перемещений 
                  const bool              hidden=true,              // скрыт в списке объектов 
                  const long              z_order=0)                // приоритет на нажатие мышью 

It will draw even with a minimum of parameters

ButtonCreate(0,InpName,0,x,y,x_size,y_size,InpCorner);
 
Andrey Sokolov #:

Greetings. Could you please tell me if and how it is possible to do this?

Is it possible to write your functions so that you can pass different number of parameters to written functions?

How, for example, in this function, you can pass 4 or 5 parameters.


/********************Script program start function*******************/
void OnStart()
 {
  double a = 2.87,
         b = 3.62,
         c = 0;
  Print("Fu(a, b) ", Fu(a, b));
  Fu(a, b, c);
  Print("Fu(a, b, c) ", c);
 }/******************************************************************/
double Fu(double x, double y)
 {
  return x*y;
 }/******************************************************************/
void Fu(double x, double y, double & z)
 {
  z = x+y;
 }/******************************************************************/
/*****************************End program****************************/

The result is

2021.11.15 00:01:54.629 00 USDJPY,M15: Fu(a, b, c) 6.49
2021.11.15 00:01:54.629 00 USDJPY,M15: Fu(a, b) 10.3894
 

Please help, I can't figure out what the error is

   for(i=limit;i>=0;i--)
     {
      if(up)
        {
         if(Label1Buffer[i+1]<Input1){a+=1;}
         else {up=false;}
        }
      if(!up)
        {
         if(Label1Buffer[i+1]>0){a-=1;}
         else {up=true;}
        }
      Label1Buffer[i]=a;

I wanted a uniform wave, but for some reason "0" goes twice


 

Why doesNormalizeDouble sometimes not work?

When I print an array to the log, almost all double values are printed to the specified 1 decimal place, and some 3-4 values (out of a hundred) with 15 digits.

...

2021.11.15 04:01:07.821Sov2EURUSD,M1: 9.9
2021.11.15 04:01:07.724 Sov2 EURUSD,M1: 9.800000000000001
2021.11.15 04:01:07.675 Sov2 EURUSD,M1: 9.9
2021.11.15 04:01:07.626 Sov2 EURUSD,M1: 9.6
2021.11.15 04:01:07.577 Sov2 EURUSD,M1: 9.1

...

 
MakarFX #:

Please help, I can't figure out what the error is

Wanted a uniform wave, but for some reason "0" goes twice


because the conditions are confusing, on one iteration of the loop you should only have the up flag in one state, and you can have true and in the same iteration of the loop become false

I would write it that way in general:

   int y = 0, shift = 1;
   const int max_value = 100;
   const int min_value = 0;
   for(int i = rates_total - 1; i >= 0; i--)
   {
      Label1Buffer[i] = y; 
      y += shift;
      if(y >= max_value || y <= min_value) shift *= -1;
   }
 
Igor Makanu #:

because the conditions are confusing, on one iteration of the loop you should only have the up flag in one state, but you can have true and in the same iteration of the loop become false

I would write it that way in general:

Thank you, Igor, very much.
 

Can you tell me how to do it correctly

   for(i=limit;i>=0;i--)
     {
      Label1Buffer[i] = MathRand(); 
      Label2Buffer[i] = Label1Buffer[i+1]+Label1Buffer[i+2]+Label1Buffer[i+3]+Label1Buffer[i+4]+Label1Buffer[i+5]; 
     }

not to enter all elements that I want to add up, but just specify 5 elements

 
Sergey Zhukov #:

If you rename it to *.mq4, everything is fine.

If you compile it that way, you get errors.

I have no errors


 
 
MakarFX #:

I have no errors.


Mine looks like this:

e

Anyway, it's not critical. Thanks for your help.