I'm trying to code to find whether the last order was a buy or a sell. Seems simple.
My typical code would be:
double LastOrder() // To find type of last order
LastOpenTime = 0; LastOrderTyp = 9;
for(int ct1 = OrdersTotal()-1; ct1 >= 0; ct1--)
OrderSelect(ct1, SELECT_BY_POS, MODE_TRADES); // Cycle through Orders
if ((OrderSymbol() == Symbol()) && // with this symbol, and
(OrderMagicNumber() == MagicNumber)) // with correct magic number
if(OrderOpenTime() > LastOpenTime)
LastOpenTime = OrderOpenTime();
LastOrderTyp = OrderType(); // OP_BUY=0, OP_SELL=1
Unfortunately, I had ignored the fact that the last order may by now have been closed, and would not be found in the pool MODE_TRADES, but in HISTORY.
How can I efficiently look through both open and closed trades, to find whether the last opened order was a Buy or Sell?
(Alternative I guess, would be to create some kind of static flag, updated when an order is opened to indicate order type. Is this a better solution?) .
Any suggestions appreciated
Yes, that's what I feared about having a static flag, rather than an OrderSelect loop.
So, just trying to figure out how to efficiently search through both open and closed orders (MODE_TRADES and HISTORY)
To add comments, please log in or register