Stop trading for some time after being stopped out at SL

 

Hi all 

I'm trying to find out how I can make my EA stop trading after being stopped out at SL.  I found some code on MQL4 that looks usable, but I'm a bit confused about one of the statement, and I'd like to ask you to verify that I understand it correctly.  The code can be found in the following mail:

https://www.mql5.com/en/forum/137546

The code is as follows:

enableopen = true;
    for(int iPos=OrdersHistoryTotal()-1; iPos >= 0 ; iPos--) if (
        OrderSelect(iPos, SELECT_BY_POS, MODE_HISTORY)      // Only orders w/
    &&  OrderMagicNumber() == Magic.Number                  // my magic number
    &&  OrderSymbol()      == chart.symbol                  // and my pair.
    &&  OrderType()        <= OP_SELL// Avoid cr/bal forum.mql4.com/32363#325360
    ){
        if (MathAbs( OrderStopLoss() - OrderClosePrice() ) < pips2dbl) enableopen=false;
        break;
    }

It looks good, but because there can be at least six different types of orders (OP_BUY, OP_BUYSTOP, OP_BUYLIMIT, OP_SELL, OP_SELLSTOP, OP_SELLLIMIT), I'm a bit confused about what the following statement means:

   OrderType() <= OP_SELL

Does this mean that only OP_BUY is less than OP_SELL, and we don't want to check other types of orders from the history file?  If that is correct, it would be the same as writing  

(OrderType() == OP_SELL || OrderType == OP_BUY)

I know that it is kind of a trivial question, and I could try it out myself, but I'm just a bit confused, because as I understand the comments in the code, it only works on OP_SELL (it states that it avoids the credit orders).

Could you please comment on this?

Thanks in advance.

Best regards

G

 
gjon:

Hi all 

I'm trying to find out how I can make my EA stop trading after being stopped out at SL.  I found some code on MQL4 that looks usable, but I'm a bit confused about one of the statement, and I'd like to ask you to verify that I understand it correctly.  The code can be found in the following mail:

https://www.mql5.com/en/forum/137546

The code is as follows:

<CODE DELETED>

Firstly . . . 

Please edit your post . . .    please use the   SRC   button to post code: How to use the   SRC   button. 

 

gjon:


It looks good, but because there can be at least six different types of orders (OP_BUY, OP_BUYSTOP, OP_BUYLIMIT, OP_SELL, OP_SELLSTOP, OP_SELLLIMIT), I'm a bit confused about what the following statement means:

   OrderType() <= OP_SELL

Does this mean that only OP_BUY is less than OP_SELL, and we don't want to check other types of orders from the history file?  If that is correct, it would be the same as writing  

(OrderType() == OP_SELL || OrderType == OP_BUY)

I know that it is kind of a trivial question, and I could try it out myself, but I'm just a bit confused, because as I understand the comments in the code, it only works on OP_SELL (it states that it avoids the credit orders).

Secondly . . .

Pending order types do not appear in the Order History . . .

( OrderType() <= OP_SELL )

//   is the same as . . .

( OrderType() == OP_SELL || OrderType == OP_BUY )

 You can see the constant values for OP_BUY  OP_SELL etc. here.

 This version is more readable . . .

( OrderType() == OP_SELL || OrderType == OP_BUY )
 

Hi RaptorUK

Thanks for your reply, it clarifies my confusion completely ... and I will try to remember to use the SRC button next time ... :-)

Best regards

Reason: