Round Number Target

 

Hi,I want my profit target to be the closest 100 pip round number if I am going up or down..

I found this code posted by WHRoeder..How can I adjust it to a chart of any digit?

double tenPips   = 0.00100,
       upperBid  = MathCeil( Bid / tenPips) * tenPips,
       lowerBid  = MathFloor(Bid / tenPips) * tenPips;

(in my case it would be 100 pips..)
 
t0mbfunk:

Hi,I want my profit target to be the closest 100 pip round number if I am going up or down..

I found this code posted by WHRoeder..How can I adjust it to a chart of any digit?


if you were using this inside your EA

//++++ 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(){                                             
     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());
     */

then you know what will be 100 pips any digit notation

 
Exactly
double // tenPips  = 0.00100, // <- False on any JPY pair or non-FX market.
       hundredPips = 100 * pips2dbl,
 

Guys how can I calculate the distance in pips from OrderOpenPrice() of for example a buy market order to the nearest 100 pip round number?

Thank you.

 
You already have the code to figure out the nearest 100 pips from Bid:
       upperBid  = MathCeil( Bid / hundredPips) * hundredPips,
You can't figure out the code for the nearest 100 pips from OrderOpenPrice()? learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.
 

I didnt ask you to write it or anything else for me. All I asked was that you explain the logic to me.

Reason: