== operation - page 3

 

SDC:

I decided to mathround the prices to round out those offending decimal places so I modified the test script:

[code not copied; see above]

output:

EURUSD,M1: Alert: 263452 prices checked

EURUSD,M1: Alert: 263452 prices passed test

EURUSD,M1: Alert: 0 prices failed test

I agree with the output from your second test. MathRound() and NormalizeDouble() do relatively same thing. MathRound takes a double and rounds that double to the nearest integer. NormalizeDouble takes a double and rounds that double to a specified decimal precision. So, MathRound(1.23) == 1.00 but NormalizeDouble(1.23, 1) == 1.20. Both values are rounded, but just in different places depending on the precision value given to NormalizeDouble(). Another example is: MathRound(1.23*10)/10 == NormalizeDouble(1.23, 1).


SDC:

i did some more testing. Someone earlier on this thread said WHR is overly critical of NormalIzeDouble() I can tell you he is not overly critical at all. NormalizeDouble() is not accurate.

[code not copied; see above]

You would expect NormalizeDouble() to round that up to 1.2322 right ? Run that script it and see what it does. The Alert says 1.2322 so you all say what are you talking about SDC that worked fine. No it didnt. If you convert that double to integer it will remove any decimal places from it and reveal if the double is really 1.2322 or is it not ? So now run this script.

[code not copied; see above]

output

EURUSD,M1: Alert: normalized 1.2322 = 1.2322

EURUSD,M1: Alert: test = 12321


NormalizeDouble() never did round it properly, the resulting double was less than 1.2322

NormalizeDouble() works correctly. The problem you are seeing is derived from dividing by Point. If you multiply by 10000, rather than dividing by Point, you get the correct anoswer:

double open = 1.232199;

double normalized = NormalizeDouble(open,4);
Alert("normalized ",open," = ",normalized);

int test = normalized * MathPow(10, 4);
Alert("test = ",test);

Alert #1

See the following side-by-side test:

double open = 1.232199;
double open_Normalized = NormalizeDouble(open, Digits);
int open_UnroundedInteger = open/Point;
int open_RoundedInteger = MathRound(open/Point);
int open_NormalizedDblToInteger1 = open_Normalized/Point;
int open_NormalizedDblToInteger2 = open_Normalized * MathPow(10, Digits);
Print ("Open: ", DoubleToStr(open, 8), " Normalized: ", DoubleToStr(open_Normalized, 8), " UnroundedInteger: ", open_UnroundedInteger, 
       " RoundedInteger: ", open_RoundedInteger, " NormalizedToInteger1: ", open_NormalizedDblToInteger1, " NormalizedToInteger2: ", open_NormalizedDblToInteger2);

Output:

Open: 1.23219900 Normalized: 1.23220000 UnroundedInteger: 123219 RoundedInteger: 123220 NormalizedToInteger1: 123219 NormalizedToInteger2: 123220

 

Yes you are right NormalizeDouble() does work correctly, my test parameters were not valid, I removed that previous post to avoid causing confusion.

I should have done integer = NormalizeDouble(1.232199/Point,0);

Reason: