I have a custom indicator I have written. It appears to work - it draws as required in a separate window and displays Print debug information in the Experts tab to show that it is working. If I recompile the indicator it reloads and refreshes as expected. From time to time I suffer from momentary "connection to 'Broker' lost" and when the connection comes back it looks as though the indicator refreshes, but the indicator chart is not redrawn and the Print debug information suggests the summary indicator data has been cleared and not rebuilt. I am hoping to use this indicator as part of an EA that I am writing, and this would be disastrous if I cannot get the indicator to automatically refresh properly after one of these dropped connections. Can anyone suggest a solution for this please?
Hi,,
some information about the help from the compilator mql4 the same for mql5
Check the reason # 6 and get it from the reson const int in OnDeinit() function
after you know in the OnInit() check with a bool (false true) if reson 6 is checked from the OnDeinit() and with true it will refresh your EA
Bye
Laurent
Uninitialization Reason Codes
Uninitialization reason codes are returned by the UninitializeReason() function. The possible values are the following:
Constant | Value | Description |
REASON_PROGRAM | 0 | Expert Advisor terminated its operation by calling the ExpertRemove() function |
REASON_REMOVE | 1 | Program has been deleted from the chart |
REASON_RECOMPILE | 2 | Program has been recompiled |
REASON_CHARTCHANGE | 3 | Symbol or chart period has been changed |
REASON_CHARTCLOSE | 4 | Chart has been closed |
REASON_PARAMETERS | 5 | Input parameters have been changed by a user |
REASON_ACCOUNT | 6 | Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings |
REASON_TEMPLATE | 7 | A new template has been applied |
8 | This value means that OnInit() handler has returned a nonzero value | |
REASON_CLOSE | 9 | Terminal has been closed |
The uninitialization reason code is also passed as a parameter of the predetermined function OnDeinit(const int reason).
The codes 1(REASON_REMOVE) and 2(REASON_RECOMPILE) are implemented for the indicators.
Example:
//+------------------------------------------------------------------+ |
Hi,,
some information about the help from the compilator mql4 the same for mql5
Check the reason # 6 and get it from the reson const int in OnDeinit() function
after you know in the OnInit() check with a bool (false true) if reson 6 is checked from the OnDeinit() and with true it will refresh your EA
Bye
Laurent
Uninitialization Reason Codes
Uninitialization reason codes are returned by the UninitializeReason() function. The possible values are the following:
Constant | Value | Description |
REASON_PROGRAM | 0 | Expert Advisor terminated its operation by calling the ExpertRemove() function |
REASON_REMOVE | 1 | Program has been deleted from the chart |
REASON_RECOMPILE | 2 | Program has been recompiled |
REASON_CHARTCHANGE | 3 | Symbol or chart period has been changed |
REASON_CHARTCLOSE | 4 | Chart has been closed |
REASON_PARAMETERS | 5 | Input parameters have been changed by a user |
REASON_ACCOUNT | 6 | Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings |
REASON_TEMPLATE | 7 | A new template has been applied |
8 | This value means that OnInit() handler has returned a nonzero value | |
REASON_CLOSE | 9 | Terminal has been closed |
The uninitialization reason code is also passed as a parameter of the predetermined function OnDeinit(const int reason).
The codes 1(REASON_REMOVE) and 2(REASON_RECOMPILE) are implemented for the indicators.
Example:
//+------------------------------------------------------------------+ |
Hello, and thank you so much for your reply - I did not know about the Uninitialization Codes.
As I worked through this, I found when the connection drops and resets, the indicator OnDeinit and OnInit functions do not actually get called.
This lead me to a deeper trace, and in the end I found that I was initializing my indicator buffers (hence the data was reset) but there were a couple of variables I was not re-initialising - they were only initialised in the OnInit function.
The result was that the buffers were re-initialised but then not recalculated as the other variables hadn't been reset.
So thank you again - you caused me to dig deeper (and in the right place) and to find the solution.
Regards,
Matt.
Hello, and thank you so much for your reply - I did not know about the Uninitialization Codes.
As I worked through this, I found when the connection drops and resets, the indicator OnDeinit and OnInit functions do not actually get called.
This lead me to a deeper trace, and in the end I found that I was initializing my indicator buffers (hence the data was reset) but there were a couple of variables I was not re-initialising - they were only initialised in the OnInit function.
The result was that the buffers were re-initialised but then not recalculated as the other variables hadn't been reset.
So thank you again - you caused me to dig deeper (and in the right place) and to find the solution.
Regards,
Matt.
that is a loop : OnInit->OnCalculate->OnDeinit->....... those are in the loop and can't be modified. it is like you make your own function, but here all is ready to go.
It is well and not so well. One thread only and before the loop go to the end some function will have to wait for.
You have to try how really the OnInit and OnDeinit work , I got some problems with that in my prog ccanvas clock. there are very strange thing about how to the OnDeinit and OnInit work......
I give you my code if you want to read it may be some parts should be interesting for you.
your welcome, have a nice day :))
Laurent
I have an indicator, which I wish to refresh at a particular time every day.
Is there a way to do it?
Thanks
Rinku
- Deinit is called only for the reasons listed. Connection lost is not one of them. On reconnect, history is updated, then indicator is called with prev_calculated being zero.
- Indicator shouldn't need to be refreshed, ever. You are not properly initializing it when prev_calculated is zero.
- Changing the chart symbol or TF or indicators parameters will result in a deinit/indicator reload/init cycle.Global and static variables work exactly the same way in MT4/MT5/C/C++.
- They are initialized once on program load.
- They don't update unless you assign to them.
- In C/C++ you can only initialize them with constants, and they default to zero.
-
In MTx you should only initialize them with constants.
There is no default
in MT5 or (MT4 with strict which
you should always use.)
MT4/MT5 actually compiles with non-constants, but the order that they are initialized is unspecified and don't try to use any price or server related functions in OnInit (or on load,) as there may be no connection/chart yet:
- Terminal starts.
- Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
- OnInit is called.
- For indicators OnCalculate is called with any existing history.
- Human may have to enter password, connection to server begins.
- New history is received, OnCalculate called again.
- New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
-
Unlike indicators, EAs are not reloaded on chart change so you must
reinitialize them, if necessary.
external static variable - Inflation - MQL4 programming forum
- Right click → Refresh will not. History updates and prev_calculated is zero.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have a custom indicator I have written. It appears to work - it draws as required in a separate window and displays Print debug information in the Experts tab to show that it is working. If I recompile the indicator it reloads and refreshes as expected. From time to time I suffer from momentary "connection to 'Broker' lost" and when the connection comes back it looks as though the indicator refreshes, but the indicator chart is not redrawn and the Print debug information suggests the summary indicator data has been cleared and not rebuilt. I am hoping to use this indicator as part of an EA that I am writing, and this would be disastrous if I cannot get the indicator to automatically refresh properly after one of these dropped connections. Can anyone suggest a solution for this please?