5 digits detection - page 6

 
cameofx 2010.07.29 10:52

I use below functions now, and it's usable across different brokers & instruments.

double vPoint; 
if(Digits == 2 || Digits == 4) vPoint = Point; else
if(Digits == 3 || Digits == 5) vPoint = Point*10; // I use this for my indies; call once on init() & use where Point supposed to be used in start() 

double Poin() 
{ 
   int d = Digits;
   switch(d){
   case 2 : {return(Point); break;}
   case 4 : {return(Point); break; }
   case 3 : {return(Point*10); break;}
   case 5 : {return(Point*10); break:}
   default : return;
} // I just come up with this. Untested but should be ok/robust. To be used to replace Point for trade parameters calculations. 

cheers, ~ cameo

Here's an alternative solution to the problem that I use...

int init()
  {
   double SymPoint;
   if (Point == 0.00001) SymPoint = 0.0001; //5 digits
   else if (Point == 0.001) SymPoint = 0.01; //3 digits
   else SymPoint = Point; //Normal
   
   return(0);
  }

Then just use the SymPoint variable in place of the Point variable. Very similar to Cameo

 

Just to confuse things a little more, BrocoTrader has securities with 0 through 5 digits for their various securities...

 
kennyhubbard:

Hi 7bit,

I think you are right to try and create bulletproof code.......but there are always going to be limits.

You just have to look at the demo feed for The Collective FX, where they are testing a combined independent feed of different liquidity providers(as opposed to a single agreggated feed from multiple sources), each with their own currency pair suffix(have we found a use for the suffix it at last?), to realise the scope of the problem. This means that within 1 platform you will be able to choose from EURUSD_fx or EURUSDm or EURUSD_dbfx as you like. This alone is going to drive a massive hole in your strategy as some of these are 4 digit pricing and other 5 digit..

The "if (Digits == 3 || Digits == 5)" is about as all encompassing as you are going to find in that it works on the simple premise that you only get 2 kinds of brokers ie ones that have whole pip feeds and ones that have 1/10th pips feeds. This case covers the 2/3/4/5 currency pairs & brokers.

For my own info, have you seen any case that would be an exception? In the case of Gold, it always has been a 2 digit quote and the new 1/10th pip brokers quote it as 3 digits, so even this case is well covered.

I would suggest simply treating any exceptions that you find as such and perhaps hard code that particular issue rather than try find an holdall solution.


One thing I have noticed when this conversation comes up is that folks talk about a suffix, but never a prefix. It is possible to have a prefix as well. I have encountered a broker who has a prefix.

My thoughts on this are in agreement with the original poster here, I want products as solid as possible for my clients, I don't care to risk more coding to fix later. My entire code could be wrapped around that one change and it may cost me several developer hours to go through thousands of lines of code to modify it. So get it right the first time reduces the risk and expense of having to go back and fix it. I also agree this is a bug, but not a bug in our code so much as a weakness in MQL.

However, I have also been contemplating a solution. One of my solutions was to go through the symbol list and find EURUSD using substring to get to it. Then get the bid value of it. Once I had the bid value, I could do a doubletostr, then figure out a way to count the chars in the string, like strlen or something like it. Pain in the backside, but it might give me the 4 or 5 digit determination which would be fairly solid. From that I could establish my basis for oddities like Gold.

This is just a theory, I have yet to attempt it. Too busy just trying to get current projects dealt with.

 

in my EA i use this code for calc of Pip - this Pip i use everywhere i deal with extern bool entered in pips like SL, TP, TS or i wanna see profit in pips .. tested on 3 diff brokers - no prob on diff pairs, DAX 1/2 decimal numbers ... ya i know it looks similar like in posts before, but its functional live...


Pip = Point;
if(Digits==2 || Digits==4 || Digits==6) Pip = 100*Point;
else if( Digits==1 || Digits==3 || Digits==5) Pip = 10*Point; 

 in my other indis i try look for JPY symbol too ... :-)

Tmp_int = StringFind(Symbol(), "JPY", 0);
if(Tmp_int<0) Pip = 10000;
else Pip = 100;
 
seic:

in my EA i use this code for calc of Pip - this Pip i use everywhere i deal with extern bool entered in pips like SL, TP, TS or i wanna see profit in pips .. tested on 3 diff brokers - no prob on diff pairs, DAX 1/2 decimal numbers ... ya i know it looks similar like in posts before, but its functional live...


 in my other indis i try look for JPY symbol too ... :-)

Instead of looking for JPY I would like to find the "Point" for each currency. This is what I tried:

  ObjectSetText("pi_Pair01",MarketInfo(Pair01,MODE_POINT));

So the expectation would be to give the respective value for the pair stored in Pair01. Yet this only returns 0. Why that? Pari01 in my example is "AUDCAD" and the indicator is attached to a EURUSD chart.

Experimenting further, I now see that it works for some currencies, but not for others. This is quite confusing. MODE_DIGITS seems to work better. How can that be?

pi

 
seic:

in my EA i use this code for calc of Pip - this Pip i use everywhere i deal with extern bool entered in pips like SL, TP, TS or i wanna see profit in pips .. tested on 3 diff brokers - no prob on diff pairs, DAX 1/2 decimal numbers ... ya i know it looks similar like in posts before, but its functional live...

if(Digits==2 || Digits==4 || Digits==6) Pip = 100*Point;

Only because you're on a 5 digit broker. On a 4 digit broker PIP and Point are the same.
           What is a TICK? - MQL4 and MetaTrader 4 - MQL4 programming forum

 

And InstaForex has 4 digits for USDSEK and USDNOK, while 5 ones for EURUSD.


So I think that you need to have a array with a setting for every quote currency to get the amount of pips and not ticks.

Reason: