Checking if Trade is closed on stoploss or takeprofit - page 3

 

I mean MT4 is watching this distance :

( OrderClosePrice() - OrderStopLoss()  


the différence between the two is the slippage,

 if OrderStopLoss() is not modified, the way to find if order was closed by SL is still valid, only the slippage is added in comments, ( this has to be checked).

It would be usefull to have access to the two arrays of the comments, where are the informations ;-)

 
GumRai:

It is worrying that I did not get a definitive answer as the broker can change the value. 

I can only say that in my experience, I have never seen an order closed at SL or TP that does not include SL,TP, sl or tp in the OrderComment.

The brokers that I use show nothing in their order comment field. I'm not sure if that is my brokers manually removing them, or they never got added.
 
ffoorr:

I mean MT4 is watching this distance :


the différence between the two is the slippage, 

Unless the trade was closed manually, or by an EA, or by the broker (margin call). This is the crucial bit of information we cannot retrieve.

I agree with GumRai, it would be great if MetaQuotes implemented a "OrderCloseAction()" or similar to remove all this guess work.

 

Hi, 

what do you think about this solution, to know if an order is closed by TP, do you think this can be wrong?:


input int slippage = 5;


bool isTopOrderClosedByTP(int type, double closePrice, double takeProfit){
        return (type == OP_BUY && closePrice >= (takeProfit - slippage));
}

bool isBottomOrderClosedByTP(int type, double closePrice, double takeProfit){
        return (type == OP_SELL && closePrice <= (takeProfit + slippage));
}


 
bool isClosedByTP(void){
   return MathAbs( OrderClosePrice() - OrderTakeProfit() ) < MathAbs( OrderClosePrice() - OrderStopLoss() ); 
}
bool isClosedBySL(void){ return !isClosedByTP(); }
 
whroeder1:

This code only works if both Stoploss and Takeprofit are set.

This code works if an order can only be close by Stoploss and Takeprofit (no OrderClose(), OrderCloseBy() or manual close).

And even in this case there is no guarantee it will work depending of the SL/TP distance from open and slippage.

 
whroeder1:

Where would you place that code? Ontick?

Reason: