- Total profit of closed orders
- Summing orderprofit and closing all trades
- How transfer OrderProfit() to profit in pips ?
I use this function which works for me perfectly ...
void LastClosedTrade(){ int cnt, total; total = OrdersHistoryTotal(); for(cnt=0;cnt<total; cnt++){ if(OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY)==true) if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC && OrderProfit()!=0){ LastOrderType = OrderType(); LastOrderLots = OrderLots(); LastOrderProfit = OrderProfit(); } } }
It returns the Last Order Type, Last Order Lots and Last Order Profit ...
If LastOrderProfit < 0, then the Last Order was in Loss.
Do minor changes to tailor the function to your needs.
I use this function which works for me perfectly ...
It returns the Last Order Type, Last Order Lots and Last Order Profit ...
If LastOrderProfit < 0, then the Last Order was in Loss.
Do minor changes to tailor the function to your needs.
bro osama thanks for ur answer but it does not work for me in this context what i want do is to enter a buy trade if it hits the stop loss i wanna enter a sell trade but if it hits the take profit i want him to exit so i just want to know how to say if the profit is positif i have juste one order just one and i wanna if it's closed to know if it hits the take profit or stop loss
bro osama thanks for ur answer but it does not work for me in this context what i want do is to enter a buy trade if it hits the stop loss i wanna enter a sell trade but if it hits the take profit i want him to exit so i just want to know how to say if the profit is positif i have juste one order just one and i wanna if it's closed to know if it hits the take profit or stop loss
//+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // retrieving info from trade history int i,ticket,hstTotal=OrdersHistoryTotal(); for(i=0;i<hstTotal;i++) { //---- check selection result if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true) { // some work with order if(OrderSymbol()==Symbol()) { if(OrderType()==OP_BUY) { if(OrderProfit()<0) { if(OrdersTotal()==0) { //enter sell trade here ticket=OrderSend(Symbol(),OP_SELL,0.01,Bid,3,0,0,"SL sell",1234,0,clrNONE); } } } else if(OrderType()==OP_SELL) { if(OrderProfit()<0) { if(OrdersTotal()==0) { //enter buy trade here ticket=OrderSend(Symbol(),OP_BUY,0.01,Ask,3,0,0,"SL buy",1234,0,clrNONE); } } } } } } //+------------------------------------------------------------------+
thanks bro but i still have a problems thanks a lot
Then open a job in freelance

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use