How to deal with server disconnection in EA

 

The following are my two questions. I haven't found good answers in the historical records. Does anyone know?

1.How can the EA get a information when sever is disconnected.I found that the server of the broker was disconnected sometimes, and it will reconnect in a few seconds. This situation can lead to some problems. So I need to refresh my EA when the EA is disconnected and reconnected.

2.When the sever is reconnected, does OnInit() work?

 
  1. OnInit is not called.
  2. If there is a disconnection, whatever server call you were doing will return an error. Log it, return, wait for a new tick. Now you are connected, verify whether the operation succeeded, or retry.
 
William Roeder #:
  1. OnInit is not called.
  2. If there is a disconnection, whatever server call you were doing will return an error. Log it, return, wait for a new tick. Now you are connected, verify whether the operation succeeded, or retry.

Thank you, William Roeder. And is there a sever call you suggest?  Which I mean the one that will not prolong a lot of testing time in tester.  RafreshRates can be used in this case?


 
Jia Run Yuan #: Thank you, William Roeder. And is there a sever call you suggest?  Which I mean the one that will not prolong a lot of testing time in tester.  RafreshRates can be used in this case?

There are no suggested server calls.

William is referring to any and all operations underway in your code at the time the disconnect occurs, such as placing an order, or modifying a trailing stop, etc.

You have to monitor those operations and detect when an error occurs and handle the situation accordingly.

 
Fernando Carreiro #:

There are no suggested server calls.

William is referring to any and all operations underway in your code at the time the disconnect occurs, such as placing an order, or modifying a trailing stop, etc.

You have to monitor those operations and detect when an error occurs and handle the situation accordingly.

OK, thank you. I have new insights. Let me try.

Reason: