# Problem with logical operator

Thousands of developers have already published their products in the Market. Join them!
22
2014.04.18 20:23
```//+------------------------------------------------------------------+
//|                                                           px.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+

extern double StopLoss_v_pipech=50;
extern double Profit_target_v_pipech=200;
extern double Velikost_pozice=0.01;
extern double Posun_na_BE_v_pipech=50;

int Magic_number=1009;
bool ticket,close,modify;
bool obchodovat=true;

int D,m,h;
double SL,PT,BE,H,L;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{
D=DayOfWeek();
m = TimeMinute(TimeCurrent());
h = TimeHour(TimeCurrent());

SL = StopLoss_v_pipech*Point;
PT = Profit_target_v_pipech*Point;
BE = Posun_na_BE_v_pipech*Point;

H = iHigh(Symbol(),PERIOD_D1,0);
L = iLow(Symbol(), PERIOD_D1, 0);

for(int p=0; p<OrdersTotal(); p++)
{
{
{
if(H-OrderOpenPrice()>BE && H-SL>OrderStopLoss())
{

Print((H-OrderOpenPrice()>BE) +" && "+ (H-SL>OrderStopLoss()));
Print((H-OrderOpenPrice())+" > "+BE+" && "+(H-SL)+">"+OrderStopLoss());

Print(OrderOpenPrice()+" # "+H+"-"+SL+" # "+OrderTakeProfit());
Print(p);
Print("X modify ");

modify=OrderModify(OrderTicket(),
OrderOpenPrice(),
H-SL,
OrderTakeProfit(),
0,
clrYellow);
}
}
}
}
}

```

I have this code and prints r

2014.04.17 22:35:29.633 2014.04.10 04:48 px EURUSD,Daily: X modify

2014.04.17 22:35:29.633 2014.04.10 04:48 px EURUSD,Daily: 0

2014.04.17 22:35:29.633 2014.04.10 04:48 px EURUSD,Daily: 1.3718 # 1.387-0.005 # 1.3918

2014.04.17 22:35:29.633 2014.04.10 04:48 px EURUSD,Daily: 0.0152 > 0.005 && 1.382>1.382

2014.04.17 22:35:29.632 2014.04.10 04:48 px EURUSD,Daily: 1 && 1

problem is that mql4 evaluated 1.382>1.382 AS true

WHY????

9
2014.04.19 01:32
vosy:

I have this code and prints r

2014.04.17 22:35:29.633 2014.04.10 04:48 px EURUSD,Daily: X modify

2014.04.17 22:35:29.633 2014.04.10 04:48 px EURUSD,Daily: 0

2014.04.17 22:35:29.633 2014.04.10 04:48 px EURUSD,Daily: 1.3718 # 1.387-0.005 # 1.3918

2014.04.17 22:35:29.633 2014.04.10 04:48 px EURUSD,Daily: 0.0152 > 0.005 && 1.382>1.382

2014.04.17 22:35:29.632 2014.04.10 04:48 px EURUSD,Daily: 1 && 1

problem is that mql4 evaluated 1.382>1.382 AS true

WHY????

Hi vosy,

I haven't read your code thoroughly but a quick glance gives two possible causes of the problem.

1. Double data types are actually accurate to 15 significant figures but without using the DoubleToString function they are shortened and rounded to a display of 3 decimal places when displayed with the Comment and Print functions. Even though they are shortened for display purposes they are still accurate beyond 3 decimal places and any comparisons will check the full value, so it may be possible that the first 1.382 is greater than the second 1.382 but display rounding is hiding the true and full value and displaying them both as 1.382. When the first 1.382 could be 1.3822 and the second 1.382 maybe 1.3821 for example. Add the DoubleToString function to display the full value to see if this is what is happening.

2. Another theory but it is a long shot but worth a try is many of your comparisons could be evaluated incorrectly due to a lack of brackets. For example,

`if(H-OrderOpenPrice()>BE && H-SL>OrderStopLoss())`

Try rewriting it with brackets to ensure the code is being interpreted as you require, for example,

`if(((H-OrderOpenPrice())>BE) && ((H-SL)>OrderStopLoss()))`

Hope these suggestions help,

Noddy

13593
2014.04.19 12:22
vosy: problem is that mql4 evaluated 1.382>1.382 AS true
The == operand. - MQL4 forum
/