Last OrderType

 

Hello Folks,

I am trying to get last Ordertype. (MQL4)

Below code only keeps on working when first buy position is opened.

but when first Sell position is opened it always gives 0 regardless of what type of position are opened further.

I have no idea what's going on.

any help would be appreciated.

    int order_type;

    if(OrderSelect(1, SELECT_BY_POS)==true)
    {
     order_type=OrderType();    
    }
 
  1. You are trying to read position index one. That will only work when you have two or more orders (opened or pending on any chart).
  2. You don't want the last position, you want the last on the current chart; use an OrderSelect loop and find it.
 
Konut:

Hello Folks,

I am trying to get last Ordertype. (MQL4)

Below code only keeps on working when first buy position is opened.

but when first Sell position is opened it always gives 0 regardless of what type of position are opened further.

I have no idea what's going on.

any help would be appreciated.

      int sonuc=-1;
      int total = OrdersTotal()-1;
      if(OrderSelect(total,SELECT_BY_POS,MODE_TRADES)==false)        break;
         {
         sonuc=OrderType();
         }
      Print(sonuc); // 0-BUy,1-sell... 
 
Mehmet Bastem #:

Can't use break because you are not in a loop.

See also #1.2

Reason: