FORTS: OnTradeTransaction() return codes - page 7

 
Михаил:

The thing is that when an order is being executed, you don't control its execution and therefore you don't block OnTick() or OnBookEvent().

You need to handle the trade event in OnTradeTransaction() to quickly control the order being executed.

I will post the code on how to do it soon.

Hm. I'll have to think about it, thanks!
 
Alexey Kozitsyn:
Ahem. I'll have to think about it, thanks!
#property copyright "Copyright 2015, Mikalas"
#property link      "https://www.mql5.com"
#property version   "1.00"
//
bool is_busy;
//
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
  is_busy = false;
  return( INIT_SUCCEEDED ); 
}
//----------------------------
void OnBookEvent( const string &a_symbol ) 
{
  if ( ( a_symbol == _Symbol ) && ( !is_busy ) )
  {
    //Работаем дальше
  }
}  
//------------
void OnTradeTransaction( const MqlTradeTransaction &trans, const MqlTradeRequest &request, const MqlTradeResult &result )
{
  switch( trans.type )
  {
    case TRADE_TRANSACTION_DEAL_ADD: if ( trans.order_state == ORDER_STATE_STARTED )
                                     {
                                       is_busy = true;
                                       //Обнуляем билет этого ордера, если одер залился полностью
                                       is_busy = false;
                                     }
                                     break; 
                                          
  }
}  
 

Or rather:

#property copyright "Copyright 2015, Mikalas"
#property link      "https://www.mql5.com"
#property version   "1.00"
//
bool is_busy;
ulong order_ticket;
//
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
  is_busy = false;
  return( INIT_SUCCEEDED ); 
}
//----------------------------
void OnBookEvent( const string &a_symbol ) 
{
  if ( ( a_symbol == _Symbol ) && ( !is_busy ) )
  {
    //Работаем дальше
  }
}  
//------------
void OnTradeTransaction( const MqlTradeTransaction &trans, const MqlTradeRequest &request, const MqlTradeResult &result )
{
  switch( trans.type )
  {
    case TRADE_TRANSACTION_DEAL_ADD: if ( trans.order_state == ORDER_STATE_STARTED )
                                     {
                                       if ( result.order == order_ticket )
                                       { 
                                         is_busy = true;
                                         //Обнуляем билет этого ордера, если одер залился полностью
                                         is_busy = false;
                                       }  
                                     }
                                     break; 
                                          
  }
}
 
Михаил:
I see, but there are doubts that this construction will block OnBookEvent(). The glass change event can run in bunches, after all. I'll check it out, thanks again.
 
Alexey Kozitsyn:
I see, but there are doubts that this construction will block OnBookEvent(). The glass change event can run in bunches, after all. I will check it, thanks again.
Have any doubts - don't use the tip, but I had the same thing as you, until I put a "prop".
 
Михаил:
Have any doubts - don't use the advice, but I had the same thing as you until I put a "backstop" in place.
No, it is an interesting idea and the longer an order takes to execute, the better it will work. In my case, both order execution and its deletion took one ms. We will have to check the Expert Advisor's logic as well.
 
Alexey Kozitsyn:
No, it is an interesting idea and the longer an order takes to execute, the higher its quality will be. In the case I cited, both order execution and order deletion took place within the same ms. We should also check the Expert Advisor's logic.
https://www.mql5.com/ru/forum/16832
ФОРТС Отмена ордера в момент его исполнения [что приходит раньше - BookEvent или TradeEvent]
ФОРТС Отмена ордера в момент его исполнения [что приходит раньше - BookEvent или TradeEvent]
  • www.mql5.com
OnBookEvent срабатывает раньше, чем OnTradeTransAction. - - Категория: автоматические торговые системы
 
Alexey Kozitsyn:
OrderSend(). What's the difference in this case?
In the implementation of the "backstop"
 
Михаил:

That's more accurate:

Not truer.

The last two parameters request and result are filled with values only for transaction type TRADE_TRANSACTION_REQUEST, information about the transaction can be obtained from the type parameter of the trans variable .

 
Alexey Kozitsyn:

Not truer.

I have written myself down, of course trans.order
Reason: