Download MetaTrader 5

if i have many open orders, how to get the last order opened open price?

To add comments, please log in or register
AhmedMorra
51
AhmedMorra  

Hello fellow traders,

I am developing an ea that opens a lot of orders but only open buy order if their is a buy order opened already

what i want is the next order to open it has to be  at price above the last opened price if that makes sense.

and vice versa for sell


that's a code i tried but it just doesn't work

int LastOpenPrice(){
    datetime lastTime  = 0;
    int      lastPrice = -1; 
    for(int pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
        OrderSelect(pos, SELECT_BY_POS)                 
    &&  OrderSymbol()       == Symbol()                 
    &&  OrderOpenTime()     >  lastTime
    ){
      lastTime   = OrderOpenTime();
      lastPrice = OrderOpenPrice();
    }
    return(lastPrice);
}

thanks traders

whroeder1
16076
whroeder1  
AhmedMorra:

I am developing an ea that opens a lot of orders but only open buy order if their is a buy order opened already

what i want is the next order to open it has to be  at price above the last opened price if that makes sense.

that's a code i tried but it just doesn't work

  1. You don't have enough free margin to "opens a lot of orders." Even at min lot a $1K account can only open less than 10 total (every broker I've used.) Once they start going against you they will margin call you very quickly.
    • You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
    • Account Balance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the SPREAD, and DeltaPerLot is usually around $10/pip but it takes account of the exchange rates of the pair vs. your account currency.)
    • Do NOT use TickValue by itself - DeltaPerLot
    • You must normalize lots properly and check against min and max.
    • You must also check FreeMargin to avoid stop out

  2. That makes sense
  3. "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
  4. Perhaps you should return a double (a price) not an int. You would know that had you used strict.
To add comments, please log in or register