Download MetaTrader 5

Handling disconnections

To add comments, please log in or register
coiler
283
coiler  

 

int start()
  {     
   // +---------------------------------------------------------------------------------+
   // | LONG LOGIC                                                                      |
   // +---------------------------------------------------------------------------------+
      bool bullish = false;
     
   // +---------------------------------------------------------------------------------+
   // | SHORT LOGIC                                                                     |
   // +---------------------------------------------------------------------------------+
      bool bearish = false; 
         
   // +---------------------------------------------------------------------------------+
   // | FLAT - NO POSITIONS                                                             |
   // +---------------------------------------------------------------------------------+
   // +---------------------------------------------------------------------------------+
   if( NoOpenPositionsExist(ORDER_COMMENT) ) {
              if( lastTradeTime != Time[0] ) {
                  if( bullish )
                           OpenTrade_function();
                           lastTradeTime = Time[0];
                     }  
                  if( bearish )
                           OpenTrade_function();
                           lastTradeTime = Time[0];
                     }
              }//lastTradeTime     
   }   
   // +---------------------------------------------------------------------------------+
   // | THERE ARE LIVE POSITIONS - MANAGING EXITS                                                       |
   // +---------------------------------------------------------------------------------+
   // +---------------------------------------------------------------------------------+
   else {                                                                  
      //+==================================================+
      //| EXIT 1                                           |
      //+==================================================+
      if ( EXIT3_ENBLD ) {                                  
        
        if( lastTradeTime != Time[0] ) {// Update SL or Exit when new bar
                Exit_update_function1(parameter1, parameter2, parameter3);
                lastTradeTime = Time[0];

        }       
      }      
      //+==================================================+
      //| EXIT 2                                           |
      //+==================================================+
      if ( EXIT3_ENBLD ) {   
        

        if( lastTradeTime != Time[0] ) {        // Update SL or Exit when new bar
                Exit_update_function2(parameter1, parameter2, parameter3);
                lastTradeTime = Time[0];

        }

          
      }
      //+==================================================+
      //| EXIT 3                                           |
      //+==================================================+
      if ( EXIT3_ENBLD ) {                                  

        if( lastTradeTime != Time[0] ) {        // Update SL or Exit when new bar
                Exit_update_function3(parameter1, parameter2, parameter3);
                lastTradeTime = Time[0];

        }

      }                    
   }
   return(0);
  }
Could the most expert coders tell me if my ea flow structure (pseudocode) could be problematic if a mt4 disconnection 
happened?. I was thinking in this scenario:

1. One position is opened.
2. A disconnection occurs.

I manage/update the position (exit or update SL) when new bar appears. I detect that situation with lastTradeTime != Time[0].

But, what if a disconnection occurs and ea reconnects when the next new bar has ticks yet, no update until the next new one? or am i wrong?. EA will not detect the open of the new bar because lastTradeTime will have the date of the bar in progress (when EA reconnects). If i am not wrong, how can i solve this?. I appreciate if you could tell me some improvements or good practices to handle disconnections.

qjol
3243
qjol  

you can  check if there is a connection

TERMINAL_CONNECTED or IsConnected

Ian Venner
2584
Ian Venner  
coiler:

 

Could the most expert coders tell me if my ea flow structure (pseudocode) could be problematic if a mt4 disconnection 
happened?. I was thinking in this scenario:
1. One position is opened.
2. A disconnection occurs.

I manage/update the position (exit or update SL) when new bar appears. I detect that situation with lastTradeTime != Time[0].

But, what if a disconnection occurs and ea reconnects when the next new bar has ticks yet, no update until the next new one? or am i wrong?. EA will not detect the open of the new bar because lastTradeTime will have the date of the bar in progress (when EA reconnects). If i am not wrong, how can i solve this?. I appreciate if you could tell me some improvements or good practices to handle disconnections.

 

The time it took to write that post you could have tested it yourself and already know the answer.

You can write a simple test code;

static datetime TestLastTime = Time[0];

Print("test = ",TestLastTime,"  Time[0] = ",Time[0]);

Attach EA to a 1 minute chart, then disconnect the internet, reconnect it a minute later and see what it prints.

whroeder1
14786
whroeder1  
coiler: But, what if a disconnection occurs and ea reconnects when the next new bar has ticks yet, no update until the next new one? or am i wrong?.
When the terminal reconnects, you'll get a new tick and Time[0] will be different if the disconnection was through end of bar.
Pavel Soukup
560
Pavel Soukup  

Hi guys,

maybe I´m wrong.... but MT4 I need aproximately 30sec than determine situation disconnected. For fast trade - scalp, arbitrage - very very bad!!!  Can you test it...

whroeder1
14786
whroeder1  
endy5: . but MT4 I need aproximately 30sec than determine situation disconnected. For fast trade - scalp, arbitrage - very very bad!!!  Can you test it...
But so does every Internet application. If you want fast access, pay your broker a $million for co-located machine.
Drazen Penic
2580
Drazen Penic  

maybe I´m wrong.... but MT4 I need aproximately 30sec than determine situation disconnected. For fast trade - scalp, arbitrage - very very bad!!!  Can you test it...

 

If you are disconnected, then there is nothing you can do anyway. Know it or don't know it, you can't trade.

If you can't pay high end solution, at least get a backup internet lines via several mobile phone connections.  These are not expensive and setup is not hard.

whroeder1
14786
whroeder1  
drazen64: If you can't pay high end solution, at least get a backup internet lines via several mobile phone connections.
  1. Or run on a VPS that has that redundancy.
  2. But if the problem is near the broker's server, the timeout still exists, because it's the Internet.
  3. You can not do "fast trade - scalp, arbitrage" with the Internet.
coiler
283
coiler  

Thank you all,

very clear the solution. 

Regards. 

To add comments, please log in or register