How can I find the smallest difference between two values for every pair?

 

Based on the pairs the smallest difference of two values may result in 0. 00001, 0.0001 or 0.001 and so on. 

For example, for GBPUSD with values 1.23434 and 1.23433, the difference is 0.00001 and for GBPJPY with values 164.712 and 164.711 the difference is 0.001.

I have been manually doing the comparison in the following way:

if ((diffAB == 0.00001) || (diffAB == 0.0001) || (diffAB == 0.001) || (diffAB == 0.01))
  {
      //smallest difference has been found
  }

I believe there should definitely be a better way to do this than what I've done above.

How can I generally cater for all currency pair smallest differences without having to manually write them case by case? Preferably a helper method that does the inner works.

 
BluePipsOnly: Based on the pairs the smallest difference of two values may result in 0. 00001, 0.0001 or 0.001 and so on. For example, for GBPUSD with values 1.23434 and 1.23433, the difference is 0.00001 and for GBPJPY with values 164.712 and 164.711 the difference is 0.001. I have been manually doing the comparison in the following way: I believe there should definitely be a better way to do this than what I've done above. How can I generally cater for all currency pair smallest differences without having to manually write them case by case? Preferably a helper method that does the inner works.

To obtain the size and value of a "tick" and/or of a "point", use the symbol functions in MQL.

Forum on trading, automated trading systems and testing trading strategies

Symbol Point Value

Fernando Carreiro, 2022.05.18 21:05

double
   dbTickSize   = SymbolInfoDouble( _symbol, SYMBOL_TRADE_TICK_SIZE  ), // Tick size
   dbTickValue  = SymbolInfoDouble( _symbol, SYMBOL_TRADE_TICK_VALUE ), // Tick value
   dbPointSize  = SymbolInfoDouble( _symbol, SYMBOL_POINT ),            // Point size
   dbPointValue = dbTickValue * dbPointSize / dbTickSize;               // Point value
Remember, it's best to use tick size and tick value in your calculations, instead of point size and its value.
 

Also read the following ...

Forum on trading, automated trading systems and testing trading strategies

Tick size vs Point(), can be a little tricky in Multicurrency EA

Fernando Carreiro, 2022.03.09 12:11

Tick Size and Point Size can be very different especially on stocks and other symbols besides forex.

Always use Tick Size to adjust and align your prices, not the point size. In essence, make sure that your price quotes, are properly aligned to the Tick size (see following examples).

...
double tickSize = SymbolInfoDouble( _Symbol, SYMBOL_TRADE_TICK_SIZE );
...
double normalised_price = round( price / tick_size ) * tick_size;
...
// Or use a function
double Round2Ticksize( double price )
{
   double tick_size = SymbolInfoDouble( _Symbol, SYMBOL_TRADE_TICK_SIZE );
   return( round( price / tick_size ) * tick_size );
};

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

 
Fernando Carreiro #:

To obtain the size and value of a "tick" and/or of a "point", use the symbol functions in MQL.

I am using the point values because I am working with candlestick OHLC values and it makes it a lot simpler to check and be certain my code is doing what it's suppose to do when the values coincide.

 
BluePipsOnly #: I am using the point values because I am working with candlestick OHLC values and it makes it a lot simpler to check and be certain my code is doing what it's suppose to do when the values coincide.

If you are already obtaining the point size, what exactly are you requesting help on?

 
  1. BluePipsOnly: Based on the pairs the smallest difference of two values may result in 0. 00001, 0.0001 or 0.001 and so on.

    The smallest difference between two prices is ticksize, not point.

    PIP, Point, or Tick are all different in general.
              Ticks, PIPs or points in the GUI. Make up your mind. - MQL4 programming forum #1 (2014)


  2. BluePipsOnly:
    if ((diffAB == 0.00001) || (diffAB == 0.0001) || (diffAB == 0.001) || (diffAB == 0.01))

    Doubles are rarely equal. Understand the links in:
              The == operand. - MQL4 programming forum #2 (2013)

 
Fernando Carreiro #:

If you are already obtaining the point size, what exactly are you requesting help on?

Sorry, I didn't see this early. Okay, I think I've been getting the point, price and tick differences a bit mixed up. I am only using iHigh, iLow, iOpen and iClose of candles for my calculations. So I must be converting the prices I get for these values into the NormalisedPrice you provided earlier. 

Reason: