onTakeProfit

 
I want to execute  code every time a take profit is triggered, how can i do that ?
 
hello buddy just check history and if you find new tp execute your code
 

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 

 
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.