Download MetaTrader 5

detect history orders properly in OnTrade

To add comments, please log in or register
chinaski
890
chinaski  

Hello,

i have a problem that i can't get history orders in some situations.

Basically i want to log my orders. For this, in OnTrade, i cycle over latest history: 

 

 

HistorySelect(last_time_query,TimeCurrent());

 

   for(oh=1;oh < HistoryOrdersTotal();oh++)        

        {

            ticket=HistoryOrderGetTicket(oh);

            if(ticket > 0)

            {

                log_my_order(ticket);

            }

        }

last_time_query= TimeCurrent();

 

My Problem:

case a) open order with stop and or target, close order  

            After close order, OnTrade is called and code above reflects history order for close

case b) open order with stop and or target, modify stop and or target,  close order  

After close order, OnTrade is called and code above DOES NOT reflect history order for close 

 

In both cases, i can see history of close order in history panel of MT5 (deals excluded)

 

Anyone has an idea what's going wrong ?

Thank you 

Documentation on MQL5: Trade Functions / HistorySelect
  • www.mql5.com
Trade Functions / HistorySelect - Documentation on MQL5
chinaski
890
chinaski  

no comment from experts ?

Still a bug 

Get in touch with developers using Service Desk!
  • www.mql5.com
We therefore attach great importance to all user reports about issues in our programs and try to answer each one of them.
Pawel Wojnarowski
686
Pawel Wojnarowski  
chinaski:

no comment from experts ?

Still a bug 

Regarding case b) - have you tried to first verify the result of modification? Because in this case, I would expect 2 trade events for OnTrade() to handle:

1. First - the event of modifying the order

2. Second - the  event of closing the order

 

See more in -> https://www.mql5.com/en/articles/232 

Trade Events in MetaTrader 5
  • 2011.02.13
  • MetaQuotes Software Corp.
  • www.mql5.com
A monitoring of the current state of a trade account implies controlling open positions and orders. Before a trade signal becomes a deal, it should be sent from the client terminal as a request to the trade server, where it will be placed in the order queue awaiting to be processed. Accepting of a request by the trade server, deleting it as it expires or conducting a deal on its basis - all those actions are followed by trade events; and the trade server informs the terminal about them.
To add comments, please log in or register