5 digits detection - page 2

 
7bit:
I am trying to write foolproof code that won't break.

If foolproof is what u r looking for then I wouldn't bet on symbols.raw file structure. It's an 'internal' and undocumented file structure. No guarantees it won't change in future versions.

 

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.

 
kennyhubbard:


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 have seen GOLD quoted with 1 digit on a 4 digit broker. I don't know the name of the broker because this was when we were testing my IRC signal generator in some IRC channel, but one of my testers made trades on GOLD and the quotes came with 1 digit. I asked him and he said his broker were a 4 digit one.

This was the exact moment where i decided that the "3 or 5" approach must be fundamentally flawed and started to search for something better.
 
7bit:
I have seen GOLD quoted with 1 digit on a 4 digit broker. [...] This was the exact moment where i decided that the "3 or 5" approach must be fundamentally flawed and started to search for something better.

On Alpari UK, which is generally a 3/5 digit broker, gold is quoted to 2DP with a tick size of 0.05. I've seen a reference somewhere on this forum to someone trading US treasuries which were quoted to 3DP. However, in such a case the tick size wouldn't have been 0.001.

One possible route is to check that the precision on a symbol is 3/5 digits and also that the tick size is 0.001/0.00001. Alternatively, depending on exactly what you are trying to achieve, you could try detecting forex currency pairs by checking that the first six characters consist of two known currency symbols (i.e. using a hard-coded list of recognised currencies). You might also be able to use MODE_PROFITCALCMODE as a way of detecting forex symbols, as opposed to futures/equities/etc, but I suspect that might not be reliable across brokers.

 
Somewhere between LotSize, TickSize, TickValue, Point, Margin, etc... there may be a ratio to solve this..
I'm too ADD right now to figure this out :)), but if someone is interested here is some links I refer to

- from Ais : LotSize,
- from fbj : Leverage, margin etc
 
The theory for the solution lies at the bottom of page 1 unless you all think it is so stupid you didn't bother to comment.
 
Ruptor:
The theory for the solution lies at the bottom of page 1 unless you all think it is so stupid you didn't bother to comment.

Speaking personally, I didn't understand your earlier post. I think 7bit's original question is asking how to handle scenarios such as the following: "There is an extern parameter where the user enters a value in pips. In some cases, the pip size which the user has in mind is different to the MODE_TICKSIZE reported by the broker - e.g. the broker has a tick size of 0.00001 but the user is calling a pip 0.0001. Is there a reliable way of reading the user's mind and working out when the pip value they entered needs to be adjusted, and by how much?" There isn't a purely mathematical answer to this along the lines you appear to be suggesting. It's a question of a semi-arbitrary convention that a pip on e.g. EURUSD is generally considered to be 0.0001 despite the fact that most brokers quote the symbol to 5DP.

EDIT: ...which is why gold etc are so tricky, because there is less of an agreed convention. On Alpari UK, gold moves in 0.05 increments. If you did a poll of traders and asked how many pips that represented, I think you'd get a reasonable number of votes for each of the following four answers: 5, 1, 0.5 and 0.05.

 
Ruptor:
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.

Ruptor,

You put it so subtle I guess I didn't get it the first time I read it. I still don't :)). Could you please elaborate?

Some brokers like GCI also list future symbols like S&P 500, IBM, Intel even Disney... how would this apply then?

 
Hi cameofx
A picture paints a thousand words or code in this case. pipx is what you have to multiply Point by to get 1/10000 th for a point which is the usual value to trade.
   double tmpx=MathCeil((Ask/10000)/Point);
   double pipx=1;
   while (tmpx>=10.0){
      pipx*=10;
      tmpx/=10;
   }
It still isn't fool proof if the currency moves up or down 10 times its value against its pair but it is impervious to broker digits in forex I think.
 
Ruptor:
[...] It still isn't fool proof if the currency moves up or down 10 times its value against its pair but it is impervious to broker digits in forex I think.

I'm frankly baffled by this. For example, if the USDJPY price fell below 90 then this code would start reporting different pipx values on a 3/5DP broker.

At the moment, with USDJPY at about 92.5, and with a 3/5DP broker where Point = 0.001, then tmpx/pipx get evaluated as follows:

  • 92.5 / 10000 = 0.00925
  • 0.00925 / 0.001 = 9.25
  • MathCeil() rounds tmpx up to 10
  • pipx gets set to 10

If the USDJPY price fell below 90 (e.g. 89.5), then the evaluation would go as follows:

  • 89.5 / 10000 = 0.00895
  • 0.00895 / 0.001 = 8.95
  • MathCeil() rounds tmpx up to 9
  • pipx remains set to 1, not 10

In other words, for reasons I completely don't understand, this code's definition of a pip is sensitive to price changes, and its multiplier flips from one order of magnitude to another based on price, not (just) based on broker settings. It would have given different results at different times over the past week. On a 2/4DP broker, pipx would stay at 1 throughout, rather than varying between 1 and 10.
Reason: