Is it possible to add an init reason similar to uninit/DeInit reason for TEMPLATE ( reason = 7)?

 

I have a special situation...

In an indicator I create a Fibo Object... I want to allow the indicator that is creating the Fibo object to be added multiple times on the chart and that fact forces me to add an index to the Fibo object name in the Init() function for the indicator.

Everything is working fine adding or removing the indicator from the chart but if I save a template containing the indicator it seems to me that the objects saved in the template are first created and after that also the Init() of the indicator is checked...

In Init() for the indicator I have code something like this:

   for(int NoFibos=1; NoFibos<=10; NoFibos++)

     {   

         FiboName="FiboObj"+IntegerToString(NoFibos);

         if(ObjectFind(0,FiboName) < 0)

         { 

            break;

         }

   }

    ... Create the object with the name FiboName...

 

So in my scenario, I add the indicator once, "FiboObj1" object is created and I save it in a template. When I re-load the template,  "FiboObj1" is already found using my code above in the Init() function and the "FiboObj2" is created having now 2 Fibo objects instead of only one as I had when saved the template.

And Yes, my DeInit() function has code to remove all objects and it is working properly removing the objects. 

 

 

Thank you. 

 
Gheorghe Cosoveanu:

I have a special situation...

In an indicator I create a Fibo Object... I want to allow the indicator that is creating the Fibo object to be added multiple times on the chart and that fact forces me to add an index to the Fibo object name in the Init() function for the indicator.

Everything is working fine adding or removing the indicator from the chart but if I save a template containing the indicator it seems to me that the objects saved in the template are first created and after that also the Init() of the indicator is checked...

In Init() for the indicator I have code something like this:

   for(int NoFibos=1; NoFibos<=10; NoFibos++)

     {   

         FiboName="FiboObj"+IntegerToString(NoFibos);

         if(ObjectFind(0,FiboName) < 0)

         { 

            break;

         }

   }

    ... Create the object with the name FiboName...

 

So in my scenario, I add the indicator once, "FiboObj1" object is created and I save it in a template. When I re-load the template,  "FiboObj1" is already found using my code above in the Init() function and the "FiboObj2" is created having now 2 Fibo objects instead of only one as I had when saved the template.

And Yes, my DeInit() function has code to remove all objects and it is working properly removing the objects. 

 

 

Thank you. 

When we save a new template, it saves also all the objects present in the chart and present on every sub-window.

Edit the template after saving it, and remove those objects. 

Next time you load the template, the objects will not be created, thus allowing your indicator to create them correctly.

 
Gheorghe Cosoveanu:

I have a special situation...

In an indicator I create a Fibo Object... I want to allow the indicator that is creating the Fibo object to be added multiple times on the chart and that fact forces me to add an index to the Fibo object name in the Init() function for the indicator.

There is no such macro for initialization reason, try using

https://www.mql5.com/en/docs/chart_operations/chartindicatorname

Documentation on MQL5: Chart Operations / ChartIndicatorName
Documentation on MQL5: Chart Operations / ChartIndicatorName
  • www.mql5.com
[in]  the index of the indicator in the list of indicators. The numeration of indicators start with zero, i.e. the first indicator in the list has the 0 index. To obtain the number of indicators in the list use the ChartIndicatorsTotal() function. Do not confuse the indicator short name and the file name that is specified when creating an...
Reason: