Math and Lotsize - page 2

 
NormalizeDouble, It's use is usually wrong,
  1. Floating point has a 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 2013.06.07

  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) — code fails on non-currencies. (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 non-currencies. 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 - MQL5 programming forum
              How to Normalize - Expert Advisors and Automated Trading - MQL5 programming forum

  7. Prices you get from the terminal are already normalized.

  8. PIP, Point, or Tick are all different in general.
              What is a TICK? - MQL4 programming forum 2014.08.03

 
Fernando Carreiro:

I make it a point in my code to NEVER use NormaliseDouble(), EVER. If you search the forum you will find that this has been debated many, many times in a very heated way. Some in favour of using it and a few like myself, against using it.

I will leave it up to you to decide for yourself what you prefer doing.

Suffice to say, that by using the calculations I have shared above, I've have never had any problems or any errors about invalid volume when placing an order.

yes, i am very aware of the mentioned "debate" haha, hence the confusion of when to use it, and "tug-o-war" of "if" to use it :D

i dont get invalid volume errors, just the weird numbers, even before the order is sent. The ea sends a different lotsize that my common sense math comes up with.

 
Revo Trades: yes, i am very aware of the mentioned "debate" haha, hence the confusion of when to use it, and "tug-o-war" of "if" to use it :D. i dont get invalid volume errors, just the weird numbers, even before the order is sent. The ea sends a different lotsize that my common sense math comes up with.
Maybe there is a coding logic flaw somewhere in your complete code that is causing the issue.
 
William Roeder:
NormalizeDouble, It's use is usually wrong,
  1. Floating point has a 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 2013.06.07

  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) — code fails on non-currencies. (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 non-currencies. 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 - MQL5 programming forum
              How to Normalize - Expert Advisors and Automated Trading - MQL5 programming forum

  7. Prices you get from the terminal are already normalized.

  8. PIP, Point, or Tick are all different in general.
              What is a TICK? - MQL4 programming forum 2014.08.03

Thanks for the readings. I read over the first ones in previous msg, and i come up with the belief that lead me to think the same is stated in your no.6

As for no.5 i was already doing that, so I believe my issue is not related to that no.5.
Will read the readings soon. Thanks.

 
Fernando Carreiro:
Maybe there is a coding logic flaw somewhere in your complete code that is causing the issue.

can only hope that todays test will fix the issue, however, if turns out not, then i will post the full code here for perusal. only reason i have not done so is that I am still hoping that it is as simple as removing normalize from that lotsize calculation. here's to hoping haha!

 

Use the function Repr() to get around MQL Print() issues. (double to string conversion errors).

Print(Repr(lotsize));

Repr() can be found in Math Utils library. https://www.mql5.com/en/code/20822

You can also use this floating-point converter https://baseconvert.com/ieee-754-floating-point to get the exact decimal value of doubles. 

A double number is stored as the binary approximations (base 2) of the exact decimal value. Most of decimal numbers are not exact for example

Print(0.07);


 

Math Utils
Math Utils
  • www.mql5.com
Handy functions for comparison, rounding, formatting and debugging of doubles (prices, lots and money).
 
amrali:

Use the function Repr() to get around MQL Print() issues. (double to string conversion errors).

Repr() can be found in Math Utils library. https://www.mql5.com/en/code/20822

You can also use this floating-point converter https://baseconvert.com/ieee-754-floating-point to get the exact decimal value of doubles. 

A double number is stored as the binary approximations (base 2) of the exact decimal value. Most of decimal numbers are not exact for example


 

nice. thanks for those. I have noted them on bookmark, however, as i said in previous comment i was already printing out my lotsize before the order was being sent. Thanks for the response anyways.

And i believe that you have nailed the answer to my issue, which i also mentioned that I needed to remove the NormalizeDouble from my calculation, due to the floating point issue that you mentioned.
 
@Fernando Car
Fernando Carreiro:


after reading the previous discussion again, I believe that you took offense at my comments, however, I was not attacking you in any way or form. I was only being critical of metaquotes and the Moderators allowing such discussions to continue since such comments that you made when you made a direct quote from the user agreement, as does @William on a regular basis, opens both you and metaquotes and mql5 up to the possibility of being sued and/or other legal action in several different countries, even if your information is proven correct.

 
Revo Trades: @Fernando Carreiro

after reading the previous discussion again, I believe that you took offense at my comments, however, I was not attacking you in any way or form. I was only being critical of metaquotes and the Moderators allowing such discussions to continue since such comments that you made when you made a direct quote from the user agreement, as does @William on a regular basis, opens both you and metaquotes and mql5 up to the possibility of being sued and/or other legal action in several different countries, even if your information is proven correct.

I have no idea what you are talking about. You seem to be referring to some other thread and not this one.

 
Fernando Carreiro:

I have no idea what you are talking about. You seem to be referring to some other thread and not this one.

correct. that is: here https://www.mql5.com/en/forum/374988/page2#comment_23876592

Signal offer - block a specific country from subscription
Signal offer - block a specific country from subscription
  • 2021.08.06
  • www.mql5.com
Hi all, to offer a mql5 signal to german customers, it seems, you need a permission from the german finance police ("BaFin...