Download MetaTrader 5
To add comments, please log in or register
Share your programs. That will improve your rating.
researchpro
57
researchpro 2014.10.26 01:52 

Hi ,

I'm trying to return the parameters from the OrderClose function event.  I want to load it into an array as each one occurs.

Example: When a Take Profit or StopLoss is hit, the order is closed . I want know When and at what price it closed, as it occurs.  The problem I'm having is that the order is sent ahead of time,pending,, as opposed to if I would Close the Order with the OrderClose() Function.

Can't find documentation on how to return the OrderClose info on the same tick or bar that it occurs on. All I see  documented is how to Close the order, using OrderClose().

I need to distinguish those orders which closed by TakeProfit or StopLoss, from those that closed using the OrderClose() function in the code. 

Thanks

John 

whroeder1
13627
whroeder1 2014.10.26 12:46  
researchpro: I need to distinguish those orders which closed by TakeProfit or StopLoss, from those that closed using the OrderClose() function in the code.
  1. There is none. Either you must remember it, or:
  2. I normally use:
    double OCP = OrderClosePrice();
    double OTP = OrderTakeProfit();
    double OSL = OrderStopLoss();
    bool wasSL = MathAbs(OCP - OSL ) < MathAbs(OCP - OTP );
    If the diistance between OCP and SL/TP is larger than (say) 10 pips, just close.
    Otherwise modify the order, move the SL/TP beyond 10 pips before closing. Then you can test
    double OCP = OrderClosePrice();
    double OTP = OrderTakeProfit();
    double OSL = OrderStopLoss();
    double dSL = MathAbs(OCP - OSL );
    double dTP = MathAbs(OCP - OTP );
    
    bool wasSL = dSL < dTP && dSL < 10 * pips2dbl;
researchpro
57
researchpro 2014.10.26 19:36  
WHRoeder:
researchpro: I need to distinguish those orders which closed by TakeProfit or StopLoss, from those that closed using the OrderClose() function in the code.
  1. There is none. Either you must remember it, or:
  2. I normally use:If the diistance between OCP and SL/TP is larger than (say) 10 pips, just close.
    Otherwise modify the order, move the SL/TP beyond 10 pips before closing. Then you can test

Excellent WHRoeder. Thank you for your help.

Using Less Than, will allow a fuzzy conclusion to create the bool I need to distinguish Types -- without having to meet an exact predetermined price criteria.

John 

/
To add comments, please log in or register