Download MetaTrader 5
To add comments, please log in or register
Use MQL5 Cloud Network. It is secure!
burawi
12
burawi 2015.05.26 12:50 
I want to execute  code every time a take profit is triggered, how can i do that ?
Aleksei Beliakov
22818
Aleksei Beliakov 2015.05.27 07:12  
hello buddy just check history and if you find new tp execute your code
Osama Shaban
1385
Osama Shaban 2015.05.27 12:27  

Try something like this ... Not sure 100% about the code because not tested it ... but it must work in such way ...

void LastClosedTrade(){ 
   int cnt, total; 
   total = OrdersHistoryTotal(); 
   for(cnt=0;cnt<total; cnt++){ 
      OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY); 
   
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC && OrderClosePrice() == OrderTakeProfit()){
            ClosedOnTP = true;
      }
   }
}

 Good luck ...

O. Shaban 

Alain Verleyen
Moderator
30295
Alain Verleyen 2015.05.27 20:02  
Osama Shaban:

Try something like this ... Not sure 100% about the code because not tested it ... but it must work in such way ...

 Good luck ...

O. Shaban 

Your code will not work on a real account. The close price is most of the time different from the take profit, even if the close was initiated by TP.
/
To add comments, please log in or register