Normalize only works in multiple of 10. You need multiples of tick size. Do it Right:
double NormalizePrice(double p, string pair=""){ // https://www.mql5.com/en/forum/135345 zzuegg reports for non-currency DE30: // MarketInfo(chart.symbol,MODE_TICKSIZE) returns 0.5 // MarketInfo(chart.symbol,MODE_DIGITS) return 1 // Point = 0.1 // Prices to open must be a multiple of ticksize if (pair == "") pair = Symbol(); double ts = MarketInfo(pair, MODE_TICKSIZE) return( MathRound(p/ts) * ts ); } double NormalizeLots(double lots, string pair=""){ if (pair == "") pair = Symbol(); double lotStep = MarketInfo(pair, MODE_LOTSTEP), minLot = MarketInfo(pair, MODE_MINLOT); lots = MathRound(lots/ls) * ls; if (lots < minLot) lots = 0; // or minLot return(lots); }
Well... I guess I was way off. Thanks for your consistent help WHRoeder.
@WHRoeder:
You use the variable ls in the MathRound(lots/ls) * ls, but as far as I can tell ls is not defined or calculated anywhere. Or am I blind? :-)
"far as I can tell ls is not defined" | lots = MathRound(lots/ls) * ls; |
Maybe you could THINK. Compare the two almost identical routines. Understand the code - not just blindly cut and paste. Yes ls was not defined and lotStep was not used. Was that so hard? | lots = MathRound(lots / lotStep) * lotStep;
|
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I made this function to normalize price if it needs to be rounded for pairs like gold with ordersends...
What do you guys think about it? Have I gone about it correctly?