bool IsLastTrade(string closedBy) { int totalOrders = HistoryTotal(); if(totalOrders>=1) { if(OrderSelect(totalOrders-1,SELECT_BY_POS,MODE_HISTORY)) { string orderComment = OrderComment() return (StringFind(orderComment,closedBy, 0)!=-1); } } return(0); }
Hi, mike. Try it. PS.: In "closedBy" parameter you put "[tp]" to know if last trade closed by Take Profit or put "[sl]" to know if closed by Stop Loss.
Bye,
Alessandro Paulino
Or you can try it
Bye,
Alessandro Paulino
int LastTrade() { /* Returns: 0 - Take Profit 1 - Stop Loss 2 - Other */ int totalOrders = HistoryTotal(); if(totalOrders>=1) { if(OrderSelect(totalOrders-1,SELECT_BY_POS,MODE_HISTORY)) { if(OrderClosePrice()==OrderTakeProfit()) { return (0) } if(OrderClosePrice()==OrderStopLoss()) { return (1) } } } return(2); }
Bye,
Alessandro Paulino
closing price is not nessarily equal to take profit or asoploss.
If you tracking one order just save it and check it such as below:
int ticket;
int start()
{
...
ticket=OrderSend(...);
...
OrderSelect(ticket,SELECT_BY_TICKET);
if(OrderClosePrice()!=0)
{
if(OrderProfit()>0 //take profit
else // stop loss
}
}
Thanks so much
Mike
Mike
ale_paulino:
Hi, mike. Try it. PS.: In "closedBy" parameter you put "[tp]" to know if last trade closed by Take Profit or put "[sl]" to know if closed by Stop Loss.
Bye,
Alessandro Paulino
I found that for backtesting with tester this works but with my real account the
comment is "[completed]". Do you get the same results?
Hi, mike. Try it. PS.: In "closedBy" parameter you put "[tp]" to know if last trade closed by Take Profit or put "[sl]" to know if closed by Stop Loss.
Bye,
Alessandro Paulino

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
Thanks,
Mike