Extra decimal place, how to detect it so I can code round it ?

 

I'm sorry if this has been answered already,  I did look but didn't find it.


I have coded a few simple indicators and scripts.  I have 2 platforms that I use and one shows an extra decimal pace compared to the other,  e.g. GU  1.5129  vs  1.51294  What I would like to do is be able to modify my code so that it can tell if it's on a platform that is using the extra digit and compensate so my indicator dispays the same information regardless.


Can anyone help ?

 

You can use Profit Factor:

int PF;

if(Digits==2||Digits==4) PF=1; else PF=10;

And then put this PF to every formula where you use Point, for example:

StopLoss=Ask-SL*Point; replace to StopLoss=Ask-SL*PF*Point;

 

Ah I see . . . you are saying that previously all instruments had either 2 or 4 digits and now on my platform with the extra digit will have 3 or 5 ?


I'm not sure that holds true for every case,  for example I have silver on my platform that gives 4 digits for GU and it gives me 3 decimal digits . . . . 

 
RaptorUK wrote >>

Ah I see . . . you are saying that previously all instruments had either 2 or 4 digits and now on my platform with the extra digit will have 3 or 5 ?

I'm not sure that holds true for every case, for example I have silver on my platform that gives 4 digits for GU and it gives me 3 decimal digits . . . .

This reports the number of digits after the decimal point:

MarketInfo (Symbol() , MODE_DIGITS ); //provides the number of digits as an integer e.g. 2 = .01, 3 = .001 4 = .0001

//This is a Metatrader predefined variable that does the same as above but you must have the symbol selected first

Digits
Good Trading
 
StooperTwada:

This reports the number of digits after the decimal point:

Good Trading

Yes I know,  but how does that help me ?

 
RaptorUK:

Yes I know, but how does that help me ?

if(MarketInfo (Symbol() , MODE_DIGITS )==4)
   {
     // ...
   }
BTW, generally it doesn't matter in an indicator how many decimals has it. It's important in EAs (SL and TP).
 

Just make an input variable that you can set & multiply poiint accordingly. I have never used the same set of inputs on 2 currencies so the decimal place can be saved a long with stops and takes etc. It's not as if you have to keep changing it.


extern double MulPoint=10;


Initialisation code

LocalPoint=Point*MulPoint;


Main Code usage

ticket=OrderSend(Symbol(),OP_BUYLIMIT,NLots,Ask,Slip*LocalPoint,Ask-stoploss*LocalPoint,Ask+takeprofit*LocalPoint,"Buy",0,0,Blue);



 
Ruptor:

Just make an input variable that you can set & multiply poiint accordingly. I have never used the same set of inputs on 2 currencies so the decimal place can be saved a long with stops and takes etc. It's not as if you have to keep changing it.


OK,  but it means I can't have an indicator that works on all platforms without some input . . .  if it can't be done then OK,  but a definitive informed  "it can't be done" would be good . . .

 
ggekko:
BTW, generally it doesn't matter in an indicator how many decimals has it. It's important in EAs (SL and TP).

You are missing the point . . .


I have an indictor that shows current bid price,  on one platform it shows it to 5 decimal places on GU on another platform it shows it to 4 decimal places . . . I want my indicator to show the same on both platforms.  So I want it to show pips not 1/10th of a pip and I want it to do this without any user input.

 
RaptorUK wrote >>

You are missing the point . . .

I have an indictor that shows current bid price, on one platform it shows it to 5 decimal places on GU on another platform it shows it to 4 decimal places . . . I want my indicator to show the same on both platforms. So I want it to show pips not 1/10th of a pip and I want it to do this without any user input.

FourDigitValue = NormalizeDouble(YourValue,4);
https://docs.mql4.com/convert/NormalizeDouble
 

OK,  but what about the other pairs and other instruments that are 2 digits on one platform and 3 on the other,  and then the ones that are 3 digits on one platform and 4 on the other ?