best way of checking if anMQL5 indicator is on the chart from EA OnInit()

 

What is the best way of checking if a required indicator is on the chart before proceeding?

I was looking along these lines but I am struggling to find a better function to do the job that ObjectsTotal() ?

int objectsTotal = ObjectsTotal();



bool customIndicatorFound = false;



for (int i = 0; i < objectsTotal; i++)

{

    string objectName = ObjectName(i);



    if (StringFind(objectName, "MyCustomIndicator") >= 0)

    {

        customIndicatorFound = true;

        break;

    }

}



if (!customIndicatorFound)

{

    // Custom indicator not found, display error message and quit

    Alert("Custom indicator MyCustomIndicator not found on the chart");

    return;

}
Step on New Rails: Custom Indicators in MQL5
Step on New Rails: Custom Indicators in MQL5
  • www.mql5.com
I will not list all of the new possibilities and features of the new terminal and language. They are numerous, and some novelties are worth the discussion in a separate article. Also there is no code here, written with object-oriented programming, it is a too serous topic to be simply mentioned in a context as additional advantages for developers. In this article we will consider the indicators, their structure, drawing, types and their programming details, as compared to MQL4. I hope that this article will be useful both for beginners and experienced developers, maybe some of them will find something new.
 
Alain Verleyen #: SOLVED!

I did it myself but I am sure others will want to know so here it is:

int iIndicatorCount =0;   
int totalIndicators = ChartIndicatorsTotal(0,0);
for(int i=0; i<totalIndicators; i++) {
    string indicatorName = ChartIndicatorName(0,0,i);
    if ((indicatorName == "My Funny Indicator") || (indicatorName == "His Funnier Indicator"))
      iIndicatorCount ++;
}

if (iIndicatorCount < 2) {
   Alert ("Two funny indicators are required");
   return ERROR;
}
Reason: