Well this is the code that fails:
I start a script that opens several charts and installs an EA by applying a template.
The EA (just as an example) sets a global variable at OnInit() and than it removes itself with the intention that OnDeinit() delets the global variable of the EA.
//Script void OnStart() { string ChartPair[5] = { "AUDUSD","USDCAD","EURCHF","EURUSD","GBPUSD" } long IDChart[5]; for(c=0;c<5;c++){ IDChart[c] = ChartOpen( ChartPair[c], PERIOD_M1 ); if ( !ChartApplyTemplate( IDChart[c], fTPL ) ) { Comment("ERROR(",_LastError,"): Can't apply Template to [",(string)c,"] ",ChartPair[c],"? Correct and Restart ",WindowExpertName()," - Installation stopped.."); return; } } } //EA: string MyGlobVar; void OnDeinit( const int reason ){ delMyGlobs(); } void delMyGlobs(){ Print("DeInit called by: ",(string)UninitializeReason()); int g = GlobalVariablesTotal(); string gN; while(g>0){g--; gN = GlobalVariableName(g); if ( MyGlobVar == gN ) { Print("GlobalVars ",gN," Delete: ", GlobalVariableDel(gN) ); } } } int OnInit(){ MyGlobVar = "myEA: "+Symbol()+" "+TimeToString(TimeCurrent(),TIME_MINUTES); GlobalVariableSet( MyGlobVar, ChartID()); ExpertRemove(); return( INIT_FAILED ); }
But no global variable is deleted - what do I do wrong or is this not jet 'implemented' ??
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
If my EA is stopped I want it to delete all its global variables!
If I start the debugger the glob.vars are set but nothing is deleted if I stop the debugger:
As the initial Print is not printing and nothing is deleted I must assume DeInit() is not called and is not working at least in the debugger?
Beside that another question:
Due to the function call of DeInit();
How shall I use DeInit() that the ea deletes its glob.-vars by any reason the ea stops or is removed and the OnInit()- function will be called if re-started (is there a temporary stop of an EA?)?
Second if I stop the debugger I have these two line in the expert tab:
What does this now mean after the EA in debug-mode was stopped?