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.
- How to find out if order was closed manually?
- How to check if order is opened?
- assumption
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? |
|
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register