Rounding issues

 

Hello

I try to find a way to eliminate the Tick from a given price without rounding.

For example: 1.29346, I'd like to work with the figure 1.2934

However, whatever command, NormalizeDouble, MathRound, DoubleToStr seams to work according to rounding rules.

In this case I receive a value 1.2935. My intention is to just eliminate (ignore) the 5th digit.

The desired result is 1.2934.

Any idea how I can achieve this ?


Thanks

 

What about the following:

double price1 = 1.23456;
double price2 = 0;

price2 = MathFloor(price1 / 0.0001) * 0.0001;
 
redhat:

Hello

I try to find a way to eliminate the Tick from a given price without rounding.

For example: 1.29346, I'd like to work with the figure 1.2934

However, whatever command, NormalizeDouble, MathRound, DoubleToStr seams to work according to rounding rules.

In this case I receive a value 1.2935. My intention is to just eliminate (ignore) the 5th digit.

The desired result is 1.2934.

Any idea how I can achieve this ?

You can multiply up by MathPow(10, Digits-1) then use MathFloor and then divide by MathPow(10, Digits-1) Maths Functions
 
RaptorUK:
You can multiply up by MathPow(10, Digits-1) then use MathFloor and then divide by MathPow(10, Digits-1) Maths Functions

RaptorUK how come we can't do this

  int integer; 
   double doubling;
   
   integer =  1.23456 *10000;
   doubling = integer/10000 ;
   Alert (integer," to ",DoubleToStr (doubling, 10)); // the result is 1
 
onewithzachy:

RaptorUK how come we can't do this

Got it https://docs.mql4.com/basis/types/casting I forget the english typecasting :(
 

Thanks guys, what you told me here delivers the desired result.


Now perhaps you can help me out with the oposit problem.

To round a value up from a value 1.29341 to a value 1.2935.

Is there a trick to do that ?

 
onewithzachy:
Got it https://docs.mql4.com/basis/types/casting I forget the english typecasting :(
There are many ways to do what the OP wanted, my suggestion was just something I knew would work for certain.
 
redhat:

Thanks guys, what you told me here delivers the desired result.


Now perhaps you can help me out with the oposit problem.

To round a value up from a value 1.29341 to a value 1.2935.

Is there a trick to do that ?

You need to be more specific about what you want to do . . . you post isn't specific enough.
 

To round a value up from a value 1.29341 to a value 1.2935.

Is there a trick to do that ?

You might try using MathCeil, using similar code that I posted in above answer. I believe MathCeil is the opposite of MathFloor, so code accordingly.

You need to be more specific about what you want to do . . . you post isn't specific enough.

I agree with Raptor for the most part. First, try to understand the problem, research the problem to find a solution (research also means trial and error), and then if you haven't found an acceptable solution, quantify the problem (with enough specifity so people here can give you appropriate answers; remember, garbage in, garbage out) here so someone (or several someones) can guide you in the right direction.

 

Thanks guys for the comments and support.

And Yes, the MathCeil is doing what I'm looking for. Just figured that out.

double price1 = 1.23456;
double price2 = 0;

price2 = MathCeil(price1 / 0.0001) * 0.0001;
 
Don't hard code numbers (0.0001). Adjust for 4/5 digit numbers
double price1 = 1.23456;
double price2 = MathCeil( price1 / pips2dbl) * pips2dbl; // 1.2346
double price3 = MathFloor(price1 / pips2dbl) * pips2dbl; // 1.2345
double price4 = MathRound(price1 / pips2dbl) * pips2dbl; // 1.2346

///////////
//++++ These are adjusted for 5 digit brokers.
int     pips2points;    // slippage  3 pips    3=points    30=points
double  pips2dbl;       // Stoploss 15 pips    0.015      0.0150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
int     init(){                                             OptInitialization();
     if (Digits % 2 == 1){      // DE30=1/JPY=3/EURUSD=5 forum.mql4.com/43064#515262
                pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
    } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
//---- These are adjusted for 5 digit brokers.
    /* On ECN brokers you must open first and THEN set stops
    int ticket = OrderSend(..., 0,0,...)
    if (ticket < 0)
       Alert("OrderSend failed: ", GetLastError());
    else if (!OrderSelect(ticket, SELECT_BY_TICKET))
       Alert("OrderSelect failed: ", GetLastError());
    else if (!OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0)
       Alert("OrderModify failed: ", GetLastError());
     */