Download MetaTrader 5

What causes a position to close?

To add comments, please log in or register
roamso
35
roamso 2014.11.28 19:16 

In my EA I open a position with both tp and sl.

When the position closes, I want to know if it was due to the tp or the sl.

What code can do this?

Thanks 

Alain Verleyen
Moderator
31085
Alain Verleyen 2014.11.28 19:20  
roamso:

In my EA I open a position with both tp and sl.

When the position closes, I want to know if it was due to the tp or the sl.

What code can do this?

Thanks 

Check the history and compare closing with your sl/tp.
roamso
35
roamso 2014.12.01 13:52  
angevoyageur:
Check the history and compare closing with your sl/tp.

Thanks for the reply angevoyageur

 So, using a long as an example, do you mean to check the history to see if close price was above tp, then tp was used and if close price was below sl, then sl was used?

I thought of this, but didn't think this logic was solid because the price can spike past the sl/tp threshold and go below again. I.e. the sl/tp could have been used but price changed by the time position closed, right?

But if this is the only way to check, then I don't have a choice.

Any other thoughts?

Thanks 

Alain Verleyen
Moderator
31085
Alain Verleyen 2014.12.01 15:08  
roamso:

Thanks for the reply angevoyageur

 So, using a long as an example, do you mean to check the history to see if close price was above tp, then tp was used and if close price was below sl, then sl was used?

I thought of this, but didn't think this logic was solid because the price can spike past the sl/tp threshold and go below again. I.e. the sl/tp could have been used but price changed by the time position closed, right?

But if this is the only way to check, then I don't have a choice.

Any other thoughts?

Thanks 

For a long, if the closeprice is >=tp, your trade was close by tp. If the closeprice is <=sl your trade was closed by sl. It's valid in all cases.
roamso
35
roamso 2014.12.01 21:53  
Thanks, appreciate the help
To add comments, please log in or register