OrderOpenPrice() bug ? v4 b 186

 
In the backtester, if I have more than 3 opened positions, the following code return always the OpenPrice of the first one, not the last one. Idem for OrderLots(). Is this a bug or some misunderstanding from my part ?
Thanks for the help !
   for(cnt = 0; cnt < OrdersTotal(); cnt ++)   
   {
      if (!OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)) continue;
      if(OrderSymbol()!= Symbol() || OrderMagicNumber() != ScriptSig) continue;     
      TradesCount ++;
      if (OrderType() == OP_BUY)
      {
         LastLongLots = OrderLots();
         LastLongPrice = OrderOpenPrice();
      }
      if (OrderType() == OP_SELL)
      {
         LastShortLots = OrderLots();
         LastShortPrice = OrderOpenPrice();              
      }
   }   
 
In the backtester, if I have more than 3 opened positions, the following code return always the OpenPrice of the first one, not the last one. Idem for OrderLots(). Is this a bug or some misunderstanding from my part ?
Thanks for the help !
   for(cnt = 0; cnt < OrdersTotal(); cnt ++)   
   {
      if (!OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)) continue;
      if(OrderSymbol()!= Symbol() || OrderMagicNumber() != ScriptSig) continue;     
      TradesCount ++;
      if (OrderType() == OP_BUY)
      {
         LastLongLots = OrderLots();
         LastLongPrice = OrderOpenPrice();
      }
      if (OrderType() == OP_SELL)
      {
         LastShortLots = OrderLots();
         LastShortPrice = OrderOpenPrice();              
      }
   }   




Hi,
Nobody in this forum knows if it's a bug or not ???
Nor how to retreive values of the last opened order ???
Thanks for your reply !
 
to detect last position analyze ticket number. You cannot be sure that orders are sorted.
 
to detect last position analyze ticket number. You cannot be sure that orders are sorted.


You are absolutly right, Watson ! Thanks very much !!!
 
to detect last position analyze ticket number. You cannot be sure that orders are sorted.


Sorry, I don't quite understand what you mean by 'You cannot be sure that orders are sorted. '

I have got a similar problem, if I have more than 3 opened positions and want to close them at the same time, I can only Close 1 or 2 of them, and the result seems quite random.

Can anyone explain when a new position is created, what kind of number or ID. is given to that order and how does it work?

for(cnt = 0; cnt < OrdersTotal(); cnt ++)
{
if (!OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)) continue;

if (OrderType() == OP_BUY) {OrderClose(OrderTicket(), OrderLots(), Bid, 3, White);}

if (OrderType() == OP_SELL) {OrderClose(OrderTicket(), OrderLots(), Ask, 3, White);}

cnt --;
}
 
to detect last position analyze ticket number. You cannot be sure that orders are sorted.


Sorry, I don't quite understand what you mean by 'You cannot be sure that orders are sorted. '

I have got a similar problem, if I have more than 3 opened positions and want to close them at the same time, I can only Close 1 or 2 of them, and the result seems quite random.

Can anyone explain when a new position is created, what kind of number or ID. is given to that order and how does it work?

for(cnt = 0; cnt < OrdersTotal(); cnt ++)
{
if (!OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)) continue;

if (OrderType() == OP_BUY) {OrderClose(OrderTicket(), OrderLots(), Bid, 3, White);}

if (OrderType() == OP_SELL) {OrderClose(OrderTicket(), OrderLots(), Ask, 3, White);}

cnt --;
}


Don't use cnt-- at the end of the loop : this is done automatically by the "for" statement (wich here does cnt++ so you close only one trade !!).
If you want close all orders (are you a grider ?) use this scheme :

If(ClosingCondition) CloseAll = true;
If(TradesCount<1) CloseAll = false;                                                 // count of trades by this EA

if(CloseAll){
   for(cnt=OrdersTotal()-1; cnt>=0;cnt--){
      if (!OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)) continue;
      if(OrderSymbol!=Symbol()) continue;                                            // sample of excluding condition
      OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 3, White);
   }
   return(0);                                                      // don't allows EA to continue until all trades are closed
}

 
thanks, MichelB
 
Hello Slawa:

I want to modify the takeprofitt using ModifyOrder. However when I test my EA i read
1) invalid ticket Error code 4108.
2) invalid ticked for OrderModify function
3) invalid ticked for OrderClose function


How can I solve it


Regards


Gonzo






to detect last position analyze ticket number. You cannot be sure that orders are sorted.
Reason: