Big trouble

 

Hello everybody,

here is simply test codes for an indicator, 

#property indicator_chart_window
#property indicator_plots               0
#property indicator_buffers             0
string shortname;

int OnInit(void)
{
   shortname="aaa";
   IndicatorSetString(INDICATOR_SHORTNAME,shortname);
   
   Comment("bbb");
   return(INIT_SUCCEEDED);
}

void OnDeinit(const int reason)
{
   Comment("---");
   Print("reason: ",reason);
}

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
{
   int sn=ChartIndicatorGet(0,0,shortname);
   if(sn==INVALID_HANDLE)Print("fff");
   return(rates_total);
}

void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{
}

you can put it in a chart as indicator, but when you remove it from chart, the string "fff" comes up as loop, it don't stop even the chart was closed !! What's wrong of it? Is it a bug?

Thank you for reply.

 
The build is 1950
 

After using the indicator handle you should release it like this:

   int sn=ChartIndicatorGet(0,0,shortname);
   if(sn==INVALID_HANDLE)
      Print("fff");
   else
      IndicatorRelease(sn);
 
Ilyas:

After using the indicator handle you should release it like this:

Right but a ghost indicator in a managed environment is a bug. Isn't ?
 
Alain Verleyen:
Right but a ghost indicator in a managed environment is a bug. Isn't ?
It is reference to itself
It has been manualy removed from the chart but it still working in symbol thread because it has one active reference to itself
This is the reason why ChartIndicatorGet returns error (indicator is absent on the chart)

Who should remove reference ?
 
Alain Verleyen:
Right but a ghost indicator in a managed environment is a bug. Isn't ?

Well, the documentation does say you must remove it when you are done using it.

(from https://www.mql5.com/en/docs/chart_operations/chartindicatorget)

//--- You should obligatorily release the indicator handle when it is no longer needed
IndicatorRelease(handle);
 
Alain Verleyen:
Right but a ghost indicator in a managed environment is a bug. Isn't ?

I use this ghost-mode.

 
OK, we can use IndicatorRelease(handle) to stop the ghost indicator but it is not be killed, it block us to use OnInit() and OnDeinit() from that time. Put indicator to chart again then you can know that.
 

Ilyas:
It is reference to itself
It has been manualy removed from the chart but it still working in symbol thread because it has one active reference to itself
This is the reason why ChartIndicatorGet returns error (indicator is absent on the chart)

I know.

Who should remove reference ?

It is a bug in the mql code of course.

The problem is if I am using someone else ex5 and such error arise, I am stuck with it.

MT5 platform should manage it, the same way you don't allow array out of range or invalid pointer.

 
If you created some objects in an indicator,  you can't remove them when you delete this indicator manually, I'm saying build 1950
 
Ilyas:

After using the indicator handle you should release it like this:

Perhaps it should be released inside OnDeinit?
Reason: