Search code examples
mql4forex

How to tell if you are filled in MQL4 order?


I can't for the life of me how to tell if a pending order that has been sent and you have gotten a valid ticket, is filled in MQL4

http://book.mql4.com/trading/index

Is there a callback or, does a script have to continuously poll somehow?


Solution

  • No.

    Neither the Broker/Terminal ecosystem, nor the MQL4 language provide a callback once a Pending Order meets the Market Price and converts into a Trade.

    Yes.

    One may opt to either poll the dbPool of records in MT4/Terminal in a rather dumb manner alike a loop

    int trades_total = OrdersTotal();
    
    for ( int i = 0; i < trades_total; i++ ) {
          OrderSelect( i, SELECT_BY_POS, MODE_TRADES );
          if (       OrderSymbol() == Symbol()
             && OrderMagicNumber() == Magic
             && (      OrderType() == OP_BUYSTOP
                ||     OrderType() == OP_BUY
                )
             ) { ...
    

    or one may create / store / maintain one's own DMA-alike bag ( array ) of record-numbers ( used as somewhat like pointers ) and associated Order attributes, which can mediate both direct access/modification ( without a prior dbPool OrderSelect() ).

    The real-time maintenance an use of such an immense bag-of-records was tested as doable for low intensity HFT with hundreds thousands of active Orders ( which would be impractical to have to get handled via dbPool OrderSelect()/Order*() instrumentation ( the less in Strategy Tester multicriterial optimisation mode ).