Download MetaTrader 5

Round Number Target

To add comments, please log in or register
Find out how social trading can improve your profits
derek portland
241
derek portland 2013.12.04 08:31 

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..)
Tjipke de Vries
6316
Tjipke de Vries 2013.12.04 09:01  
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

whroeder1
14532
whroeder1 2013.12.04 14:24  
Exactly
double // tenPips  = 0.00100, // <- False on any JPY pair or non-FX market.
       hundredPips = 100 * pips2dbl,
derek portland
241
derek portland 2013.12.04 18:13  

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.

whroeder1
14532
whroeder1 2013.12.04 19:12  
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.
Tom Maryland
77
Tom Maryland 2013.12.05 08:39  

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

To add comments, please log in or register