Download MetaTrader 5

Making a range on mql4 coding

To add comments, please log in or register
momo133
22
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

whroeder1
17050
whroeder1  
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 )
Carl Schreiber
Moderator
7943
Carl Schreiber  

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
Alain Verleyen
Moderator
35039
Alain Verleyen  
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.
Alain Verleyen
Moderator
35039
Alain Verleyen  
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)
  ...
momo133
22
momo133  

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.

Blahtech Limited
6858
James Cater  
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.

whroeder1
17050
whroeder1  
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;
To add comments, please log in or register