Broker digit conversion function

To add comments, please log in or register
Fernando Jose Velasco Borea
894
Fernando Jose Velasco Borea  

Hello all, my question is if this function is stated correctly?

int Pips()
{          
      double Pips = Point;
      
       if(Digitos == Cinco)
         {
           Pips = Point*10;
            return(10);
          }
        else if(Digitos == Cuatro)
         {
            Pips = Point;
             return(1);
          }
        return(-1);    
} 

It's made to be able to adapt the SL, TP and Slippage values according to the amount of digits on the broker and it supports 4 or 5 digits broker.

My doubt is on the return(-1); part as I have to return something on the last path to avoid getting "not all control paths returns a value" error. It's technically imposible to get that return but I want to make sure by having another opinion:)

Thanks guys!

Eugenio Bravetti
5557
Eugenio Bravetti  
FernandoBorea:

Hello all, my question is if this function is stated correctly?

It's made to be able to adapt the SL, TP and Slippage values according to the amount of digits on the broker and it supports 4 or 5 digits broker.

My doubt is on the return(-1); part as I have to return something on the last path to avoid getting "not all control paths returns a value" error. It's technically imposible to get that return but I want to make sure by having another opinion:)

Thanks guys!

double Pips(string pSymbol = NULL)
{
   double iPoint = SymbolInfoDouble(pSymbol == NULL ? Symbol() : pSymbol, SYMBOL_POINT);
   return Digits == 3 || Digits == 5 ? (iPoint * 10) : iPoint;
}
William Roeder
19131
William Roeder  
 return Digits == 3 || Digits == 5 ? (iPoint * 10) : iPoint;
Digits is the current symbol. Code breaks for any other.
          How to manage JPY pairs with parameters? - MQL4 and MetaTrader 4 - MQL4 programming forum
          Slippage defined in index points - Currency Pairs - Expert Advisors and Automated Trading - MQL5 programming forum
Alain Verleyen
38494
Alain Verleyen  
FernandoBorea:

Hello all, my question is if this function is stated correctly?

It's made to be able to adapt the SL, TP and Slippage values according to the amount of digits on the broker and it supports 4 or 5 digits broker.

My doubt is on the return(-1); part as I have to return something on the last path to avoid getting "not all control paths returns a value" error. It's technically imposible to get that return but I want to make sure by having another opinion:)

Thanks guys!

I am tired to move your topic to the right section.

mql4 question in mql4 section, is that hard to understand ?

Eugenio Bravetti
5557
Eugenio Bravetti  

Hi whroeder1

you are right,I was wrong.....

double Pips(string pSymbol = NULL)
{
   double iPoint = SymbolInfoDouble(pSymbol == NULL ? Symbol() : pSymbol, SYMBOL_POINT);
   int iDigits = SymbolInfoInteger(pSymbol == NULL ? Symbol() : pSymbol, SYMBOL_DIGITS);
   return iDigits == 3 || iDigits == 5 ? (iPoint * 10) : iPoint;
}

in this mode is possible to use function for other symbol

William Roeder
19131
William Roeder  
I'd simplify thus:
double Pips(void){ return Pips(_Symbol); }
double Pips(string pSymbol){
   double iPoint = SymbolInfoDouble(pSymbol, SYMBOL_POINT);
   if(SymbolInfoInteger(pSymbol, SYMBOL_DIGITS) % 2 != 0) iPoint *= 10.;
   return iPoint;
}
or
double Pips(string pSymbol = NULL){
   if(pSymbol == NULL) pSymbol = _Symbol;
   double iPoint = SymbolInfoDouble(pSymbol, SYMBOL_POINT);
   if(SymbolInfoInteger(pSymbol, SYMBOL_DIGITS) % 2 != 0) iPoint *= 10.;
   return iPoint;
}
To add comments, please log in or register