I want to know what kind of script I would write to access and determine whether the most recent order was closed by a stoploss or takeprofit. How would I go about doing this?
- How to Purchase an App - Market App Store
- Modifying a Position - Trade - MetaTrader 5 for Android
- Parabolic SAR - Trend Indicators - Technical Indicators - Price Charts, Technical and Fundamental Analysis
Try something like (I'm just sketching this here, you'll need to fill in the details.
int n= OrdersTotal()-1; OrderSelect(n,SELECT_BY_POS,MODE_TRADES); if (OrderTakeProfit()>0 && OrderClosePrice()>=OrderTakeProfit()) { // must have been TP } if (OrderStopLoss()>0 && OrderClosePrice()<=OrderStopLoss()) { // must have been SL }
Ahh, one more thing.
This was of course meant for buy order :-)
This was of course meant for buy order :-)
if (OrderType==OP_BUY) { // checks like above } if (OrderType==OP_SELL) { if (OrderTakeProfit()>0 && OrderClosePrice()<=OrderTakeProfit()) { // must have been TP } if (OrderStopLoss()>0 && OrderClosePrice()>=OrderStopLoss()) { // must have been SL } }
Thanks for your advice, I found another way to do it was to record the AccountBalance() right after opening an order.
Then, after the order closed [OrdersTotal()==0], check to see if the account balance is lower or higher than the recorded balance right after the order was opened. This will determine whether it hit a profit or a loss as well.
Then, after the order closed [OrdersTotal()==0], check to see if the account balance is lower or higher than the recorded balance right after the order was opened. This will determine whether it hit a profit or a loss as well.
Thanks for your advice, I found another way to do it was to record the AccountBalance() right after opening an order.
Since you mention that, calculating the difference between OrderOpenPrice() and OrderClosePrice() should do the same (but requires check for OrderType()).
Glad you solved it and thanks for sharing your idea.
Markus
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