Tracking open orders

 

How do I track my orders to know which ones are open and which ones are closed.?

Specifically, how do I track each order individually to see where it is in relation to Stop Loss?

Thanks for any input

Chuck... still a newbie and wet behind the ears!

 
mrchuckw:

How do I track my orders to know which ones are open and which ones are closed.?

Specifically, how do I track each order individually to see where it is in relation to Stop Loss?

Thanks for any input

Chuck... still a newbie and wet behind the ears!

There are lots of ways to do this. Use OrdersTotal() to tell you how many orders are open.

When you open an order you can save its ticket number and check up on it later.

Use OrderSelect() to select orders and check their values. The help files for those functions will lead you through it.

 

OK... thanks for the reply, but over the course of time there will be thousands of orders to check the status of... is that still the best way? Or can I reset the search total?

I guess I need to read up on arrays? is that what I would use?

for instance... I would take the OrdersTotal() and do a for loop starting from 1 to the OrdersTotal().... but how do I check if it's still open? and when deemed open, how do I save the ticket number? with ticket() = ticket ? I tried that, but it gives me errors.

do you know of any code already written that I could play with?

thanks for your response.

 
mrchuckw:

OK... thanks for the reply, but over the course of time there will be thousands of orders to check the status of... is that still the best way? Or can I reset the search total?

I guess I need to read up on arrays? is that what I would use?

for instance... I would take the OrdersTotal() and do a for loop starting from 1 to the OrdersTotal().... but how do I check if it's still open? and when deemed open, how do I save the ticket number? with ticket() = ticket ? I tried that, but it gives me errors.

  1. Brokers won't let you open thousands (IBFX max is 1000 and that assumes you have the margin.)
  2. Arrays could be used, but if the terminal crashes, machine reboots, power glitch, etc, you MUST recover. Either use persistent storage (I.E. files) or you must loop through the open orders.
        for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
            OrderSelect(pos, SELECT_BY_POS)
        &&  OrderMagicNumber()  == Magic.Number.Base        // Only my orders w/
        &&  OrderSymbol()       == Symbol() ){              // period and symbol
            // Trail SL, etc.
  3. You must count DOWN with multiple open orders (one chart or multiple charts)
  4. If you do not find the order in the orderSelect loop, the order is closed.
  5. Why to you need to save the ticket number, use in the orderSelect loop.
  6. I do not recommend the file route because it is insufficient. If you try open a order and get ERR_NO_RESULT (1) you do not know if the order opened or not. If you return and enter the orderSelect loop on the next tick, you will know and can set the TP/SL then. The EA MUST recover from errors.
  7. The file route is necessary only if you need to remember additional data not recalculate-able from the chart and order parameters. Then you must maintain the list as orders close.
Reason: