Init() and DeInit() execution sequence - page 28

 
Alexey Viktorov:
The number of windows is clear, but the number of MA with different parameters how to determine?
You need to query and parse the indicator parameters.
 
Figured it out
int GetShortNames( string &ShortNames[], const long Chart_ID = 0, const int SubWindow = 0 )
{    
  const int Total = ChartIndicatorsTotal(Chart_ID, SubWindow);

  ArrayResize(ShortNames, Total);
  
  for (int i = 0; i < Total; i++)
    ShortNames[i] = ChartIndicatorName(Chart_ID, SubWindow, i);
    
  return(Total);

}

// Возвращает свое "Короткое имя" - ShortName
string GetMyShortName( void )
{  
  string Res = "";
  
  const int SubWindow = ChartWindowFind();
  
  string ShortNames[];

  GetShortNames(ShortNames, 0, SubWindow);
  
  const string TmpShortName = __FUNCSIG__ + (string)MathRand();

  IndicatorSetString(INDICATOR_SHORTNAME, TmpShortName);    

  string NewShortNames[];

  const int Total = GetShortNames(NewShortNames, 0, SubWindow);
  
  for (int i = 0; i < Total; i++)
    if (NewShortNames[i] == TmpShortName)
    {
      Res = ShortNames[i];
      
      IndicatorSetString(INDICATOR_SHORTNAME, Res);
      
      break;
    }
  
  return(Res);
}

// Возвращает свой хэндл
int GetMyHandle( void )
{
  const string ShortName = GetMyShortName();
  
  const string TmpShortName = __FUNCSIG__ + (string)MathRand();  
  
  IndicatorSetString(INDICATOR_SHORTNAME, TmpShortName);

  const int Res = ChartIndicatorGet(0, ChartWindowFind(), TmpShortName);
  
  IndicatorSetString(INDICATOR_SHORTNAME, ShortName);  

  return(Res);
}

It is very important to make an IndicatorRelease of its handle BEFORE OnDeinit.

Interestingly, after each such IndicatorRelease, the indicator handle is incremented by one.

 
fxsaber:
Figured it out

It is very important to make an IndicatorRelease of its handle BEFORE OnDeinit.

Interestingly, after each such IndicatorRelease, the indicator handle is incremented by one.

IndicatorRelease already working in the tester? Just in case - it didn't work before.
 
Andrey Dik:
Is IndicatorRelease working in the tester yet? Just in case - it didn't work before.
Didn't test it.
 
fxsaber:
I haven't tested it.
I mean that the absence of possibility to unload an indicator from the memory in the tester will lead to suspension of the system, if, for example, you optimize indicators by your own means on the fly. Or, for example, changing indicator parameters dynamically will lead to memory overflow, because every time a new handle will be created and the old one won't be deleted in the tester.
 
https://www.mql5.com/ru/code/18138
Init_Sync
Init_Sync
  • 2017.04.17
  • fxsaber
  • www.mql5.com
Библиотека делает синхронизированными Init/Deinit индикаторов
 
good topic
 
Alexberrr:
Good topic

A necessary and relevant one at the moment. I was looking for the cause myself for a long time, thought it was a bug in my code, thanks to this thread the problem has been solved.

Thank you all!

Reason: