calculation problem with mql4

 

Hy,

i want to do a simlpe calculation but i got always a wrong result.


#property strict

input double boxsize       =15;

double boxcalc = boxsize / 2;

int OnInit()
  {
   return(INIT_SUCCEEDED);
  }
  
void OnDeinit(const int reason) {

   
}

void OnTick() {
   
   double halfspread = (SymbolInfoDouble(Symbol(),SYMBOL_ASK) - SymbolInfoDouble(Symbol(),SYMBOL_BID)) / 2;
   double middleprice = SymbolInfoDouble(Symbol(),SYMBOL_ASK) - halfspread;
   Print(middleprice + 7.5 + " orig");
   
   double boxsizeup = middleprice + boxcalc;
   double boxsizedown = middleprice - (boxsize / 2);
   
   Print(boxcalc);
   
   Print(boxsizeup + " calc");
   
}


Print "orig" and Print boxcalc are both right but Print "calc" shows a wrong result, the difference between both are 0.5, but it should be the same result.

I dont know why they arent equal.

Can someone explain the problem?


thx

 
2021.06.23 13:13:13.934    testscr USDSGD,Daily: 8.84515 calc
2021.06.23 13:13:13.934    testscr USDSGD,Daily: 7.5
2021.06.23 13:13:13.934    testscr USDSGD,Daily: 8.84515 orig
It is the same result.