why not calculate correct ??

 

hi guys  i try to do a simply script

//+------------------------------------------------------------------+
//|                                                  CalicettoPS.mq4 |
//|                        Copyright 2015, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   Comment (Close[6]-Open[6]);
   
  }
//+------------------------------------------------------------------+

but 6° candle return me error value   ,because the result is 3,999999999      but  open  value  is  0.99104  and close vale  is 0.99108

why???

Files:
why.jpg  112 kb
 
faustf:

hi guys  i try to do a simply script

but 6° candle return me error value   ,because the result is 3,999999999      but  open  value  is  0.99104  and close vale  is 0.99108

why???

The result is 3,999999999992898e-5 which is 0.00003999999999992898

 

Try this code

Comment (NormalizeDouble(Close[6]-Open[6], Digits());
 
amrali: Try this code
Try that code and get the same result. Floating point has infinite number of decimals, it's your not understanding floating point and that some numbers can't be represented exactly. (like 1/10.)
          Double-precision floating-point format - Wikipedia, the free encyclopedia

See also The == operand. - MQL4 programming forum

Print out your values to the precision you want with DoubleToString - Conversion Functions - MQL4 Reference.

Reason: