Why most Math Function doenst work in long doubles?!

 

since Spread removed from MQL5 and helpfile mentioned this method

double Spread=Ask-Bid;

but when i try to trim it from something like this

2020.02.07 22:05:02.297 Calling_Functions (EURUSD,M1) 2.999999999997449e-10

with NormalizeDouble it only return 

2020.02.07 22:05:06.829 Calling_Functions (EURUSD,M1) 0

i tried other Mathematical function same results

even turn it to INT doesnt help either


the only method is working turn it to string then return it standard int or less digits double


is it bugged or what?!

 
There is no such thing as a long double. A long is Long, a double is double, a long can not be a double. Study the concept data types.
 
Amirfakhredin Ghanbari:


2020.02.07 22:05:02.297 Calling_Functions (EURUSD,M1) 2.999999999997449e-10

with NormalizeDouble it only return 

2020.02.07 22:05:06.829 Calling_Functions (EURUSD,M1) 0


What are you trying to do here, 

please post your code here and use alt+s  


such that we see it like this 

 
Show all the relevant code if you need coding help.
 
Enrique Dangeroux:
There is no such thing as a long double. A long is Long, a double is double, a long can not be a double. Study the concept data types.

thank you for reply i meant long as large some of digits not long as data type

 
Alain Verleyen:
Show all the relevant code if you need coding help.

for some reason when i try this code

void OnTick()

  {

     double Ask=NormalizeDouble(SymbolInfoDouble(NULL,SYMBOL_ASK),_Digits);

     double Bid=NormalizeDouble(SymbolInfoDouble(NULL,SYMBOL_BID),_Digits);

     double Spread=Ask-Bid*_Point;

     Print(Spread);

     Print(NormalizeDouble(Spread,0));

  }

first print give me this

2020.02.07 22:05:02.297 Calling_Functions (EURUSD,M1) 2.999999999997449e-10

second line give me this

2020.02.07 22:05:06.829 Calling_Functions (EURUSD,M1) 0

 
double Spread=Ask-Bid*_Point;

Why are you doing this?

Maybe you mean

double Spread=(Ask-Bid)*_Point;

or maybe

double Spread=(Ask-Bid)/_Point;

or

double Spread=Ask-Bid;
 
Keith Watford:

Why are you doing this?

Maybe you mean

or maybe

or

ah i forgot the ()


tnX  something so easy yet forgot it :) 

Thank you

 
Amirfakhredin Ghanbari:

ah i forgot the ()


tnX  something so easy yet forgot it :) 

Thank you

So what was your intention?

If it was

double Spread=(Ask-Bid)*_Point;

Why multiply by Point?

 
Keith Watford:

So what was your intention?

If it was

Why multiply by Point?

I think this is what he was after:

int spread = SymbolInfoInteger(_Symbol,SYMBOL_SPREAD);
 
     Print(NormalizeDouble(Spread,0));
This will always result in zero. You used NormalizeDouble, It's use is usually wrong, as it is in your case.
  1. 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

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

  3. SL/TP (stops) need to be normalized to tick size (not Point.) (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 programming forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 programming forum
  4. Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on Metals. So do it right: Trailing Bar Entry EA - MQL4 programming forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 programming forum
  5. Lot size must also be adjusted to a multiple of LotStep and check against min and max. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
  6. MathRound() and NormalizeDouble() are rounding in a different way. Make it explicit.
              MT4:NormalizeDouble - General - MQL5 programming forum
              How to Normalize - Expert Advisors and Automated Trading - MQL5 programming forum
Reason: