**desert:**

Hello,

In my code I use this sentence:

LotValue = NormalizeDouble(LotValue, LotDecimalPlaces);

I use . . .

LotValue = NormalizeDouble(LotValue, Digits);

17360

Hello,

In my code I use this sentence:

LotValue = NormalizeDouble(LotValue, LotDecimalPlaces);

I use . . .

LotValue = NormalizeDouble(LotValue, Digits);

220

I use . . .

LotValue = NormalizeDouble(LotValue, Digits);

Thanks for your answer, but in my humble opinion it is not correct at all, Digits has the number of decimal places in the price value (2 or 3, 4 or 5), these decimal places do not apply for the lot value. I could be wrong maybe.

Regards

24607

`LotValue = NormalizeDouble(LotValue, LotDecimalPlaces); `

This is WRONG. Depending on LDP (0, 1, 2) it assumes a lotstep is 1.0, 0.1, or 0.01. Any other BROKER DEFINED lotstep (like 0.05) can not be done by this code. Just do it right:double lotStep = MarketInfo(Symbol(), MODE_LOTSTEP), //IBFX= 0.01 minLot = MarketInfo(Symbol(), MODE_MINLOT ); //IBFX= 0.10 lotValue=MathCeil(lotValue/lotStep)*lotStep; if (lotValue < minLot) ...

220

This is WRONG. Depending on LDP (0, 1, 2) it assumes a lotstep is 1.0, 0.1, or 0.01. Any other BROKER DEFINED lotstep (like 0.05) can not be done by this code. Just do it right:

Hello, thank you for the advise.

The issue with MathCeil is the following:

if Lot = 0.833333, after MathCeil it is 0.9 (Step 0.1)

if Lot = 0.866666, after MathCeil it is 0.9 (Step 0.1)

However, if I use Lot = NormalizeDouble(Lot,1), the rounding I got is more exact:

if Lot = 0.833333, after NormalizeDouble(Lot,1)it is 0.8 (Step 0.1)

if Lot = 0.866666, after NormalizeDouble(Lot,1)it is 0.9 (Step 0.1)

See the difference? So, the issue I have is detecting the number of decimal places in the lot value, for that is what I thought to use the decimal places of the step value, could please tell me why this is wrong?

Thanks again.

6

I'm newbie in this, but I think you can use MathCeil, or MathFloor or MathRound depend on what you expect.
ex: MathCeill(1.05) = 2 MathCeil(1.95) = 2 -------> UP
MathFloor(1.05) = 1 MathFloor(1.95) = 1 ---------> DOWN
MathRound(1.05) = 1 MathRound(1.95) = 2 I think you can use this one.
Hope can help.

17360

Does this work . . .

MathAbs((lots +( 0.5 *lotstep))/lotstep) *lotstep

it rounds up/down to the nearest lotstep . . . I think. Looks like it works for a lotstep of 0.05 too

24607

MathAbs will not work, you need truncation to an int before the *lotstep. int i=(lots+lotstep/2)/lotstep; lots=i*lotstep;

I think you're splitting hairs with the mathCeil, (1.12 vs 1.13 lots) but mathRound will work just as well.

17360

MathAbs will not work, you need truncation to an int before the *lotstep. int i=(lots+lotstep/2)/lotstep; lots=i*lotstep;

I think you're splitting hairs with the mathCeil, (1.12 vs 1.13 lots) but mathRound will work just as well.

220

7

I know this is an old question.

Not sure if any drawbacks from a trading perspective...

MQL4:

int getDecimalPlaces(double number) {

string decimalPlaces[] = {0};

StringSplit(number,46,decimalPlaces);

if (ArraySize(decimalPlaces) == 2) {

return StringLen(decimalPlaces[1]);

}

return 0;

}

getDecimalPlaces(MarketInfo(NULL,MODE_MINLOT));

You are missing trading opportunities:

- Free trading apps
- Free Forex VPS for 24 hours
- Over 8,000 signals for copying
- Economic news for exploring financial markets

Registration
Log in

You agree to website policy and terms of use

If you do not have an account, please register

Hello,

In my code I use this sentence:

LotValue = NormalizeDouble(LotValue, LotDecimalPlaces);

Question is:

How to know the right value for variable LotDecimalPlaces? I mean in an automatic way inside of the EA.

I thought that value could be equal to the decimal places of the Step (MODE_LOTSTEP), for example:

Step: 0.01 -> LotDecimalPlaces: 2

Step: 0.05 -> LotDecimalPlaces: 2

Step: 0.1 -> LotDecimalPlaces: 1

Step: 1.0 -> LotDecimalPlaces: 0

So the routine would be:

if (Step < 0.1) then LotDecimalPlaces: 2

if (Step >= 0.1 and Step < 1) then LotDecimalPlaces: 1

if (Step >= 1) then LotDecimalPlaces: 0

Do you see any problem to this?

Thanks in advance!