//+----------------------------------------------------------------------------+//| Автор : Ким Игорь В. 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.
//+----------------------------------------------------------------------------+//| Автор : Ким Игорь В. 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
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
for some reason the terminal does not show errors)
Can't you do it yourself?
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?
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.
Try this one.
what difference does the lot pitch make more than zero or less.
Artem, why don't you just forget them?
go to sleep.
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?
When I read your posts on the forum, I think "this man has a weak brain".
Try this one.
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