Turn ON/OFF my indicator - Can't find a solution

 

Hi everyone,

I'm trying to find a way to turn On/Off my Fibo indicator but I can't find a way to do it properly.
Also when I remove the indicator from chart all the objects they remained there.

For the On/Off button I've tried to add:

extern bool FibRatio = true ;

and modify the int start section like:

int start()
{
  if (FibRatio)
  {
    CreateObj();
  }

  mT1 = iBarShift(NULL, 0, ObjectGet("m.Fib", 0));
  mT2 = iBarShift(NULL, 0, ObjectGet("m.Fib", 2));
  
  if(mT1 < mT2)
  {  
    mT1 = mT2;
    mT2 = iBarShift(NULL, 0, ObjectGet("m.Fib", 0));
  }
  
  mT2 = MathMax(0, mT2 - mLineExtend);
  
  SetFibs();
  
  return(0);
}

This is actually doing something but it's not working as expected.

The second issue I have is that when I remove the indicator from the list, all the objects they stay there.

The only way I've found to delete those objects is with the help of an external script I tweaked so that it deletes only the objects with a precise prefix I wanted.

#property copyright "Copyright © 2017, mrnerd"
#property link      "http://www.techiediaries.com/mql4"

int start()
{
    int totalObjects = ObjectsTotal();
    for (int i = totalObjects - 1; i >= 0; i--)
    {
        string objName = ObjectName(i);
        if (StringFind(objName, "m.Fib") == 0 || StringFind(objName, "m.Lab") == 0)
        {
            ObjectDelete(objName);
        }
    }
    return 0;
}

This is working but it's not ideal.

Does anyone know how could I modify the main code so that I can turn the indicator ON/OFF (without affecting the position of it while navigating through different timeframes) while applied on chart?
Also is there a way to totally remove the Objects from chart when the indicator is deleted from the list of indicators?

Thanks for your help

Files:
FibRatio.mq4  7 kb
 
Simple on/off button can be add to most indicators in 2 seconds lol.
 
Jan4654 #:
Simple on/off button can be add to most indicators in 2 seconds lol.

Thanks for your answer but it's not very helpful.

I thought that was the case too but then things are different than expected.
Have you by any chance tried to add it to the code I provided?

Reason: