Pips / Points at Risk for Different Symbols and Categories (Forex, Metals, Cryptos, Energies, CFDs...)

 

Hey everyone,


Before beginning, I must say I have read several forum posts (including):

https://www.mql5.com/en/forum/135345

https://www.mql5.com/en/forum/135416


It still not clear to me, how to correct calculate Pips / Points for different categories. I am aware that we must adjust for 4/5 digit brokers to correctly place TP, SL and slippage.


But when it comes to XAUUSD (Gold) (2 decimals), XAGUSD (Silver) (3 decimals), XTIUSD (Crude Oil) (2 decimals) or even US30 (2 decimals). How should we proceed?

This is the way I'm currently calculating the Pips/Points At Risk:

double PipsAtRisk(string orderSymbol, double orderPrice, double stopLoss)
{
   Print("> PIPS AT RISK <");
  
   int symbolDigits = MarketInfo(orderSymbol,MODE_DIGITS);
   Print("symbolDigits: ",symbolDigits);
   
   bool fiveDigits = GetBrokerDigits(orderSymbol);
   Print("fiveDigits: ",fiveDigits);
   
   double pipsAtRisk;
   if (fiveDigits){ pipsAtRisk = MathAbs((orderPrice-stopLoss)) * MathPow(10,symbolDigits-1); }
   else{ pipsAtRisk = MathAbs((orderPrice-stopLoss)) * MathPow(10,symbolDigits); }
   
   return pipsAtRisk;
}

bool GetBrokerDigits(string orderSymbol)
{   
   bool fiveDigits=false;
   // Detect 3/5 digit brokers for Point and Slippage
   double digits  = MarketInfo(orderSymbol,MODE_DIGITS);
   
   if (MathMod(digits,2) == 1){ fiveDigits = true; }
   return fiveDigits;
}


I also have seen that we should use TICK_VALUES / TICK_SIZE ratio instead of MODE_DIGITS but it doesn't make sense to me.

Any thoughts?


Thanks!

 
PIP, Point, or Tick are all different in general.
          What is a TICK? - MQL4 programming forum

Unless you manually adjust your SL/TP for each separate symbol, using Point means code breaks on 4 digit brokers, exotics (e.g. USDZAR where spread is over 500 points,) and metals. Compute what a PIP is and use it, not points.
          How to manage JPY pairs with parameters? - MQL4 programming forum
          Slippage defined in index points - Currency Pairs - Expert Advisors and Automated Trading - MQL5 programming forum

 
William Roeder:
PIP, Point, or Tick are all different in general.
          What is a TICK? - MQL4 programming forum

Unless you manually adjust your SL/TP for each separate symbol, using Point means code breaks on 4 digit brokers, exotics (e.g. USDZAR where spread is over 500 points,) and metals. Compute what a PIP is and use it, not points.
          How to manage JPY pairs with parameters? - MQL4 programming forum
          Slippage defined in index points - Currency Pairs - Expert Advisors and Automated Trading - MQL5 programming forum

Thanks William, but can't you just elaborate a little better? I have seen the exact response already in some other posts

As far as I understood, first I should get the pips2dbl for 4/5 digits broker right?

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)

//init digit adjustment
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; 
}

Than, you've mentioned that we should calculate DeltaValuePerLot(). But what exactly are we getting here? A ratio between TICK_VALUE (considering Account's Currency) divided by the TICK_SIZE. Is it the Price per Tick?

double  PipValuePerLot(string pair=""){ return(DeltaValuePerLot() * pips2dbl); }
double  DeltaValuePerLot(string pair=""){
    /* Value in account currency of a Point of Symbol.
     * In tester I had a sale: open=1.35883 close=1.35736 (0.0147)
     * 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.0/pip.
     *
     * https://www.mql5.com/en/forum/127584 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.0001 respectively, I've seen this
     * (intermittently) change to 14.00 and 0.0002 respectively (just example
     * tick values to illustrate).
     * https://www.mql5.com/en/forum/135345 zzuegg reports for non-currency DE30:
     * MarketInfo(Symbol(),MODE_TICKSIZE) returns 0.5
     * MarketInfo(Symbol(),MODE_DIGITS) return 1
     * Point = 0.1
     * Prices to open must be a multiple of ticksize */
    if (pair == "") pair = Symbol();
    return(  MarketInfo(pair, MODE_TICKVALUE)
           / MarketInfo(pair, MODE_TICKSIZE) ); // Not Point.
}

And lastly, you've mentioned to calculate the PIPS. What is exactly happening here?

CHANGE   gPip, gTS;     COUNT    gPipDigits;    COUNT    gPipToPoint;
bool     compute_pip(void){ // Requires MarketInfo, don't call in OnInit.
   // pip = StringFind(_Symbol, "JPY") < 0 ? 0.0001 : 0.01; // Forex
      MONEY    dvpl  = DeltaValuePerLot();                  // \ +Metals/exotics
      if(dvpl == 0)  return false;
   gTS   = MarketInfo(_Symbol, MODE_TICKSIZE);
   gPip  = gTS;   while(dvpl * gPip < 5)  gPip *= 10;       // / USDMXN/USDZAR
   gPipToPoint = COUNT(gPip / _Point);
   gPipDigits  = COUNT(MathLog10(gPipToPoint) );
   return true;
}


I would appreciate if you could explain it in more details. Also this post could a Definite Guide for people who wants to know how to do it and don't need to be jumping around looking for answers.

Thanks once more.

Regards.
Caio


 

caiopoliveira:

As far as I understood, first I should get the pips2dbl for 4/5 digits broker right?

Than, you've mentioned that we should calculate DeltaValuePerLot(). But what exactly are we getting here? A ratio between TICK_VALUE (considering Account's Currency) divided by the TICK_SIZE. Is it the Price per Tick?

And lastly, you've mentioned to calculate the PIPS. What is exactly happening here?

  1. What part of "Compute what a PIP is and use it, not points," was unclear? JPY #2.2

  2. Price per Tick is meaningless. What part of "DeltaValuePerLot" was unclear? ΔValue=Distance × Lots × DVPL.
    Never risk more than a small percentage of your trading funds, certainly less than 2% per trade, 6% total.

    Risk depends on your initial stop loss, lot size, and the value of the pair. It does not depend on margin and leverage. No SL means you have infinite risk.

    1. You place the stop where it needs to be — where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
    2. AccountBalance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the spread, and DeltaPerLot is usually around $10/pip but it takes account of the exchange rates of the pair vs. your account currency.)
    3. Do NOT use TickValue by itself - DeltaPerLot and verify that MODE_TICKVALUE is returning a value in your deposit currency, as promised by the documentation, or whether it is returning a value in the instrument's base currency.
                MODE_TICKVALUE is not reliable on non-fx instruments with many brokers - MQL4 programming forum 2017.10.10
                Is there an universal solution for Tick value? - Currency Pairs - General - MQL5 programming forum 2018.02.11
                Lot value calculation off by a factor of 100 - MQL5 programming forum 2019.07.19
    4. You must normalize lots properly and check against min and max.
    5. You must also check FreeMargin to avoid stop out

    Most pairs are worth about $10 per PIP. A $5 risk with a (very small) 5 PIP SL is $5/$10/5 or 0.1 Lots maximum.

  3. When trading exotics (e.g. USDZAR where spread is over 500 points,) and metals, the first will not be enough (3 pips → 1500 points.) See JPY #2.3