what's the different between == and >= ?

 

Hi,

can anyone show me what is the difference between == and >= ?

Code 1 Using >=: (This Work)


int ticket;
  if(iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_LOWER,0) >= Close[0])
    {
     ticket=OrderSend(Symbol(),OP_BUY,1,Ask,3,Ask-25*Point,Ask+25*Point,"My order #2",16384,0,Green);
     if(ticket<0)
       {
        Print("OrderSend failed with error #",GetLastError());
        return(0);
       }
    } 


Code 2 Using == symbol : (This doesn't work)


int ticket;
  if(iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_LOWER,0) == Close[0])
    {
     ticket=OrderSend(Symbol(),OP_BUY,1,Ask,3,Ask-25*Point,Ask+25*Point,"My order #2",16384,0,Green);
     if(ticket<0)
       {
        Print("OrderSend failed with error #",GetLastError());
        return(0);
       }
    } 


Actually, the condition i'm planning to build is it will entry a position only when it touched the lower BB. therefore, i would like to use == symbol, because if i use >= symbol, whenever the price move under the lower BB, it will continue open another position

 

You need to read here about Relational Operations : https://book.mql4.com/basics/expressions

Simply put . . .

if (a == b) this is true is a is equal to b

if (a >= b) this is true if a is greater than b or if a is equal to b

 

yup2...so that when the price touched the lower BB

it should have fulfilled the condition of

if(iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_LOWER,0) == Close[0])

correct me if i'm wrong...

 
lucif:

yup2...so that when the price touched the lower BB

it should have fulfilled the condition of

correct me if i'm wrong...

Only if it hit the exact same value to the 1/10th of a pip, if it jumped past that level then the condition would not be met.
 
RaptorUK:
Only if it hit the exact same value to the 1/10th of a pip, if it jumped past that level then the condition would not be met.

uhmm...sorry to bother you again...coz i'm still a noob here...but can you explain what is 1/10th of a pip?

when i try the EA at my demo account, i monitor the price and when the current price is the same already with the value of lower bb, it still don't open any new position

 
lucif:

uhmm...sorry to bother you again...coz i'm still a noob here...but can you explain what is 1/10th of a pip?

when i try the EA at my demo account, i monitor the price and when the current price is the same already with the value of lower bb, it still don't open any new position

Take a pip, divide it by 10 . . . a 5 digit broker shows prices where the last digit is not one whole pip, it's 1/10 th of a whole pip.

How do you know the values are exactly the same ? are you printing them ?

 

i see...actually i just see the value of the bb and the current price

for example, in my metatrade

the lower bb is 1.3636 and the current price is 1.3640, when the current price is 1.3636, i checked the lower bb again and show 1.3636.

so, i think it should has fulfilled the condition, but quite strange it doesn't open position as what i code.

oh, one more question that i'd like to ask

in order to get the last open position, do we need to use Magic Number?

if yes, what is the function then?

 
lucif:

i see...actually i just see the value of the bb and the current price

for example, in my metatrade

the lower bb is 1.3636 and the current price is 1.3640, when the current price is 1.3636, i checked the lower bb again and show 1.3636.

so, i think it should has fulfilled the condition, but quite strange it doesn't open position as what i code.

oh, one more question that i'd like to ask

in order to get the last open position, do we need to use Magic Number?

if yes, what is the function then?

So you aren't printing them ? why not ? how do you expect to solve your issue without knowing what these values are ?

You mentioned the current price (Bid) . . yet you are not using the Bid price you are using Close[0] does Close[0] = Bid ? are you 100% sure ?

How is the Bollinger Band calculated ? is it's precision 4 digits ? or is it's real value 1.36360001 ?

You seem to be using a Magic Number when you place the Order, why ? what is your reason for using a Magic Number ?

https://docs.mql4.com/trading/OrderMagicNumber

 
one more thing, what about MarketInfo(Symbol(), MODE_SPREAD)
 

does that (==) really has work at least once before?

Not sure whether this can help. This category of logic, I tend to ussually employ "absolute & distancing" measure ...so the code looks like:

double   b=NormalizeDouble(iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_LOWER,0),Digits),
         c=NormalizeDouble(Close[0],Digits),
         Distance=1;

   if(MathAbs(b-c)<=Distance*Point){...

The distance must be less than D points, (up or down, does not really matter), then there are enough ground to say, that condition is met, or about to. usually goes with a stop/lim orders, seldom direct.

Reason: