Making a range on mql4 coding

 

Hi,

My problem is the following code snip below:

if ( (ReferencePrice - 10*Point) < Bid < (ReferencePrice - 10*Point)) ;

  OrderSend (...............)


My order executes at any point above (ReferencePrice - 10*Point) and vice versa. Is there any way of creating a range, so that when the Bid is inbetween the two values, it only executes in between them.

Any help would be most appreciated.


Regards,

Mohammed Ali

 
if ( (ReferencePrice - 10*Point) < Bid < (ReferencePrice - 10*Point)) ; 
True = 1 and false = 0 so you get
if( 3 < 2 < 1 )
if( false < 1 )
if(     0 < 1 )
if(     true  )
if( 3 > 2 > 1 )
if(  true > 1 )
if(     1 > 1 )
if(     false )
 

in some occasion this:

10*Point

will become 0 as the integer value 10 causes Point to be casted to an integer and that means it becomes 0.

So you'd better write to be save:

10.0*Point
 
Carl Schreiber:

in some occasion this:

will become 0 as the integer value 10 causes Point to be casted to an integer and that means it becomes 0.

So you'd better write to be save:

This is not exact. Typecast will never happen implicitly in such case.
 
momo133:

Hi,

My problem is the following code snip below:

if ( (ReferencePrice - 10*Point) < Bid < (ReferencePrice - 10*Point)) ;

  OrderSend (...............)


My order executes at any point above (ReferencePrice - 10*Point) and vice versa. Is there any way of creating a range, so that when the Bid is inbetween the two values, it only executes in between them.

Any help would be most appreciated.


Regards,

Mohammed Ali

Your value is the same on both side.

if(Bid > Reference - Xpoint && Bid < Reference + Xpoint)
  ...
 

Sorry for any confusion,  I meant to write :

if ( (ReferencePrice - 10*Point) < Bid < (ReferencePrice + 10*Point)) ;


Thank you for the help so far. It has been very helpful for me.

 
Carl Schreiber:

in some occasion this:

will become 0 as the integer value 10 causes Point to be casted to an integer and that means it becomes 0.

So you'd better write to be save:

That's not true, any double in an operation will force the result of the operation to be a double.

 
momo133: Sorry for any confusion,  I meant to write :
if( (ReferencePrice - 10*Point) < Bid < (ReferencePrice + 10*Point));
  1. Please use SRC for code.
  2. That is bogus as I already pointed out.
  3. Write it like Alain Verleyen already gave you. Or simplify:
    if(MathAbs(ReferencePrice - Bid) < 10*Point);
  4. You shouldn't use 10*Point, that is 10 pips for a 4 digit broker but 1 pip for a 5. If you mean one pip, write it that way:
    double   pip          = StringFind(_Symbol,"JPY") < 00.010.0001;
    int      pipsToPoints = int(pip / _Point);
    int      pipDigits    = (int)MathLog10(pipsToPoints);
    int      slippage     = 3 * pipsToPoints;