# Coding for FIFO Rule 11

Hi, I'M not very skilled in MQL4, and havig problems with the lot size in my EA, where souldn't be to orders open with the same Lot Size at the same time. I made a For loop that finds if there's an open order with the same Lot Size as the intended one, and if its true, adds 0.01 to the lot size, but works ok for the first 3 orders opened, and then repeats the values. Could somebody tell me where the error is?

Thanks a lot!

Gustavo

``` double LotSize_Buy()

{
double Equity= AccountEquity();
double RiskedAmount=Equity*RiskedPercent*0.01;

for(int b=0;b<OrdersTotal();b++)
{
&& OrderMagicNumber()==MagicNumber
&& OrderSymbol()==Symbol())

if(OrderLots()==Intended_LotSize)
{
Intended_LotSize+=0.01;
b=-1;
}

}
return (Intended_LotSize);``` 20233

gbiaggi: Could somebody tell me where the error is?
1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Messages Editor

2. Your question/problem has nothing to do with FIFO.

3. Floating point has infinite number of decimals, it's your not understanding floating point and that some numbers can't be represented exactly. (like 1/100.)
Double-precision floating-point format - Wikipedia, the free encyclopedia

4. 0.01 + 0.01 + 0.01… does not equal 0.0n. Drop your b=-1; Find the largest OrderLots. Then return your next size (0.01 more.) 11

gbiaggi:

Hi, I'M not very skilled in MQL4, and havig problems with the lot size in my EA, where souldn't be to orders open with the same Lot Size at the same time. I made a For loop that finds if there's an open order with the same Lot Size as the intended one, and if its true, adds 0.01 to the lot size, but works ok for the first 3 orders opened, and then repeats the values. Could somebody tell me where the error is?

Thanks a lot!

Gustavo

Thanks William! Now I Know how to paste the code so it looks like MQL4....

So You can't compare two numbers to find if they are equal, even if you NormalizeDouble () both to same digits after 0?

I didn't want to add 0.01 to the largest, because I wouldn't need to if there's no need to. For example, if the largest lot size open is 0.37, and the intended lot size is 0.75, I would've end up with a Lot Size of 0.38 instead of 0.75....

Thanks again,

Gustavo 11

gbiaggi:

Thanks William! Now I Know how to paste the code so it looks like MQL4....

So You can't compare two numbers to find if they are equal, even if you NormalizeDouble () both to same digits after 0?

I didn't want to add 0.01 to the largest, because I wouldn't need to if there's no need to. For example, if the largest lot size open is 0.37, and the intended lot size is 0.75, I would've end up with a Lot Size of 0.38 instead of 0.75....

Thanks again,

Gustavo

Hi, I finally corrected it, as the problem was comparing two floating points, that they look equal but are different by several digits after the comma, instead of comparing them, I asked if the difference between them is less than 0.001, then they are equal, and is working perfect.

Every day I leran a little bit more!

Thanks

Gustavo