EA doens't trigger the order and returns a error - page 2

 
Jan:

Yes, it is coupled with the LoweIsEmpty and UpperIsEmpty because it must be one of those. It can only be 0 and 1 or 1 and 0... - It can never be 1 and 1 or 0 and 0...
That is the reason for it. And it is coupled because I need to know if my EA is getting the right SuperTrend, more specifically any value of the SuperTrend. But it looks like that my EA isn't getting the value...

That is the reason why I'm getting #02 or #03 error...


No, it is not the reason because both ifs cannot be true at the same time

You should be using something like

if((LowerIsEmpty == 0 && UpperIsEmpty == 0) ||  (LowerIsEmpty == 1 && UpperIsEmpty == 1))
     Alert("Supertrend error");
 
Keith Watford: You should be using something like
if((LowerIsEmpty == 0 && UpperIsEmpty == 0) ||  (LowerIsEmpty == 1 && UpperIsEmpty == 1))
     Alert("Supertrend error");
No he shouldn't. Never use 0 or 1 with bools, only true and false. And extremely seldom:
I say: You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So Don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled. Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence.
bool isBothFalse = !LowerIsEmpty && !UpperIsEmpty;
bool isBothTrue  =  LowerIsEmpty &&  UpperIsEmpty;
if(isBothFalse || isBothTrue)
     Alert("Supertrend error");
 

I tried to code it with bool but the problem was that I got wrong results... so I changed to 0 and 1...

But however, how can I fix my problem.. I don't understand why my code isn't working.. 

 

whroeder1:

Keith Watford: You should be using something like
if((LowerIsEmpty == 0 && UpperIsEmpty == 0) ||  (LowerIsEmpty == 1 && UpperIsEmpty == 1))
     Alert("Supertrend error");


No he shouldn't. Never use 0 or 1 with bools, only true and false. And extremely seldom:
bool isBothFalse = !LowerIsEmpty && !UpperIsEmpty;
bool isBothTrue  =  LowerIsEmpty &&  UpperIsEmpty;
if(isBothFalse || isBothTrue)
     Alert("Supertrend error");

As I said in my earlier post

I don't know whether UpperIsEmpty and LowerIsEmpty are bools or ints. Ideally they should be bools and you should use true or false instead of 0 and 1.

You are using 0 for true and 1 for false which is the opposite of the way they will be read by other coders.


I looked at the code again and actually there is no need for the alerts #2 and #3, they are already covered with


   if(sT_l == EMPTY_VALUE && sT_u != EMPTY_VALUE){
      Comment("sT_l == EMPTY_VALUE && sT_u != EMPTY_VALUE");
      UpperIsEmpty = 1;
      LowerIsEmpty = 0;
   }else if(sT_l != EMPTY_VALUE && sT_u == EMPTY_VALUE){
      Comment("sT_u == EMPTY_VALUE && sT_l != EMPTY_VALUE");
      UpperIsEmpty = 0;
      LowerIsEmpty = 1;  
   }else{
      Alert("Error by getting SuperTrend! - Please inform the programmer! #01");
   }
There could be a return incuded si that the following code is not executed.
 
Jan:

I tried to code it with bool but the problem was that I got wrong results... so I changed to 0 and 1...

But however, how can I fix my problem.. I don't understand why my code isn't working.. 

Did you read my post?
 
Jan: But however, how can I fix my problem.. I don't understand why my code isn't working.. 
Print out your variables, and find out why.
 

I have the same problem ,i think the the condition expression       if(var!=empty_value)    is not easy to get true result ,it should be replaced by  if(!(var==empty_value))   .

though it looks the same in logic ,  in practical ,I get really different result !

 

the  value of EMPTY_VALUE   is  2147483647 (0x7FFFFFFF) ,it is an int type , if a indicator buffer is double type ,

is it accurate when use expression       if(var!=empty_value)  or if(var==empty_value)  ?

 
yalewang: is it accurate when use expression       if(var!=empty_value)  or if(var==empty_value)  ?
  1. You always have to be careful with doubles when equality is important. The == operand. - MQL4 forum
    if(Bid == Open[0]) // unlikely to be ever true
  2. But the comparison on integer values and with specific values are always correct.
    double a = X;
    if(a == X) // always true
  3. Your problem is above your posted code. Print out your variables, and find out why.
 
whroeder1:

  1. You always have to be careful with doubles when equality is important. The == operand. - MQL4 forum
    if(Bid == Open[0]) // unlikely to be ever true
  2. But the comparison on integer values and with specific values are always correct.
    double a = X;
    if(a == X) // always true
  3. Your problem is above your posted code. Print out your variables, and find out why.

then, as we know,indicator buttor is defined as double type , if an indicator have normal value of 1.0 and EMPTY_VALUE ,


in an ea ,we will use the value ,which method is correct in following expression ?

if(var!=empty_value)  /  if(var==empty_value) / if(var!=1.0)  or if(var==1.0)

thank you .

Reason: