Very strange results

 

Could sombody explain me why, the Metatrader make this results:

I have this function:

void CheckIndicators(){

buy=sell=sellL=buyL=sell_close=buy_close=deleteSell=deleteBuy=false;

double kwanUP,kwanDN,midUP,midDN;

kwanUP=NormalizeDouble(iCustom(NULL,0,"Kwan",Count_Bars,StartLine,0,1),2);

kwanDN=NormalizeDouble(iCustom(NULL,0,"Kwan",Count_Bars,StartLine,1,1),2);

midUP=NormalizeDouble(iCustom(NULL,0,"Kwan",Count_Bars,StartLine,4,1),2);

midDN=NormalizeDouble(iCustom(NULL,0,"Kwan",Count_Bars,StartLine,5,1),2);

PrintFormat("kwanUP0=%f",kwanUP);

PrintFormat("kwanDN0=%f",kwanUP);

Print ("MathAbs(kwanUP-kwanDN)>0.001=",MathAbs(kwanUP-kwanDN)>0.001);

if (kwanUP!=kwanDN)Print ("Not Equal");

if (MathAbs(kwanUP-kwanDN)>0.001){

PrintFormat("kwanUP=%f",kwanUP);

PrintFormat("kwanDN=%f",kwanUP);

PrintFormat("midUP=%f",midUP);

PrintFormat("midDN=%f",midDN);

if (kwanUP0.0){

buy=true;

deleteSell=true;

sell_close=true;

}

if (kwanDN>midDN&&kwanUP==0.0&&kwanDN>0.0){

sell=true;

buy_close=true;

deleteBuy=true;

}

}

}

and in tester I've got this results in logfile

0 19:54:04 2015.05.11 01:03 Zkwana EURUSD,M15: MathAbs(kwanUP-kwanDN)>0.001=0

0 19:54:04 2015.05.11 01:03 Zkwana EURUSD,M15: kwanUP0=3.940000

0 19:54:04 2015.05.11 01:03 Zkwana EURUSD,M15: kwanDN0=3.940000

0 19:54:04 2015.05.11 01:03 Zkwana EURUSD,M15: MathAbs(kwanUP-kwanDN)>0.001=0

0 19:54:04 2015.05.11 01:03 Zkwana EURUSD,M15: kwanUP0=3.940000

0 19:54:04 2015.05.11 01:03 Zkwana EURUSD,M15: kwanDN0=3.940000

0 19:54:04 2015.05.11 01:03 Zkwana EURUSD,M15: MathAbs(kwanUP-kwanDN)>0.001=1

0 19:54:04 2015.05.11 01:03 Zkwana EURUSD,M15: Not Equal

0 19:54:04 2015.05.11 01:03 Zkwana EURUSD,M15: kwanUP=3.940000

0 19:54:04 2015.05.11 01:03 Zkwana EURUSD,M15: kwanDN=3.940000

0 19:54:04 2015.05.11 01:03 Zkwana EURUSD,M15: midUP=50.990000

0 19:54:04 2015.05.11 01:03 Zkwana EURUSD,M15: midDN=17.000000

2 19:54:04 2015.05.11 01:03 Zkwana EURUSD,M15: open #1 buy stop 0.10 EURUSD at 1.12073 sl: 1.11473 tp: 1.12573 ok

What's is going on. the same command is different resultaty and it's against logic. Why it is not equal, when is equal?

 
Zbigi:
Could sombody explain me why, the Metatrader make this results:

I have this function:

void CheckIndicators(){

buy=sell=sellL=buyL=sell_close=buy_close=deleteSell=deleteBuy=false;

double kwanUP,kwanDN,midUP,midDN;

kwanUP=NormalizeDouble(iCustom(NULL,0,"Kwan",Count_Bars,StartLine,0,1),2);

kwanDN=NormalizeDouble(iCustom(NULL,0,"Kwan",Count_Bars,StartLine,1,1),2);

midUP=NormalizeDouble(iCustom(NULL,0,"Kwan",Count_Bars,StartLine,4,1),2);

midDN=NormalizeDouble(iCustom(NULL,0,"Kwan",Count_Bars,StartLine,5,1),2);

PrintFormat("kwanUP0=%f",kwanUP);

PrintFormat("kwanDN0=%f",kwanUP);

Print ("MathAbs(kwanUP-kwanDN)>0.001=",MathAbs(kwanUP-kwanDN)>0.001);

if (kwanUP!=kwanDN)Print ("Not Equal");

if (MathAbs(kwanUP-kwanDN)>0.001){

PrintFormat("kwanUP=%f",kwanUP);

PrintFormat("kwanDN=%f",kwanUP);

PrintFormat("midUP=%f",midUP);

PrintFormat("midDN=%f",midDN);

if (kwanUP0.0){

buy=true;

deleteSell=true;

sell_close=true;

}

if (kwanDN>midDN&&kwanUP==0.0&&kwanDN>0.0){

sell=true;

buy_close=true;

deleteBuy=true;

}

}

}

and in tester I've got this results in logfile

What's is going on. the same command is different resultaty and it's against logic. Why it is not equal, when is equal?

Zbigi

Which exact version of kwan are you using?

 
mladen:
Zbigi Which exact version of kwan are you using?

I use my Version, I took the version "Copyright © 1999-2008, MetaQuotes Software Corp." as basis and I changed it a little bit. The Kwan result is not an issue. I put the result in variables and they shouldn't chandge their values. And as You see, they don't change values but the result are diffrrent

 
Zbigi:
I use my Version, I took the version "Copyright © 1999-2008, MetaQuotes Software Corp." as basis and I changed it a little bit. The Kwan result is not an issue. I put the result in variables and they shouldn't chandge their values. And as You see, they don't change values but the result are diffrrent

I asked that because this way the code can not be tested

 

Normalize double does not guarantee same results in new builds

 
Zbigi:
Yes its true, but as I mention, I put the results of indicator into variable, then I check if then are not equal. And with the same value printed in the log for both variables (3.94) I've got the value false and next time true. Are the printed result wrong or there are only pointer to indicator? Then there are not the true variables and it can be very faulty.

try using NormalizedDouble(kwanUP-kwanDN,2)==0 for comparison

if you use kwanUP = NormalizeDouble(...,2) you have a double value that does not necessarily have 0es after the 2nd decimal (that is the way how double value is stored)

 
techmac:
Normalize double does not guarantee same results in new builds

Yes its true, but as I mention, I put the results of indicator into variable, then I check if then are not equal. And with the same value printed in the log for both variables (3.94) I've got the value false and next time true. Are the printed result wrong or there are only pointer to indicator? Then there are not the true variables and it can be very faulty.

Interestingly, the error is repetitive

 
techmac:
try using NormalizedDouble(kwanUP-kwanDN,2)==0 for comparison if you use kwanUP = NormalizeDouble(...,2) you have a double value that does not necessarily have 0es after the 2nd decimal (that is the way how double value is stored)

Unfortunately, this solution works worse than roulette. The results are completely unpredictable

 

I changed the value to integer and it is still the same error.

int kwanUP,kwanDN,midUP,midDN;

kwanUP=NormalizeDouble(iCustom(NULL,0,"Kwan",Count_Bars,StartLine,0,1),2)*100;

kwanDN=NormalizeDouble(iCustom(NULL,0,"Kwan",Count_Bars,StartLine,1,1),2)*100;

midUP=NormalizeDouble(iCustom(NULL,0,"Kwan",Count_Bars,StartLine,4,1),2)*100;

midDN=NormalizeDouble(iCustom(NULL,0,"Kwan",Count_Bars,StartLine,5,1),2)*100;

PrintFormat("kwanUP0=%i",kwanUP);

PrintFormat("kwanDN0=%i",kwanUP);

Print ("MathAbs(kwanUP-kwanDN)>0.01=",MathAbs(kwanUP-kwanDN)>0.01);

if (kwanUP!=kwanDN)Print ("Not Equal");

if (MathAbs(kwanUP-kwanDN)>0.01){

PrintFormat("kwanUP=%i",kwanUP);

PrintFormat("kwanDN=%i",kwanUP);

PrintFormat("midUP=%i",midUP);

PrintFormat("midDN=%i",midDN);

Zkwana EURUSD,M15: kwanUP0=394

Zkwana EURUSD,M15: kwanDN0=394

Zkwana EURUSD,M15: MathAbs(kwanUP-kwanDN)>0.01=1

Zkwana EURUSD,M15: Not Equal

Zkwana EURUSD,M15: kwanUP=394

Zkwana EURUSD,M15: kwanDN=394

Zkwana EURUSD,M15: midUP=5099

Zkwana EURUSD,M15: midDN=1700

Very mysterious behavior

 

I'm very sorry, I retract everything. I find it. It it was only the typo error