How to determine the number of pips lost when stop loss is hit

 

Suppose I determine that a stop loss has occurred.


In the start() function, how would I determine the number of pips I have lost?


is it as simple as determining the price of the original order and determining the difference between either the Ask() or Bid() (depending on whether the original order was a Buy or Sell)?


All / any help would be appreciated.

 
//++++ These are adjusted for 5 digit brokers.
int     pips2points;    // slippage  3 pips    3=points    30=points
double  pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
int     init(){
    if (Digits == 5 || Digits == 3){    // Adjust for five (5) digit brokers.
                pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
    } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
}
==============
    static datetime lastClose;  datetime lastClosePrev = lastClose;
    double pips=0;
    for(int pos=0; pos < OrdersHistoryTotal(); pos++) if (
        OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY)   // Only orders w/
    &&  OrderCloseTime()    > lastClosePrev             // not yet processed,
    &&  OrderMagicNumber()  == magic.number             // my magic number
    &&  OrderSymbol()       == Symbol()                 // and my pair.
    &&  OrderType()         <= OP_SELL){// Avoid cr/bal forum.mql4.com/32363#325360
        lastClose = OrderCloseTime();
        pips     += OrderProfit()/OrderLots()/PointValuePerLot()/pips2points;
    }    // Or (OrderProfit() + comm + swap...)
==============
double  PointValuePerLot() { // Value in account currency of a Point of Symbol.
    /* In tester I had a sale: open=1.35883 close=1.35736 (0.00147)
     * gain$=97.32/6.62 lots/147 points=$0.10/point or $1.00/pip.
     * IBFX demo/mini       EURUSD TICKVALUE=0.1 MAXLOT=50 LOTSIZE=10,000
     * IBFX demo/standard   EURUSD TICKVALUE=1.0 MAXLOT=50 LOTSIZE=100,000
     *                                  $1.00/point or $10.00/pip.
     *
     * https://forum.mql4.com/33975 CB: MODE_TICKSIZE will usually return the
     * same value as MODE_POINT (or Point for the current symbol), however, an
     * example of where to use MODE_TICKSIZE would be as part of a ratio with
     * MODE_TICKVALUE when performing money management calculations which need
     * to take account of the pair and the account currency. The reason I use
     * this ratio is that although TV and TS may constantly be returned as
     * something like 7.00 and 0.00001 respectively, I've seen this
     * (intermittently) change to 14.00 and 0.00002 respectively (just example
     * tick values to illustrate). */
    return(  MarketInfo(Symbol(), MODE_TICKVALUE)
           / MarketInfo(Symbol(), MODE_TICKSIZE) ); // Not Point.
}
 

When you check the closed orders just use

OrderClosePrice() - OrderOpenPrice() then use (preferably) WHRoeders method for calculating pips out of it. I personally am not concerned with pips and just tend to go with my broker decimal, so if I lose for example 20 pips on E/U it'll show as 0.002. The sooner you stop thinking in pips (rather in decimals) the better.

EDIT: are we talking about already closed orders or about calculating risk before setting up stop loss for orders?

 
He is referring to a closed order that closed as a loss. Now how to get the number of pips lost using the dollar amount is the question. 
 
yuddy7 #: He is referring to a closed order that closed as a loss. Now how to get the number of pips lost using the dollar amount is the question. 
  1. Do you really expect that people are still watching this thread after twelve (12) years?
    Don't resurrect old threads without a very good reason. A lot has changed since Build 600 and Higher. (2014)

  2. MathAbs( OrderOpenPrice() - OrderClosePrice() )  / pips2dbl;

Reason: