MQL4 - Known Issues and Best Practices - page 2

 

My understanding is that NormalizeDouble is a perfectly fine general function for general rounding of a decimal fraction to a certain number of decimal places. So is correct in the context of general programming.

However when it comes to sending Lots and Prices to the broker, it only works fine as long as MODE_LOTSTEP or MODE_TICKSIZE are powers of 10.

Eg if LOTSTEP = 0.015 then simply rounding the number to a given number of decimal places is not correct.

Therefore, for sending Lots and Prices, WHRoeder's approach is correct all of the time, and NormalizeDouble is correct most of the time :)

Also, even when the increments are powers of 10, WHRoeder's approach is simpler, than trying to work out the number of decimal places to round to?

The Article does also cover other areas such as Print only display 4 decimals, and comparison of doubles, and even mentions the MathMod bug.

 
ydrol:

My understanding is that NormalizeDouble is a perfectly fine general function for general rounding of a decimal fraction to a certain number of decimal places. So is correct in the context of general programming.

However when it comes to sending Lots and Prices to the broker, it only works fine as long as MODE_LOTSTEP or MODE_TICKSIZE are powers of 10.

Eg if LOTSTEP = 0.015 then simply rounding the number to a given number of decimal places is not correct.

Therefore, for sending Lots and Prices, WHRoeder's approach is correct all of the time, and NormalizeDouble is correct most of the time :)

Also, even when the increments are powers of 10, WHRoeder's approach is simpler, than trying to work out the number of decimal places to round to?

The Article does also cover other areas such as Print only display 4 decimals, and comparison of doubles, and even mentions the MathMod bug.

Yes, I understand . . . but does it make sense to list both as best practice ? if they are in contention/contradiction they both can't be best practice . . . I would ditch the article because it is covered in the other links.
 

Ah - we can take a vote I guess?

That is why I put WHRoeder's link in EA Best Practices (which is more significant), but the article under "General Best Practices", because the article is talking generally and not specifically about rounding for Lots/Prices, so maybe it is still valid for general programming?

 
ydrol:

Ah - we can take a vote I guess?

LOL, there is no need for a vote . . . best practice is the best practice . . . there can't be 2 best practices for the same thing. I'm just making a suggestion though, not laying down the law or anything, it's OK to disagree with me and ignore me if you want, I won't get annoyed or upset, honestly
 

No worries . To me the Article covers a number of other useful general topics (DoubleToMorePrecision, MathMod, comparison) and only discusses NormalizeDouble in a general way in which case the function works as advertised.

However for Prices and Lot sizes (not mentioned in the Article), WHRoeder's approach is best. (although possibly overstating the evilness of NormalizeDouble) We could lose the Article link, but it has other useful stuff, and is more clearly written than some forum topics that cover the same issues?

Happy to be thoughtfully disagreed with :)

 
The link about MathMod . . . the page it links to has a solution that is buggy, read this thread/post: https://www.mql5.com/en/forum/143605
 
ydrol:
I cant edit first post anymore - Can a mod change MathMod link to https://forum.mql4.com/54107#760571
Done.
 

Ta, also can you pretty please add the following under General section ?

Debugging and logging (also here and here)


And move Can price != price above working with doubles. When you get the chance ;) TIA

Trying to find best comprehensive link on dealing with broker timezone...

 
ydrol:

Ta, also can you pretty please add the following under General section ?

Debugging and logging (also here and here)


And move Can price != price above working with doubles. When you get the chance ;) TIA

Trying to find best comprehensive link on dealing with broker timezone...

Done.