Comparing two doubles not working

 

I am trying to compare two double numbers to try and determine where I need to draw my fib. I get a price variable from the larger timeframe and then scale down to the 30 min to find the candle I was looking at on the larger timeframe. I am determining the candle by comparing the high and or low of the candle of the larger timeframe to the 30 min timeframe. If the two prices equal then I found the candle I am looking for. When comparing prices my if statement isn't working. I've tried rounding the prices, converting to a string, subtracting them and then rounding and seeing if they equal 0 (meaning they match). All of those options aren't working. I have printed out the values that I am comparing and they match, but my logic doesn't catch it. Attached will be the indicator along with the source code I am writing. I am currently testing with USD/JPY. 

Any help would be greatly appreciated!

This is the function I am currently working on and having issues with:

Improperly formatted code removed by moderator. 

 

Improperly formatted code removed by moderator. Please EDIT your post and use the CODE button (Alt-S) when inserting code.

Code button in editor

Hover your mouse over your post and select "edit" ... 

 

Please search before you post. Your question has already been discussed multiple times on the forum.

Forum on trading, automated trading systems and testing trading strategies

MathRound fails for one particular number

Fernando Carreiro, 2018.01.01 22:08

He means that the value "0.69" cannot be exactly represented given the way a floating point number works (based on binary and not decimal representation) - hence, why the value gets represented as "0.68999999..." (see below).

You can never really "normalize" it and it is the main reason why both @whroeder1 and myself contest the use of the NormalizeDouble() function. It should in the very least be renamed to something like "RoundDigits()" because it is more of a "rounding" function and does not "normalize" in any way or fashion.


https://www.h-schmidt.net/FloatConverter/IEEE754.html

EDIT: Please note that the above images are for examples of representation in the 4-byte "float", and not the 8-byte "double" which offers more precision but still cannot represent the value "0.69" exactly due to the "binary" nature of the format.

EDIT2: For future readers that have difficulty understanding (or accepting) this concept, of decimal values not having an exact representation with a "float" or a "double", here is an article worth reading:

Why 0.1 Does Not Exist In Floating-Point

Many new programmers become aware of binary floating-point after seeing their programs give odd results: “Why does my program print 0.10000000000000001 when I enter 0.1?”; “Why does 0.3 + 0.6 = 0.89999999999999991?”; “Why does 6 * 0.1 not equal 0.6?” Questions like these are asked every day, on online forums like stackoverflow.com.

The answer is that most decimals have infinite representations in binary. Take 0.1 for example. It’s one of the simplest decimals you can think of, and yet it looks so complicated in binary:


Decimal 0.1 In Binary ( To 1369 Places

The bits go on forever; no matter how many of those bits you store in a computer, you will never end up with the binary equivalent of decimal 0.1.

... Read the rest of the article at: http://www.exploringbinary.com/why-0-point-1-does-not-exist-in-floating-point/

 

Also, the system has accidentally removed your attachments, when I edited your post. My apologies about that.

Can you please attach them again, however, please only attach the source code files, not the executable files.