Download MetaTrader 5
To add comments, please log in or register
How to use MQL5.community messages editor? Find out in the article!
Alberto Tortella
481
Alberto Tortella 2014.08.05 07:52 

HI all, I need to build a control to find this situation

 

If (Bid contains 0.0010 or 0.0090) then (...)

 

For instance bid is 1.3810 or 1.3890. How can I isolate the 10 and 90 round numbers?

 

Thank you!

Keith Watford
Moderator
7908
Keith Watford 2014.08.05 08:35  

Not sure, maybe something like this will do it?

Odd! SRC won't work with this post for some reason! 

Keith Watford
Moderator
7908
Keith Watford 2014.08.05 08:36  
 double B=Bid;
 if(Digits==5 ||Digits==4)
    {
    double r=NormalizeDouble(B-(MathFloor(B*100)/100),5);
    if(r==0.0090 || r==0.0010)
      Print("true");
    }
whroeder1
13616
whroeder1 2014.08.05 14:11  
  1. GumRai: Odd! SRC won't work with this post for some reason!
    Happens sometimes (JS gets confused.) Copy what you need (the html,) back out of the edit form, control-refresh, edit again.
  2.     double r=NormalizeDouble(B-(MathFloor(B*100)/100),5);
        if(r==0.0090 || r==0.0010)
    
    This fails on JPY where digits < 4. This is also subject to floating equals problems The == operand. - MQL4 forum
  3. int BidPips = int(Bid / pips2dbl) % 100;
    if( BidPips == 90 || BidPips == 10) ...
    
Ian Venner
2583
Ian Venner 2014.08.06 02:44  

WHR your code will introduce a rounding error of 1 pip sometimes too

whroeder1
13616
whroeder1 2014.08.06 12:22  
SDC: WHR your code will introduce a rounding error of 1 pip sometimes too
Yep, probably should round to nearest pip
int BidPips = int(Bid / pips2dbl + 0.5) % 100;

/
To add comments, please log in or register