- error 130
- I don't know why sometimes my indicator freeze !
- Errors, bugs, questions
Hi,
Error 4022 often relates to problems with resources used by the indicator, such as graphical objects or buffers. Make sure you’re properly releasing all resources in your code.
Ensure your OnDeinit function correctly handles all deinitialization reasons. It’s possible that your logic is inadvertently causing the indicator to be removed. Here is a sample structure for your OnDeinit function to capture more information:
void OnDeinit(const int reason)
{
Print("Deinitializing. Reason: ", reason);
switch(reason)
{
case REASON_CHARTCHANGE:
// Specific code for chart change
break;
case REASON_REMOVE:
// Specific code for indicator removal
break;
case REASON_RECOMPILE:
// Specific code for recompilation
break;
// Add other cases if necessary
}
// Release resources
// ...
}
Add additional logs to your system to better understand execution flow
Hi,
Error 4022 often relates to problems with resources used by the indicator, such as graphical objects or buffers. Make sure you’re properly releasing all resources in your code.
Ensure your OnDeinit function correctly handles all deinitialization reasons. It’s possible that your logic is inadvertently causing the indicator to be removed. Here is a sample structure for your OnDeinit function to capture more information:
void OnDeinit(const int reason)
{
Print("Deinitializing. Reason: ", reason);
switch(reason)
{
case REASON_CHARTCHANGE:
// Specific code for chart change
break;
case REASON_REMOVE:
// Specific code for indicator removal
break;
case REASON_RECOMPILE:
// Specific code for recompilation
break;
// Add other cases if necessary
}
// Release resources
// ...
}
Add additional logs to your system to better understand execution flow
This is exactly what i did. I added the logs and that’s how i was able to capture the error 4022 and the fact it gives REASON_REMOVE when it should give REASON_CHARTCHANGE.
Code ?
void OnDeinit(const int reason){ EventKillTimer(); int err = GetLastError(); Print(reason," deinit",err); if(reason!= REASON_CHARTCHANGE){ Print("deleted",reason," ",err);ObjectsDeleteAll(0, prefix);//ChartRedraw(0); } ChartRedraw(0); } 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[]) { return (rates_total); } void OnTimer() { if(IsStopped()) {Print("stopped");return;} //lOAD DATA if(afficherHull){ int c = CopyBuffer(hull, 0, 0, 3000, hma); if(c <= 0){return ;} } if(plusbashautcci){ int end = iBarShift(_Symbol, PERIOD_CURRENT, iTime(_Symbol, PERIOD_D1, lookback+1)); //double cci[]; //ArraySetAsSeries(cci , true); int c = CopyBuffer(handlecci, 0, 0, end+1, cci); if(c != end+1){Print("4 ",c," ",end+1);return ;} } if(fibonacci){ ArraySetAsSeries(h1, true); if(CopyTime(_Symbol, PERIOD_H1, 0, 48, h1) != 48){return ;} } if(croisementh1){ int bshift = iBarShift(_Symbol, PERIOD_H1, iTime(_Symbol, PERIOD_D1, lookback)); int c = CopyBuffer(h_ema5_h1, 0, 0, bshift, ema5_h1) ; int c1 = CopyBuffer(h_ema21_h1, 0, 0, bshift, ema21_h1); if(c != bshift) {return ;} if(c1 != bshift) {Print("6");return ;} } if(croisementm15){ int bshift = iBarShift(_Symbol, PERIOD_M15, iTime(_Symbol, PERIOD_D1, lookback)); int c = CopyBuffer(h_ema5_m15, 0, 0, bshift, ema5_m15) ; int c1 = CopyBuffer(h_ema21_m15, 0, 0, bshift, ema21_m15); if(c != bshift) {Print("8");return ;} if(c1 != bshift) {Print("9");return ;} } if(croisementm5){ int c = CopyBuffer(h_ema5_m5, 0, 0, 500, ema5_m5) ; int c1 = CopyBuffer(h_ema21_m5, 0, 0, 500, ema21_m5); //Print(c," ",c1," "); if(c != 500) {return ; Print("10");} if(c1 != 500) {return ;Print("11");} } MqlRates rates[]; if(pointpivot){ ArraySetAsSeries(rates, true); if(CopyRates(_Symbol, PERIOD_D1, 0, 2, rates) != 2){ Print("7");return ; } } //............ }
something like this
void OnDeinit(const int reason){ EventKillTimer(); int err = GetLastError();
- Capture the error, before calling more functions.
- Where is the log output?
Hey, i did as you asked. but still happens. Here's the result on pic when i tried swithing timeframe. 1 deinit4022 means reason was 1 and error was 4022.
But on other times i will change timeframe and it will give 3 deinit0 so the correct values.
It gives the reason 1 (REASON_REMOVE) but indicator stay on chart when normally for reason 1 (REASON_REMOVE), the indicator should've been removed from the chart. For the logic of my program this cause an issue because the objects that i didn't want deleted when switching timeframes gets deleted because reason doesn't give the correct values sometimes when it is checked in OnDeinit.
![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