Determining how previous order closed

 
I want to know what kind of script I would write to access and determine whether the most recent order was closed by a stoploss or takeprofit. How would I go about doing this?
 
Try something like (I'm just sketching this here, you'll need to fill in the details.

  int n= OrdersTotal()-1;
   OrderSelect(n,SELECT_BY_POS,MODE_TRADES);

   if (OrderTakeProfit()>0 && OrderClosePrice()>=OrderTakeProfit()) {
      // must have been TP
   }

   if (OrderStopLoss()>0 && OrderClosePrice()<=OrderStopLoss()) {
      // must have been SL
   }

 
Ahh, one more thing.

This was of course meant for buy order :-)

if (OrderType==OP_BUY) {
   // checks like above
}

if (OrderType==OP_SELL) {
      if (OrderTakeProfit()>0 && OrderClosePrice()<=OrderTakeProfit()) {
      // must have been TP
   }

   if (OrderStopLoss()>0 && OrderClosePrice()>=OrderStopLoss()) {
      // must have been SL
   }
}
 
Thanks for your advice, I found another way to do it was to record the AccountBalance() right after opening an order.

Then, after the order closed [OrdersTotal()==0], check to see if the account balance is lower or higher than the recorded balance right after the order was opened. This will determine whether it hit a profit or a loss as well.
 
Thanks for your advice, I found another way to do it was to record the AccountBalance() right after opening an order.


Since you mention that, calculating the difference between OrderOpenPrice() and OrderClosePrice() should do the same (but requires check for OrderType()).

Glad you solved it and thanks for sharing your idea.


Markus
Reason: