if/else - Strange results

 

Hi there,

i am pretty new to coding in MQL4 and tried to create a test-EA to check some things up.

(I have a huge amount of crapcode in between the interesting parts, which i  will cut out - only the parts that have effect on the variables are posted :) )

extern int StopLossTolerance=10;


double sar, ...;

double oderStopLoss;

sar = iSAR(NULL, 0, SarStep, SarMax, 5);

orderStopLoss = OrderStopLoss();

[...]

else if (orderStopLoss+orderStopLoss*Point < sar && sar+StopLossTolerance*Point < Ask) {

...

So fine it looks okay to me.

But when i put an OrderModify in there it got me an error code 1 (nothing changed). I started to wonder where the error could be, and after printing the whole inflicted variables, i got this result:

Print ("-------");
Print ("SL+Tollerance: ",orderStopLoss+StopLossTolerance*Point);
Print ("SAR: ", sar);
Print ("SAR + tollerance: ", sar+StopLossTolerance*Point);
Print ("ASK: ",Ask);
Print("=========");

2008.06.12 15:17:56 2008.06.05 17:58 RSIPAREMA EURUSD,M1: =========
2008.06.12 15:17:56 2008.06.05 17:58 RSIPAREMA EURUSD,M1: ASK: 1.556
2008.06.12 15:17:56 2008.06.05 17:58 RSIPAREMA EURUSD,M1: SAR + tollerance: 1.5558
2008.06.12 15:17:56 2008.06.05 17:58 RSIPAREMA EURUSD,M1: SAR: 1.5548
2008.06.12 15:17:56 2008.06.05 17:58 RSIPAREMA EURUSD,M1: SL+Tollerance: 1.5548
2008.06.12 15:17:56 2008.06.05 17:58 RSIPAREMA EURUSD,M1: -------

so the part (orderStopLoss+orderStopLoss*Point < sar) cant be true, according to the print of the variables - but even when i just give it a print (orderStopLoss+orderStopLoss*Point < sar) it sais "1" (correclty, as he entered the if else-block :)

It now came to my mind that MQL perhaps uses more than four decimal places, which are just not shown when printed. Is that the fact or have i done something really stupid here? ^^

thanks in advance!

 - georg

 

hi georg,

please consider all workings with doubles in light of normalization and symbol pair. MarketInfo() is mind opening and strongly suggest if not done already - you forget coding for bit and read Programming in Algorithmic Language MQL4

and always note:

great importance placed on NormalizeDouble()

==========

for sure more than 4 dp's.

dbl is 64bits after all, yes?

Print(dbl); defaults to 4 dp's but not strictly true as Symbol() biased eg:

2008.06.12 14:50:17 testx EURJPY,H1: Symbol()=EURJPY, Bid=166.36, Ask=166.39
2008.06.12 14:49:50 testx EURUSD,M15: Symbol()=EURUSD, Bid=1.5405, Ask=1.5407
2008.06.12 14:49:41 testx USDJPY,M15: Symbol()=USDJPY, Bid=107.99, Ask=108.02
2008.06.12 14:49:35 testx USDCAD,H1: Symbol()=USDCAD, Bid=1.0248, Ask=1.0252
2008.06.12 14:49:22 testx GBPUSD,H4: Symbol()=GBPUSD, Bid=1.9458, Ask=1.9461

and quicky code is:

int start()
{
Print("Symbol()=",Symbol(),", Bid=",Bid,", Ask=",Ask);
return(0);
}
=========

note also that mql conditionals are 100% guarranteed to be left -> right executed - no exceptions... there are reprecussions if any multipart condition has dependancies, yes? so gotta at times single-shot conditions into dreaded nested ifs syndrome...lol

=====

friend - fwiw, mql has warts for sure but you be beyond hard pressed to find/discover some issue that stop code from doing what code. that is the crux here, code will do what you have put down. the outcome maybe not wanted but mql just do what it do cuz that how it works... even tho is royal pain in backside... ;)



maybe help...

enjoy trip!