5 digits detection

 
double pointsPerPip(){
   string suffix = StringSubstr(Symbol(), 6);
   int digits = MarketInfo("EURUSD" + suffix, MODE_DIGITS);
   if (digits == 0){
      digits = MarketInfo("EURUSD", MODE_DIGITS);
   }
   if (digits == 0){
      return(1);
   }else{
      if (digits == 5){
         return(10);
      }
   }
   return(1);
}
I'm currently trying to find the most foolproof way to detect whether we need 1 or 10 as pip multiplier. The above was my first Idea, simply looking how many digits the EURUSD has. there are brokers where this symbol is called EURUSDm or EURUSDiam or other funny nonsense added by brokers with no other reason than to break our code and also there are Symbol names that don't have exactly 6 characters, like GOLD or GOLDm for example and the above can NOT handle this.

Does anybody have an even more sophisticated algorithm to find the correct digits? I think it all boils down to the problem of first finding how exactly the symbol name of EURUSD is and then the rest is easy. Is there for example an easy way to enumerate all available symbols so i can search for a name that contains or starts with "EURUSD"?
 

Usually I check it just once in init section:

int mypoint;
int init()
{
if(MarketInfo(Symbol(), MODE_DIGITS)==3||MarketInfo(Symbol(), MODE_DIGITS)==5)
mypoint=10;
else mypoint=1;
}
...
 
Roger:

Usually I check it just once in init section:

Your code is not foolproof, there are Symbols with 1 or 2 (gold) or other numbers of digits.

I have found a better way (still need to test it with some more brokers). It reads symbols.raw in the history folder to find the name of eurusd and then use MarketInfo();

/**
* determine the pip multiplier (1 or 10) depending on how many
* digits the EURUSD symbol has. This is done by first
* finding the exact name of this symbol in the symbols.raw
* file (it could be EURUSDm or EURUSDiam or any other stupid name
* the broker comes up with only to break other people's code) 
* and then usig MarketInfo() for determining the digits.
*/
double pointsPerPip(){
   int i;
   int digits;
   double ppp = 1;
   string symbol;
   int f = FileOpenHistory("symbols.raw", FILE_BIN | FILE_READ);
   int count = FileSize(f) / 1936;
   for (i=0; i<count; i++){ 
      symbol = FileReadString(f, 12);
      if (StringFind(symbol, "EURUSD") != -1){
         digits = MarketInfo(symbol, MODE_DIGITS);
         if (digits == 4){
            ppp = 1;
         }else{
            ppp = 10;
         }
         break;
      }
      FileSeek(f, 1924, SEEK_CUR);
   }
   FileClose(f);
   return (ppp);
}
 

It was a code for one currency only. If you want to use your EA for multi currencies you have to calculate it for each case separately.

 
7bit:
I have found a better way (still need to test it with some more brokers). It reads symbols.raw in the history folder to find the name of eurusd and then use MarketInfo();

This would break if they ever change the symbols.raw file (and might not work with older versions of MT4... although that's probably not a problem).

 
I use a method the same as Roger's and it hasn't caused me a problem yet.
It'll work for most eventualities. If you find one that it doesn't fit in the future, then just cross that bridge when you find it.

CB
 
//++++ These are adjusted for 5 digit brokers.
double  pips2points,    // slippage  3 pips    3=points    30=points
        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; }
 
WHRoeder:
if (Digits == 5 || Digits == 3) {   // Adjust for five (5) digit brokers.

You are just repeating the same thing that i already found insufficient. Using the Digits variable alone does not help the problem (the problem defined be me in the first posting) since it does not take into account on which symbol it is currently running and how many digits this symbol should have. There can be any amount of digits from 0 to 5 on some exotic pairs, not only 5 or 3 vs 4 or 2. If it were so simple i had not opened this thread. Therefore i am now just using the digits of eurusd, no matter on what pair it runs. Finding the actual name of eurusd was the biggest problem, and so far the symbols.raw method seems to be the most simple and most reliable one.
 
cloudbreaker:
If you find one that it doesn't fit in the future, then just cross that bridge when you find it.

I am trying to write foolproof code that won't break. Writing (knowingly) buggy code and wait until it breaks before i fix it doesn't fit my philosophy of how software development should be done.
 
7bit wrote >>
I am trying to write foolproof code that won't break. Writing (knowingly) buggy code and wait until it breaks before i fix it doesn't fit my philosophy of how software development should be done.


I wouldnt say the above code was 'buggy' - it merely has.. limitations, of which the users are well aware
The beauty of philosophy is that it can run asynchronously with practicality :)
-BB-
 
Isn't it just a simple (maybe not so simple in maths terms) matter of working out what one point is relative to a given price and then deciding which digit it is in compared to the digits of the price?
A simple way of achieving this could be take a price add a point and compare it to your multiplier+same price if your result is not the same increase your mutiplier in a loop until they match.
Reason: