When a disconnection occurs when an EA tries to open an order.

 

When a disconnection occurs when an EA tries to open an order. 

Is there a way to ensure that it would place that last order once connection is established again?

(Regardless of the conditions that were set for the order to be opened in the first place.)

 
johnnybegoode: When a disconnection occurs when an EA tries to open an order. Is there a way to ensure that it would place that last order once connection is established again? (Regardless of the conditions that were set for the order to be opened in the first place.)

Yes, absolutely! An EA should always be coded to be able to recover from a disconnect or even a PC Crash. It should be coded to store its state, and to pick up where it left off, such as a disconnection.

However, you should not just retry the order without reconsidering the new market state. Consider for example, that during the disconnected period, market conditions changed sufficiently that would no longer comply with your original signal criteria and once the connection was reestablished it would be a very bad idea to place the order.

So, I would suggest, that you code your EA, so that in the event of disconnects or crash, that it restart from a known base state and have it reevaluate market conditions and signals (and any open trades), and only then, if still valid, would it proceed with placing the order adjusting for new prices quotes (and/or also manage any open trades accordingly).

 

Lets say the strategy requires me to place that order regardless of the conditions

How to tell the EA to place that order it missed once connection resume. 

 
johnnybegoode: Lets say the strategy requires me to place that order regardless of the conditions. How to tell the EA to place that order once connection resume.

I don't quite get what the exact nature of your difficulty is. Maybe you should show some code so that we can understand what it is that you are having trouble with.

Just monitor (and react to) the normal Checkup points, that you would normally verify during the EA runtime - errors (_LastError), connection (IsConnected), trade context (IsTradeContextBusy), etc.

In other words, you could use a simplistic state machine (or any other appropriate method), to keep track of what has to be done depending on what state the EA is in.

EDIT: Here is a good reference PDF that might help you understand that the difficulty you might be facing is not so much a coding issue, but a basic design (or human thought) issue:

However, if that is too mathematical for you, here are a few links to simpler explanations:

 
      int ticket=OrderSend(Symbol_1,OP_BUY,LongLot,ask,slippage,0,0,"My EA",12345,0,Green);         
      if(ticket>0)
      {
         if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) 
         {
         Print("BUY " ,Symbol_1 ," order opened : ",OrderOpenPrice());
         
         }
      }
         else Print("Error opening BUY " ,Symbol_1 ," order : ",GetLastError());
         return;  

 I receive error 128Trade timeout.

if (int GetLastError() ==  128)

int ticket=OrderSend(Symbol_1,OP_BUY,LongLot,ask,slippage,0,0,"My EA",12345,0,Green); 

 
johnnybegoode: I receive error 128 - Trade timeout.

if (int GetLastError() ==  128)
int ticket=OrderSend(Symbol_1,OP_BUY,LongLot,ask,slippage,0,0,"My EA",12345,0,Green);

"ERR_TRADE_TIMEOUT" is not necessarily a disconnection. However, from your code, I see that it seems that maybe the concept of "state machines" or even "event driven architecture", may be a little beyond your knowledge and experience to be able to implement, so maybe you can just try something a little simpler - maybe you can just code a simple retry loop:

// Please note: Uncompiled and untested!!!

input int
   intRetryCount = 3,   // Order Retry Count
   intSleepTime  = 100; // Retry Sleep Time

...

void someFunction( void )
{
   ...

   int intOrderRetryCount = IsTesting() ? 0 : intRetryCount;
   
   do
   {
      ResetLastError(); // Reset Error Codes
   
      int intTicket = OrderSend(
            _Symbol, intType, dblLots, dblOpenPrice,
            intSlippagePoints, dblStopLossPrice, dblTakeProfitPrice, strComment,
            intMagic, 0, intColour );
   
      if( intTicket != EMPTY ) break;
      
      // Test for various Error codes
      switch( _LastError )
      {
         case ERR_INVALID_STOPS:
            // Do something accordingly in this case
            ...
            // Don't Retry and Exit Loop
            intOrderRetryCount = 0;
            break;
      
         case ERR_TRADE_TIMEOUT:
            // Do something accordingly in this case
            break;
            
         ...
         
         // etc for all Error codes you wish to handle
         
         ...

         default:
            // Do something accordingly in this case
            break;
      }
   
      intOrderRetryCount--;
      if( intOrderRetryCount > 0 ) Sleep( intSleepTime );
   }
   while( intOrderRetryCount > 0 );

   ...
}
Reason: