- 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 forum
- Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't
use it.
It's use is always wrong
- 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 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 forum
- 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 forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 forum
- Lot size must also be adjusted to a multiple of LotStep. If that is
not a power of 1/10 then NormalizeDouble is wrong. Do it right.
- You place the stop where it needs to be - where the reason for the trade is
no longer valid. E.g. trading a support bounce the stop goes below the
support.
- Account Balance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the SPREAD, and DeltaPerLot is usually around $10/pip)
- Do NOT use TickValue by itself - DeltaPerLot
- You must normalize lots properly and check against min and max.
- You must also check FreeMargin to avoid stop out
- 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 forum
- Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong
- 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 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 forum
- 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 forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 forum
- Lot size must also be adjusted to a multiple of LotStep. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
- You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
- Account Balance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the SPREAD, and DeltaPerLot is usually around $10/pip)
- Do NOT use TickValue by itself - DeltaPerLot
- You must normalize lots properly and check against min and max.
- You must also check FreeMargin to avoid stop out
I don not use normalizedouble in EA code, this script was made just to test why i get wrong number, lot is beign adjusted with lotstep, max lot and min lot from broker and i check for freemargin also.
I'm going to read everything you psoted, i hope i can get everything working, i have no coding background, so a lot of "easy" thing are out of my knowledge and English is not my native language.
Thank you for helping. I'll write back if i need more practical examples.
- 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 forum
- Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong
- 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 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 forum
- 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 forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 forum
- Lot size must also be adjusted to a multiple of LotStep. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
- You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
- Account Balance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the SPREAD, and DeltaPerLot is usually around $10/pip)
- Do NOT use TickValue by itself - DeltaPerLot
- You must normalize lots properly and check against min and max.
- You must also check FreeMargin to avoid stop out
I readed everything, point 2. and 3. are fully implemented in my code, the script i posted is just with plain number i get from ea with no "safety" logic just to test why i get this strange numbers.
I readed Can price != price ? - MQL4 forum, but i do not understand what i should do in my case, i don't need to compare 2 double, it's clear how to do it the topic.
I have a double, 69.0 in this case, multiplied by *0.01, and i should get 0.69, isntead i get 0.6900000000000001.
What kind of function or calculation should i use to turn this double with 16th decimal in something that my OrderModify function can accept?
d_bignotti: I have a double, 69.0 in this case, multiplied by *0.01, and i should get 0.69, isntead i get 0.6900000000000001.
| No you shouldn't. Read and understand #1 |
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I'm running this script to test a function in my EA that auto calculate lot based on % and a Delta, i wrote the revelant code only with numeric value, it's the first time i get this kind of problem running it for several week.
If you run the Script i'm getting a Lots that is 0.6896662958841845,
when i'm rounding it with Lot step of my broker (0.01) i get 69.0 that is right.
But when then, i'm multiplying it for lot step (again 0.01) i get 0.6900000000000001. Why this is happening?
Tried also using NormalizeDouble and i get wrong value, what should i do? The correct lot should be 0.69!