5-digit broker (Alpari) but calculations return 4-digits

 

I'm coding an EA (my first real one) and I'm stumped...

Alpari (US) is showing 5-digit pricing (fractional pip pricing), but all of my calculations and return values are only 4-digits.

This has a negative impact when "rounding" EMA values; for instance the EMA value of the previous bar could be 1.58393 and the EMA value of the second previous bar could be 1.58386. To my EA, that means that the EMA is moving in an upward direction. However, the rounding to four digits returns 1.5839 for both values (rounding the previous bar down and the second previous bar up). Ugh.

Oh, and when I convert the double value to a string and display it, it shows 5 digits. Do I have to convert every double to a string and then back to a double to get the 5-digits?

What am I missing?

Thanks.

 

S

> all of my calculations and return values are only 4-digits

Which ones and how are you checking the precision?

The Print statement will only show 4 digits unless you do the DoubleToString thing

NB

Some indicators only return 4 digits on a 5 digit account

Some brokers occasionally have a 4 digit pair when the others are 5...

So... I always do something like this on all order operations

adOrderPrice = NormalizeDouble(dOrderPrice, Digits)

Good Luck

-BB-

 
BarrowBoy:

S

> all of my calculations and return values are only 4-digits

Which ones and how are you checking the precision?

The Print statement will only show 4 digits unless you do the DoubleToString thing

NB

Some indicators only return 4 digits on a 5 digit account

Some brokers occasionally have a 4 digit pair when the others are 5...

So... I always do something like this on all order operations

Good Luck

-BB-


My return values have been Bar prices [Close,Open, High, Low], Stochastic values, EMA values (I'm writing a typical MA crossover EA just to get my feet wet). This may be a newbie mistake, but my "check" has been to use the Alert() to print values during test runs. You're right - it prints 5 digits only if I use DoubleToString.

I'll try the NormalizeDouble function. Guess if I wasn't such a rookie, I'd have known about this function. Thanks for your patience.

And since no good deed goes unpunished - :), I have a few more questions: How can I validate the values? What tools do you use for testing and debugging? I saw one debugger on this website - have you tried it?

Thanks again.

 

dont worry about the print function. Your doubles will internally have the highest precision and if you compare two doubles you will have the expected result, even if it *seems* to look the same through the print function. It will only be formatted to 4 digits for printing, the number itself keeps all its digits and its precision.

Don't use NormalizeDouble() for your EMA values since this will really cut off digits and you will lose precision. The only use for NormalizeDouble() is to prepare prices for the OrderSend() function which will for some strange reason only accept rounded prices and complain if it is too precise. (Of course there are some other uses too but you will first need to understand what is really going on behind the scenes with your doubles)

 

As 7bit says, the non-order double comparisons will be just fine without NormalizeDouble

As for debugging, there are various freeware tools, get one for that handles C

Thing is, after a while, once you have enough functions, includes and libraries, you really wont need it

Worst case, I just rem out big chunks in MetaEditor with

/*

... suspect code here

*/

until I find the bug

The obvious thing is to not write too much between compilations ;)

Less obvious is to start a new copy of the working code before adding your 'new improved' code :)

-BB-

 

BB and 7bit,

Thanks for all your help. Much appreciated. I'll post back here in a couple of days to let you know how the EA is running.

Thanks again.

 

BTW to display 5 digits in Data Window (& Mouse over) I put

IndicatorDigits(Digits);// display correct number of digits for prices

or

IndicatorDigits(Digits + 1); // increase accuracy those those 'did my signals really cross over?'

in my Indicator init()

 
The EA is running as programmed (too bad it's not going to make me a millionaire overnight! LOL). Thanks for your help. The information you guys provided was quite useful.