OrderTicket() problem?

To add comments, please log in or register
Forex Trader
114484
Forex Trader  
Hi,
I was trying to build an array of the open order tickets, but OrderTicket() just returns 0. Is that a known issue or am I somehow messing up the incredibly simple code?

Loren
Forex Trader
114484
Forex Trader  
Probably if you'd post your code it would help.


Markus
Forex Trader
114484
Forex Trader  
The code isn't anything special, which is why I didn't bother. But if you really think it's necessary... I apologize if there is a syntax error, I'm typing this from memory...

int getOpenOrders(int &ts[])
  {
   int openorders=0;
   for(int i2=0;i2<OrderTotal();i2++)
     {
      OrderSelect(i2,SELECT_BY_POS,MODE_TRADES)
      if (OrderMagicNumber!=MAGIC_NUM || OrderSymbol()!=Symbol()) continue;
      ts[openorders]=OrderTicket();
      Print("#",openorders," ticket=",ts[openorders]," OrderTicket=",OrderTicket());
      openorders++;
     }
   return(openorders);
  }



In this case, the print statement shows that both ts[openorders] always equals 0, and OrderTicket() always equals 0. I don't think that's right. Especially when there are multiple orders open and each one says it's ticket number is 0.

Loren

**Edited per shimodax's comments about i and i2.

Forex Trader
114484
Forex Trader  
I see that your loop runs on i and i2. I'm not sure where your i comes from but I think if the code is quoted from from the program directly there's a mixup of i and i2. Also, you may want to give an error message if OrderSelect() doesn't work.


Markus
Forex Trader
114484
Forex Trader  
The error is just because i was typing from memory. The code really is fine in the expert itself. I've also tried printing an error if OrderSelect doesn't work. That's not the problem. Can you please tell me if you've used OrderTicket() and what it returns when you use it. If you haven't used it, it would be a big help if you just tried printing it out for yourself and letting me know what you get.

Thanks,
Loren
Forex Trader
114484
Forex Trader  
Loren,

I've used it many times. In backtests the order tickte numbers start with 1 and go up. In real time tradig (MetaQuotes demo account) it shows the order which is shown in the open trades list.

I just opened an order manually and ran an expert and put a print statement in the part that manges the open orders

     for (i=0; i<OrdersTotal();i++) {	   // check all orders
      
         if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) {
            break;  // could not select this order for processing, so leave
         }
         
         Print(OrderTicket(), " ", OrderSymbol(), " ", OrderOpenPrice());
         ....



Output was:
2005.10.03 23:56:40 04-Expert1 USDCHF,M15: 2088858 USDCHF 1.3022

Forex Trader
114484
Forex Trader  
I fixed it. It didn't like the fact that the array ts[] was of an undefined size. Kinda annoying.

Loren
Forex Trader
114484
Forex Trader  
I did want to offer this as the source of your problem but since you said it would print OrderTicket() also as 0 I had put it aside as a possible reason. Guess I should have mentioned it anyway.

Good to hear you have it!

Markus
Forex Trader
114484
Forex Trader  
Yeah, I thought I had, but I was at work and didn't have the exact code in front of me. Turns out I was only printing from the array, not straight from OrderTicket().

I still don't understand why the arraysize needs to be defined, but it works for now.

Loren
Forex Trader
114484
Forex Trader  
Hello

I am testing my first EA (I am a newbie) and when I tested it , I read "Invalid ticket" Error code 4108. Sometimes
I read invalid ticket for OrderModify function and others invelid ticket for OrderClose function

How Can Isolve it

regards

Gonzalo

I did want to offer this as the source of your problem but since you said it would print OrderTicket() also as 0 I had put it aside as a possible reason. Guess I should have mentioned it anyway.

Good to hear you have it!

Markus
Forex Trader
114484
Forex Trader  
It sounds like you are passing an incorrect ticket number to the OrderModify and OrderClose functions. The ticket you reference must be pending or open - closed tickets will cause an error. Try printing the ticket number you are about to modify or close and check the result in the journal against your current orders.

HTH,

Aaron.
12
To add comments, please log in or register