how to delete object after close custom indicator? - page 2

 
Oh. Well I was referring to the fact, he is using ObjectDelete inside an EA, deleting Objects from another Indicator, not specifically referring to a custom indicator to which he has the handle available within the EA....

So, yes, it could mislead when stating "... see on screen".

Sorry for the confusion.

Edit:
Besides the code being inside the indicator creating the objects itself. The intention was more in pointing to the whole concept of ChartID and windows in general.

A bridge to far, I assume in hindsight.
 
OnDeinit will queue your requests and processing will be done later.

In fact it is also OnDeinit call itself which gets queued, so you will see a delay in execution.
 
  int qq=0;
   if(reason == 1)
     {
       while(ObjectFind(0,"Line"+IntegerToString(qq)) >=0)
        {
       
          ObjectDelete(0,"Line"+IntegerToString(qq));
         qq++;
        }
     }
     ChartRedraw(0); 

Your code assumes that there will always be an object named "Line0".

If there isn't the code will not be executed.

Also anytime the object is not found the loop will exit. So if there is not an object named "Line4", "Line5" etc will not be deleted.

You would be better off to use

   if(reason == 1)
     {
      ObjectsDeleteAll(0,"Line");
     }
     ChartRedraw(0); 
 
Keith Watford:

Your code assumes that there will always be an object named "Line0".

If there isn't the code will not be executed.

Also anytime the object is not found the loop will exit. So if there is not an object named "Line4", "Line5" etc will not be deleted.

You would be better off to use

thank you this is the easiest way and worked.

but still is worked only when indicator close from H1 time frame and if indicator close from another one the object still remain.

I do not understand why this is happand.
 
May I know your findings around ChartID?
 
justlink:

but still is worked only when indicator close from H1 time frame and if indicator close from another one the object still remain.

It should make no difference what the chart time-frame is when the indicator is deleted.

If the objects are not being removed then they are not named beginning with "Line"

 
Dominik Egert:
May I know your findings around ChartID?

Thank you for Advice. I read that Articles, But i Said it again. I try my code with ChartID, 0 and Symbol() and nothing different between them. all of the method worked perfectly when i use it in the OnInit or OnCalculate. But When i use in OnDeinit nothing happens and the Object Only remove when i Close my Indicator from H1 Time frame.

 
Keith Watford:

It should make no difference what the chart time-frame is when the indicator is deleted.

If the objects are not being removed then they are not named beginning with "Line"

I know it But not work. one of the attachment image is part of my code create the objects and other for the time i close indicator from D1 time frame. As you can see the Object remain have Line in the name

Files:
1234.png  26 kb
121345.png  41 kb
 
justlink:

I know it But not work. one of the attachment image is part of my code create the objects and other for the time i close indicator from D1 time frame. As you can see the Object remain have Line in the name

Please show the full OnDeinit function that you are currently using. Don't forget to use the code button when pasting code.

Don't edit or change the  OnDeinit function, post it exactly as you are using.

 
Keith Watford:

Please show the full OnDeinit function that you are currently using. Don't forget to use the code button when pasting code.

Don't edit or change the  OnDeinit function, post it exactly as you are using.

void OnDeinit(const int reason)
  {
   
 // int qq=0;
   if(reason == 1)
     {
         
       //while(ObjectFind(0,"Line"+IntegerToString(qq)) >0)
       // {
       //    ObjectDelete(0,"Line"+IntegerToString(qq));
       //  qq++;
       // }
       ObjectsDeleteAll(0,"Line",0,-1);
      
     }
    // qq=0;
     ChartRedraw(0); 
 

  }
Files:
OnDeinit.png  13 kb