为止损程序编写一个处理程序

Program a handler for a stop loss

我想在每次自动触发止损(或获利)时执行一系列命令。

我不知道该怎么做,因为我还没有找到这些事件的处理程序。

void OnTradeTransaction(const MqlTradeTransaction& trans,const MqlTradeRequest& request,const MqlTradeResult& result)
   {
    if(trans.type!=TRADE_TRANSACTION_DEAL_ADD)return;
    if(!HistoryDealSelect(trans.deal))return;
    if(HistoryDealGetInteger(trans.deal,DEAL_MAGIC)!=InpMagicNumber)return;
    if(HistoryDealGetInteger(trans.deal,DEAL_ENTRY)!=DEAL_ENTRY_OUT)return;
    if(HistoryDealGetString(trans.deal,DEAL_SYMBOL)!=_Symbol)return;
    long reason=HistoryDealGetInteger(trans.deal,DEAL_REASON);
    if(reason==DEAL_REASON_SL)
       {
        Print(__LINE__,__FILE__," we are afraid SL is hit);
       }
    else if(reason==DEAL_REASON_TP)
       {
        Print(__LINE__,__FILE__," TP is HIT!);
       }
   }