[solved] How Can My EA Recognize Difference Between PIP and Point ?

 

Hello !


How To Recognize PIP Size in decimal places ( PIP, not Point ) ?


I had idea like this :


     string Instrument = Symbol () ;
     double PIPSize ;
     double PointSize = MarketInfo ( Instrument, MODE_POINT ) ;
     if ( PointSize  < 0.0001 ) PIPSize = 0.0001 ; // for most currencies
     if ( PointSize == 0.001 ) PIPSize = 0.01 ;    // JPY Curencies
     if ( PointSize == 0.01 ) PIPSize = 1;         // Well, it won't work, it will confuse JPY pairs, indices and commodities if broker does not provide POINTS ...
     Print ( "PIP size in the quote currency = ", PIPSize ) ;


But it seems very unprofessional.

My goal is to develop universal calculator, that works with every broker.

Next idea is loop for, that checks lowest point value in all symbols.

But it also won't solve this problem, especially with commodities. I saw somewhere, even GOLD has 3 digits...


Maybe, is there opprotunity somewhere in properties, to check ( differentiate ), are symbols COMMODITIES, INDICIES, CURRENCIES ?

For Loop and String comparison ?


Any ideas ?

Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
Symbol Properties - Environment State - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

Hi, the internal function "Point()" returns the value of the, well, point of your broker. For 5-digit brokers that value is 0.00001. Usually what you do is that you use your own variable in pips by multiplying by 10, so that your EA can handle 4-digit brokers. In other words, your EA main price-unit is now a PIP, from 0.00001 to 0.0001, here:

//+------------------------------------------------------------------+
// Calculates the value of price unit
//+------------------------------------------------------------------+
void CalculatePipPoint(void) {
// Uses pips instead of points to cope with 4-digit brokers
   pipPoint = Point(); // For a 5-digit broker pipPoint is 0.00001 (1 point)
   if(Digits() == 5 || Digits() == 3)
      pipPoint *= 10; // We use 0.0001 (1 pip) instead to handle 4-digit brokers 
}

Then when you use the price for a comparison you do it in pips, so you have first to convert everything into pips by dividing into 10:

// Maximum spread
   double spread = (Ask - Bid) / pipPoint; // "spread" has 5 digits after the decimal point (i.e., 0.00004), I convert that into pips (0.4) to handle 4-digit brokers
   if(INP_maxSpread > 0 && spread > INP_maxSpread) { // and I compare the spread with INP_maxSpread, where the user inputs i.e., "0.9" max spread for EURUSD
      SetUserError(0);
      return(GetLastError());
   }

I hope that makes sense. Regards.


EDIT: My EA works for Forex so I'm gonna find only either 5-digit or 4-digit brokers. If you wanna cover all possible scenarios, I guess that instead of multiplying by or dividing into 10, you'll have to ask first about the number of decimals after the point by invoking the internal function "Digits()".

 
Carlos Moreno Gonzalez #:

Hi, the internal function "Point()" returns the value of the, well, point of your broker. For 5-digit brokers that value is 0.00001. Usually what you do is that you use your own variable in pips by multiplying by 10, so that your EA can handle 4-digit brokers. In other words, your EA main price-unit is now a PIP, from 0.00001 to 0.0001, here:

Then when you use the price for a comparison you do it in pips, so you have first to convert everything into pips by dividing into 10:

I hope that makes sense. Regards.

Hi Carlos !


Thanks for answering me.

It makes sense. But this solution does not take into account INDICES and COMMODITIES.

Of course, it could be multiplied by 100, but it would confuse them with JPY currency pairs. Another issue, BTW, I can see that my broker offers 3 decimal places in GOLD, so I really don't know, how to search way to standardization.

I am thinking of different solutions, but I expected that it could be done in much easier way.

 
Michal Herda #: It makes sense. But this solution does not take into account INDICES and COMMODITIES.Of course, it could be multiplied by 100, but it would confuse them with JPY currency pairs. Another issue, BTW, I can see that my broker offers 3 decimal places in GOLD, so I really don't know, how to search way to standardization. I am thinking of different solutions, but I expected that it could be done in much easier way.

Correct. That is because MetaTrader does not identify "pips". It only works with "points" (point size) and with "ticks" (tick size, and tick value). All other forms of expressing the price quotes, like "pips" would have to be expressed by the user.

Given, that the definition of "pips" is not always the same between different traders, institution, brokers and symbols, I would suggest that you abandon the concept of "pips" and use only "points" or "ticks".

Here is an example were "points" and "ticks" can be different ...

Forum on trading, automated trading systems and testing trading strategies

Symbol Point Value

Fernando Carreiro, 2022.06.02 01:14

Here are two examples from AMP Global (Europe):

  • Micro E-mini S&P 500 (Futures): point size = 0.01, tick size = 0.25, tick value = $1.25
  • EURO STOXX Banks (Stock Index): point size = 0.01, tick size = 0.05, tick value = €2.50

 

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

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 (2017)
          Slippage defined in index points - Expert Advisors and Automated Trading - MQL5 programming forum (2018)

 

Thanks for Advices !


Indeed, it looks like a very time consuming task. So at the moment I have decided to skip this problem and use point values.

BTW I have an idea, but it requires a lot of work: each possible symbol have to be considered separately.


The solution could be:

1.  Symbol categories definition ( 4 digit FX, 2 digit FX, commodities, indices, stocks etc...) 

2.  Sorting all available instrument ( using for loop ) by :  MarketInfo ( Instrument, MODE_POINT ) and string properties.

3.  Possible exceptions consideration


Of course, it requires more details, unfortunately I cannot afford to spend hours attempting do this .


Regards

 
  1. Michal Herda #: Indeed, it looks like a very time consuming task.
    Very time consuming? I gave you a link to:
    double   pip          = StringFind(_Symbol,"JPY") < 0 ? 0.01 : 0.0001;
  2. Michal Herda #: 1.  Symbol categories definition ( 4 digit FX, 2 digit FX, commodities, indices, stocks etc...) 
    The term PIP (in the link I gave you) only applies to FX. It has no meaning outside. Period. Yet I gave you a function that would work with others. You couldn't be bothered to look.

Stop wasting our time.

 

Yes, time consuming.

Unfortunately in this case I have to gather all possible instruments in one place and it will be faster and easier to use points values, than spending time on considering what PIP definition is (example: I saw brokers using the PIP definition as the last value before the comma - for CMD and indices ). Even if it's true that it aplies only for FX , I can agree, of course, it makes no difference to me .

 

Sorry for wasting your time and thank you for the links and your help ( StringFind - very usefull function in many cases, as the others   ) .

Topic to close. Solved

Reason: