Historical Data method of close

 
I'm trying to find a way to specify how the last order was closed. I have used the OrdersHistoryTotal() then OrderSelect(index, SELECT_BY_POS , MODE_HISTORY) and finally OrderType() but this simply refers to the ENUM for OP_BUY, OP_SELL etc. Is there anyway to specifically find out if an order closed by s/l , t/p or closed manually? Thanks.
 
Not compiled, not tested
enum ClosedBy { BY_SL, BY_TP, BY_CLOSE };
ClosedBy OrderClosedBy(void){
  double minGapStop = MarketInfo(OrderSymbol(), MODE_STOPLEVEL) * _Point;
  double dir        = op_direction(OrderType() );
  double ocp        = OrderClosePrice();
  double osl        = OrderStopLoss();
  double otp        = OrderTakeProfit();
  if(osl != 0.0 && (ocp - osl)*dir <  minGapStop) return BY_SL;
  if(otp != 0.0 && (otp - ocp)*dir < -minGapStop) return BY_TP;
  return BY_CLOSE; // including stop out
}
double   op_direction(int op){
   return OP_BUY == (op % MKT_COUNT) ? +1.0 : -1.0;
}
Not compiled, not tested
 
Thanks, Seems pretty straight forward. Whats the MKT_COUNT variable? if op is 0 wont you get divide by 0 error? I'll just use a switch i think. Thanks again.
 
Keelan:
Whats the MKT_COUNT variable?
if op is 0 wont you get divide by 0 error?
  1. Buy=0, Sell=1, Count=2; works for pending orders also.
  2. Where in my post do you see a divide by op?
 
It works btw and nvm 0 / 2 will give the -1 but the MKT_COUNT isn't standard. Thanks a lot for the help. They should have functions like this built in. by the by, do you know why you cant use long double? i thought it was standard.