Download MetaTrader 5

How can I know the order is new open or be closed by OnTradeTransaction fucntion?

To add comments, please log in or register
HongDi s& t development co.,ltd.
1602
hongbin fei  
Can you help me?
Alain Verleyen
Moderator
33807
Alain Verleyen  
codeidea:
Can you help me?
Check the values of the transmitted parameters. All is there.
HongDi s& t development co.,ltd.
1602
hongbin fei  
angevoyageur:
Check the values of the transmitted parameters. All is there.
is there any sample code? I research more, it is not clear to confirm it is be open or close, all is BUY or SELL, and there is not IN or OUT parameter.
Alain Verleyen
Moderator
33807
Alain Verleyen  
codeidea:
is there any sample code? I research more, it is not clear to confirm it is be open or close, all is BUY or SELL, and there is not IN or OUT parameter.
//+------------------------------------------------------------------+
//| TradeTransaction function                                        |
//+------------------------------------------------------------------+
void OnTradeTransaction(const MqlTradeTransaction& trans,
                        const MqlTradeRequest& request,
                        const MqlTradeResult& result)
{
    string transTypeName;
    
    switch (trans.type) {
        case TRADE_TRANSACTION_DEAL_ADD : 
            transTypeName = "TRADE_TRANSACTION_DEAL_ADD"; break;
        case TRADE_TRANSACTION_DEAL_DELETE : 
            transTypeName = "TRADE_TRANSACTION_DEAL_DELETE"; break;
        case TRADE_TRANSACTION_DEAL_UPDATE : 
            transTypeName = "TRADE_TRANSACTION_DEAL_UPDATE"; break;
        case TRADE_TRANSACTION_HISTORY_ADD : 
            transTypeName = "TRADE_TRANSACTION_HISTORY_ADD"; break;
        case TRADE_TRANSACTION_HISTORY_DELETE : 
            transTypeName = "TRADE_TRANSACTION_HISTORY_DELETE"; break;
        case TRADE_TRANSACTION_HISTORY_UPDATE : 
            transTypeName = "TRADE_TRANSACTION_HISTORY_UPDATE"; break;
        case TRADE_TRANSACTION_ORDER_ADD : 
            transTypeName = "TRADE_TRANSACTION_ORDER_ADD"; break;
        case TRADE_TRANSACTION_ORDER_DELETE : 
            transTypeName = "TRADE_TRANSACTION_ORDER_DELETE"; break;
        case TRADE_TRANSACTION_ORDER_UPDATE : 
            transTypeName = "TRADE_TRANSACTION_ORDER_UPDATE"; break;
        case TRADE_TRANSACTION_POSITION : 
            transTypeName = "TRADE_TRANSACTION_POSITION"; break;
        case TRADE_TRANSACTION_REQUEST : 
            transTypeName = "TRADE_TRANSACTION_REQUEST"; break; 
        default:
            transTypeName = "UNKNOWN";
    }
    Print("TradeTransaction event, type : ", transTypeName, "(", trans.type, ")");
    
    if (trans.type == TRADE_TRANSACTION_DEAL_ADD) {
        if (HistoryDealSelect(trans.deal) == true) {
            string dealEntryName;
            ENUM_DEAL_ENTRY dealEntry = (ENUM_DEAL_ENTRY) HistoryDealGetInteger(trans.deal, DEAL_ENTRY);
            switch (dealEntry) {
                case DEAL_ENTRY_IN:
                    dealEntryName = "DEAL_ENTRY_IN"; break;
                case DEAL_ENTRY_INOUT:
                    dealEntryName = "DEAL_ENTRY_INOUT"; break;
                case DEAL_ENTRY_OUT:
                    dealEntryName = "DEAL_ENTRY_OUT"; break;
                case DEAL_ENTRY_STATE:
                    dealEntryName = "DEAL_ENTRY_STATE"; break;
                default:
                    dealEntryName = "UNKNOWN";
                    
            }
            Print("Deal (", trans.deal, ") entry : ", dealEntryName);
            if (dealEntry == DEAL_ENTRY_OUT) {
                double price=HistoryDealGetDouble(trans.deal,DEAL_PRICE);
                double profit=HistoryDealGetDouble(trans.deal,DEAL_PROFIT);
                Print(StringFormat("deal price=%.5f profit=%.2f",price,profit)); /// zero zero
            }
        }
    }
}   
HongDi s& t development co.,ltd.
1602
hongbin fei  
thanks man!
To add comments, please log in or register