• Get access

NormalizeDouble(Bid, Digits) - page 3

To add comments, please log in or register
Alain Verleyen
39093
Alain Verleyen  
whroeder1:
Congratulations, you found a bug in MathRound.

Actually there is no bug in MathRound, you misunderstood.

printf("%.15f %.15f %.15f",price,price/tickSize,MathRound(price/tickSize));

2018.04.05 00:47:16.628    Test EURUSD,H1: 1.700605000000000 170060.499999999970896 170060.000000000000000

Actually it's not a bug at all in my opinion.

nicholi shen
2402
nicholi shen  
So can we all unanimously agree that we should no longer say the use of ND is "always" wrong?
Lakshan Perera
9893
Lakshan Perera  
nicholishen:
So can we all unanimously agree that we should no longer say the use of ND is "always" wrong?

Yes, I do

Thushara Dissanayake
28872
Thushara Dissanayake  

Thank you for all. After read all 3 pages i changed my code to this way. Please tell me is this correct or not. Thank you.

double TP_Level = NormalizeDouble(Bid-(pips*Take_Profit),Digits);
double SL_Level = NormalizeDouble(Bid+(pips*Stop_Loss),Digits);
              
if(CheckStopLoss_Takeprofit(OP_SELL,SL_Level,TP_Level) )
{              
  ticket=OrderSend(Symbol(),OP_SELL,LotsOptimizedsell(),Bid,3,0,TP_Level,"macd sample",MagicNumber,0,Red);
}


Earlier in this OrderSend(), I used order open price as "Bid". But when i send it for review, the product is failed by "Error 130". After that i used "ND(Bid)". I only added that ND and it is Ok! So is their any relation?

double ND(double val)
{
   return(NormalizeDouble(val, Digits));
}

 

So finally what you recommend for me?

Petr Nosek
3166
Petr Nosek  
nicholishen:
So can we all unanimously agree that we should no longer say the use of ND is "always" wrong?
I've never said that the use of ND is always wrong and I won't start with it. But I'm afraid someone will post this here every day.
Petr Nosek
3166
Petr Nosek  
Thushara Dissanayake:

Thank you for all. After read all 3 pages i changed my code to this way. Please tell me is this correct or not. Thank you.

Earlier in this OrderSend(), I used order open price as "Bid". But when i send it for review, the product is failed by "Error 130". After that i used "ND(Bid)". I only added that ND and it is Ok! So is their any relation?

So finally what you recommend for me?

You should adjust price, SL and TP to Tick Size. BTW Error 130 means invalid stops (SL, TP). I use below code to normalize price, SL and TP.
double NormalizePrice(const double price,string symbol=NULL)
  {
   if(price<0.0) return(0.0);
   if(symbol==NULL || symbol=="") symbol=_Symbol;
   double tickSize=SymbolInfoDouble(symbol,SYMBOL_TRADE_TICK_SIZE);
   return(round(price/tickSize)*tickSize);
  }
William Roeder
20388
William Roeder  
Alain Verleyen: Actually there is no bug in MathRound, you misunderstood.

2018.04.05 00:47:16.628    Test EURUSD,H1: 1.700605000000000 170060.499999999970896 170060.000000000000000

Actually it's not a bug at all in my opinion.

Then NormalizeDouble(170060.499999999970896,0) is wrong and MathRound is correct.

Alain Verleyen
39093
Alain Verleyen  
whroeder1:

Then NormalizeDouble(170060.499999999970896,0) is wrong and MathRound is correct.

I would say no if we refer to the documentation. For MathRound() it's clearly specified "rounded off to the nearest integer". While NormalizeDouble() documentation is just saying "Rounding floating point number to a specified accuracy", without specifying what rounding.

But that's interesting, maybe you will finish to convince me about NormalizeDouble

Seriously, if a function is working as documented and it's behaviour is coherent, there is no problem to use it. Up to now I never read an example showing an unpredictable or incoherent value returned by NormalizeDouble.

nicholi shen
2402
nicholi shen  
whroeder1:

Then NormalizeDouble(170060.499999999970896,0) is wrong and MathRound is correct.

http://www.dummies.com/education/math/basic-math/how-to-round-numbers-up-and-down/

How to Round Numbers Up and Down - dummies
How to Round Numbers Up and Down - dummies
  • www.dummies.com
EducationMathBasic MathHow to Round Numbers Up and Down Rounding numbers makes long numbers easier to work with. To round a two-digit number to the nearest ten, simply increase it or decrease it to the nearest number that ends in 0: When a number ends in 1, 2, 3, or 4, bring it down; in other words, keep the tens digit the same and turn the...
Thushara Dissanayake
28872
Thushara Dissanayake  
Thank you for every one!
To add comments, please log in or register