Hi,
all important things in the OnInit-routine not be called, if I change the server. Is there another event handler to react on server-change?
Regards
Burkhard
No. There's no event handler for server changing, and what for anyway.
To solve your problem, write OnInit codes in UDF (User Defined Function), if terminal server has change, call this UDF again.
Forget to add : ... and you have to null all value of globally declared variables.
but we can I check the server change?
Use AccountServer(), click that, please. If the server name is not the same like the previous one - perhaps after there's no connection - then the server has change.
//Indicator-Code string ACCOUNT_SERVER_1; void OnInit() { OnInit_UDF(); } int OnCalculate (const int rates_total, const int prev_calculated, const datetime& time[], const double& open[], const double& high[], const double& low[], const double& close[], const long& tick_volume[], const long& volume[], const int& spread[]) { if (ACCOUNT_SERVER_1 == NULL || ACCOUNT_SERVER_1 != AccountInfoString(ACCOUNT_SERVER)) { OnInit_UDF(); } ... } void OnInit_UDF() { ACCOUNT_SERVER_1 = AccountInfoString(ACCOUNT_SERVER); ... } void OnDeinit(const int reason) { ACCOUNT_SERVER_1 == NULL; }
I'll do this, it's pretty much the same though ...
string ACCOUNT_SERVER_1 = ""; // always initialize string variable, otherwise we will get "uninitialize string" error. void OnInit() { OnInit_UDF(); } int OnCalculate (const int rates_total, const int prev_calculated, const datetime& time[], const double& open[], const double& high[], const double& low[], const double& close[], const long& tick_volume[], const long& volume[], const int& spread[]) { if (ACCOUNT_SERVER_1 != AccountInfoString(ACCOUNT_SERVER)) OnInit_UDF(); // no need to check string = NULL, just check if string has different value than before } void OnInit_UDF() { ACCOUNT_SERVER_1 = AccountInfoString(ACCOUNT_SERVER); }
I rarely use OnDeinit, except if there are something need/have to/must to be done before indicator is closed, such as deleting some object on chart, or deleting some object variable that was created using operator new and so need/have to/must be deleted using operator delete.
I'll do this, it's pretty much the same though ...
I rarely use OnDeinit, except if there are something need/have to/must to be done before indicator is closed, such as deleting some object on chart, or deleting some object variable that was created using operator new and so need/have to/must be deleted using operator delete.
I often check UninitializeReason(), how do you set it to REASON_ACCOUNT? When I check UninitializeReason() when the accoun changed there is still whatever but REASON_ACCOUNT. I need it correct.
Please check UninitializeReason() in OnInit().
You can check it anywhere, but I am sure you will never see REASON_ACCOUNT in indicators. This bug has been sitting there since I remember the MT4. I am surprised it is discussed for the first time in years, probably not many indicators depend on the server data directly.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
all important things in the OnInit-routine not be called, if I change the server. Is there another event handler to react on server-change?
Regards
Burkhard