Historical Data method of close

Back to topics list To post a new topic, please log in or register
avatar
70
Keelan 2015.11.01 13:04
 
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.
avatar
12983
WHRoeder 2015.11.01 16:32 #
 
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

avatar
70
Keelan 2015.11.01 16:55 #
 
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.
avatar
12983
WHRoeder 2015.11.01 17:04 #
 
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?

avatar
70
Keelan 2015.11.01 17:32 #
 
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.
Back to topics list  

To add comments, please log in or register