Python mql5

 
hi all, I'm creating a bot using Python and mql5, I have a doubt, I want to let the script open a trade, and if that trade hit TP or SL it opens a new trade, is it possible? I can't find the variable to use in comparison I think it's ORDER_REASON_TP but I don't quite understand how to implement could you help me?
 
#include <Trade\DealInfo.mqh>
CDealInfo      m_deal;                    

void OnTradeTransaction(const MqlTradeTransaction& trans,
                        const MqlTradeRequest& request,
                        const MqlTradeResult& result)
  {
   if(trans.type==TRADE_TRANSACTION_DEAL_ADD)
     {
      if(HistoryDealSelect(trans.deal))
         m_deal.Ticket(trans.deal);
      else return;

      long reason=-1;
      m_deal.InfoInteger(DEAL_REASON,reason);

      if(reason==DEAL_REASON_TP)
      {
         // open new trade here
      }
     }
  }
 
Yashar Seyyedin #:
thanks, I've translated the code into python, but after I launch the program of course it closes, without waiting for the TP or SL, is there a way to keep it listening until one of these conditions becomes true and run the new operation? Thank you very much