Order Lotage

 
Hello Friends, 

I'm surprised by one thing 

I use this code: 

double   min_lot     = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN);
double   max_lot     = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MAX);
int      lotdigits   = (int) - MathLog(SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP));
double   lots        = NormalizeDouble(_lotcalculation, lotdigits);

when my order lots is 0.07 (Only this number!!) i get Print from lots and it is 0.070000000001 

My order open with 0.07 but when I get and Print  order lotage by 

OrderGetDouble(ORDER_VOLUME_INITIAL)   

I see lotage is 0.070000000001 . 

Please not that it accord only for 0.07 lots!!

Do you have any Idea about this ?

 

Unbelievable!!! 

The result of this code is 0.0700000000001


string lottDD;
void OnTick(void)
  {
  lottDD=StringToDouble(0.07);
   Print(lottDD);
  }
 
prg_mt4:
Hello Friends, 

I'm surprised by one thing 

I use this code: 

when my order lots is 0.07 (Only this number!!) i get Print from lots and it is 0.070000000001 

My order open with 0.07 but when I get and Print  order lotage by 

I see lotage is 0.070000000001 . 

Please not that it accord only for 0.07 lots!!

Do you have any Idea about this ?

Floating point numbers aren't 100% accurate and 0.07 doesn't have an exact representation in floating point.

 
prg_mt4: I see lotage is 0.070000000001 . 
prg_mt4: The result of this code is 0.0700000000001


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/10.)
          Double-precision floating-point format - Wikipedia, the free encyclopedia

See also The == operand. - MQL4 programming forum

Print out your values to the precision you want with DoubleToString - Conversion Functions - MQL4 Reference.

 
William Roeder:

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/10.)
          Double-precision floating-point format - Wikipedia, the free encyclopedia

See also The == operand. - MQL4 programming forum

Print out your values to the precision you want with DoubleToString - Conversion Functions - MQL4 Reference.

Thank you for your answer 

I used  MathFloor(x/lotStep)*lotStep

but result is 0.0700000001

Actually I don't know how can I create 0.07 

this is very bad problem for me . EA close my order immediately because my order lotage is more than acceptable risk management .

Could you exactly tel me how can I make 0.07 lotage in my code 

Thank you very very much 

 

What part of "some numbers can't be represented exactly" was unclear?

If you loose the extra $0.000000000001 is that unacceptable?

 
William Roeder:

What part of "some numbers can't be represented exactly" was unclear?

If you loose the extra $0.000000000001 is that unacceptable?

Hello Williams 

this issue solved with this formula :

if(P_lots-Lots_F[sd_1]>-0.0000001) {close all positions}

It's Ok now . 

Thank you for your help 👍👍

 
William Roeder:

What part of "some numbers can't be represented exactly" was unclear?

If you loose the extra $0.000000000001 is that unacceptable?

Dear william, can you answer to my question in this page ?

https://www.mql5.com/en/forum/323372

font size in deferment laptops!
font size in deferment laptops!
  • 2019.09.30
  • www.mql5.com
Hello I have a problem with fonts size in EA, font size in my PC is OK (Left photo) but in my friend's PC is very big(Right photo), My another frie...
 

Do not use the NormalizeDouble function to calculate lots

double volumeStep = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP);
double lot = round(_lotcalculation / volumeStep) * volumeStep;

This option will work correctly

Reason: