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

 
multiplicator:
for some reason the terminal does not show errors)

Can't you do it yourself?

 
multiplicator:
For some reason the terminal does not show errors)

What does the terminal have to do with it? You have to take volume grading into account in your program.

Try to programmatically send an order to open a position with lot 0.000001, or 0.12345678, or 100000.1, etc.

 
Алексей Тарабанов:

Can't you do it yourself?

What? It doesn't show.
 
Artyom Trishkin:


Try sending a programmed order to open a position with lot 0.12345678

opens with lot 0.12.

The question is whether to normalise or not to normalise.

 
Artem, why don't you just forget them?
 
Alekseu Fedotov:

Try this one.

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 16.05.2008                                                     |
//|  Описание : Возвращает нормализованное значение торгуемого лота.           |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    lo - нормализуемое значение лота.                                       |
//|    ro - способ округления          (   False    - в меньшую,               |
//|                                        True     - в большую сторону)       |
//|    sy - наименование инструмента   ("" или NULL - текущий символ)          |
//+----------------------------------------------------------------------------+
double NormalizeLot(double lo, bool ro=False, string sy="") {
  double l, k;
  if (sy=="" || sy=="0") sy=Symbol();
  double ls=MarketInfo(sy, MODE_LOTSTEP);
  double ml=MarketInfo(sy, MODE_MINLOT);
  double mx=MarketInfo(sy, MODE_MAXLOT);

  if (ml==0) ml=0.1;
  if (mx==0) mx=100;

  if (ls>0) k=1/ls; else k=1/ml;
  if (ro) l=MathCeil(lo*k)/k; else l=MathFloor(lo*k)/k;

  if (l<ml) l=ml;
  if (l>mx) l=mx;

  return(l);
}


This is where it's not clear:
  if (ls>0) k=1/ls; else k=1/ml;
what difference does the lot pitch make more than zero or less.
 
Алексей Тарабанов:
Artem, why don't you just forget them?
Fuck you.
go to sleep.
 
multiplicator:

opens with a lot of 0.12.

The question is to normalize or not to normalize.

I'm sick of it. What's the lot got to do with the price at which he opened, you patient?

 
Алексей Тарабанов:

I'm sick of it. What's the lot got to do with the price you opened it at, you patient?

Old man, nobody asked you anything. Go to sleep.

When I read your posts on the forum, I think "this man has a weak brain".
 
Alekseu Fedotov:

Try this one.

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 16.05.2008                                                     |
//|  Описание : Возвращает нормализованное значение торгуемого лота.           |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    lo - нормализуемое значение лота.                                       |
//|    ro - способ округления          (   False    - в меньшую,               |
//|                                        True     - в большую сторону)       |
//|    sy - наименование инструмента   ("" или NULL - текущий символ)          |
//+----------------------------------------------------------------------------+
double NormalizeLot(double lo, bool ro=False, string sy="") {
  double l, k;
  if (sy=="" || sy=="0") sy=Symbol();
  double ls=MarketInfo(sy, MODE_LOTSTEP);
  double ml=MarketInfo(sy, MODE_MINLOT);
  double mx=MarketInfo(sy, MODE_MAXLOT);

  if (ml==0) ml=0.1;
  if (mx==0) mx=100;

  if (ls>0) k=1/ls; else k=1/ml;
  if (ro) l=MathCeil(lo*k)/k; else l=MathFloor(lo*k)/k;

  if (l<ml) l=ml;
  if (l>mx) l=mx;

  return(l);
}

It here divides by lot step size, discards the remainder, then takes how many of these lot steps it got.

There might be a mistake here.

For example, we put the value in the function: 7 lots.
The broker has a minimum lot volume of 5 and a lot step of 2.


He will divide 7 by the lot increment. He will take the number of whole parts. And multiply again by the lot increment. The result will be 6 lots. And he will try to open an order with this volume.
But the order can be opened only with such volumes as 5, 7, 9, etc.


It would be better to subtract the minimum lot size (5) from our lot (7). And with the remainder to work.

perform all actions with the remainder, that it has a function.

Count how many whole steps are there, the size of the lot step. Then multiply the number of steps by the lot step size. This gives us 2.

Then this 2 is again added to the size of the minimum lot (5). the result is 5+2=7.


But this is a fantastic example.
Brokers now have a min lot and lot increments of 0.01
or min lot and lot increments of 0.1