Defining number of price digits before decimal point

 

Hello

I am trying to define the number of digits in the pair price infront of the decimal, I understand that for digits after the point I can use:

Digits

But I cant seem to find anything on the digits before the point.

Thanks

Antony

 
tonyjms2005:

Hello

I am trying to define the number of digits in the pair price infront of the decimal, I understand that for digits after the point I can use:

But I cant seem to find anything on the digits before the point.

Thanks

Antony

Hi Antony,

Here is a very simple function to do this:

int DigitsBeforeDecimalPoint(double value)
{
   string number = DoubleToStr(value,2);
   
   int digits = StringFind(number,".",0);
   
   return(digits);
}
 

Hi

Thanks, so am I on the right track here:

double Atr(int shift){

   double res = iATR(Symbol(),Period(),AtrPeriod,shift);
   
   int DigitsBeforeDecimalPoint(double value)
{
   string number = DoubleToStr(value,2);
   
   int digits = StringFind(number,".",0);
   
   return(digits);
}
   
   if(digits == 3){return(NormalizeDouble(res,2));}
   if(digits == 2){return(NormalizeDouble(res,3));}
   if(digits == 1){return(NormalizeDouble(res,4));}
   

  }
}

Thank you for your swift reply

Antony

 
tonyjms2005:

Hi

Thanks, so am I on the right track here:

Thank you for your swift reply

Antony

Not exactly..

Here it is how you should do it:

double Atr(int shift)
{
   double res = iATR(Symbol(),Period(),AtrPeriod,shift);
   
   if(DigitsBeforeDecimalPoint(res) == 3){return(NormalizeDouble(res,2));}
   if(DigitsBeforeDecimalPoint(res) == 2){return(NormalizeDouble(res,3));}
   if(DigitsBeforeDecimalPoint(res) == 1){return(NormalizeDouble(res,4));}
   

  }
}

int DigitsBeforeDecimalPoint(double value)
{
   string number = DoubleToStr(value,2);
   
   int digits = StringFind(number,".",0);
   
   return(digits);
}
 

Hi

Yes I see where I was going wrong.

Thank you for your help

Antony

 

This was the only thread that I found when I wanted to do this but not reinvent the wheel but it seems inordinately complicated. I am using this:

string number = DoubleToStr(Ask,2);
if (AutoMultiplier == true){
if (StringFind(number,".",0) == 3)Multiplier=100;
if (StringFind(number,".",0) == 2)Multiplier=1000;
if (StringFind(number,".",0) == 1)Multiplier=10000;

}

where AutoMultiplier and Multiplier are extern variables, boolean and integer respectively, so that this code can be bypassed and Multiplier set manually. Multiplier is an integer used, for example, to multiply the difference between two prices to display the number of pips like this:

int Range.Day = (iHigh(NULL,PERIOD_D1,0)-iLow(NULL,PERIOD_D1,0))*Multiplier;