Hello, how to cancel and stop same indicator in the same chart ?? :)

 

Hello,

I need help about indicator.

1)  I have an indicator with the name file "test.mq4".

2) I load /link it with a chart EURUSD, all is good

3) now I do the same as before (line 2)

4) I got 2 identical indicators in the same chart

5) question : 

how to stop the second loading before it run ??

I did try with this :

int OnInit()
  {
      
      IndicatorSetString(INDICATOR_SHORTNAME,"efface");
      totalIndicator = ChartIndicatorsTotal(ChartID(),0);
      int count = 0;
      for(int u = 0; u < totalIndicator; u++)
      {
         if(ChartIndicatorName(ChartID(),0,u) == "efface")
         {
            count++;
            if(count > 1)
            { 
              deleteIndicator = 1;
              //ChartIndicatorDelete(ChartID(),0,"efface");
              const int reason = NULL;
          OnDeinit(reason);
            }
         }
      }
      
      
//--- indicator buffers mapping
      EventSetMillisecondTimer(1000);
      f_LabelTexte();
//---
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| OnDeinit function                                                |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
      EventKillTimer();
      Comment("");
      if(!ObjectFind(0, labelID )) ObjectDelete(labelID);
      if(!ObjectFind(0, "PP_1")) ObjectDelete("PP_1");
      if(!ObjectFind(0, "PPJ")) ObjectDelete("PPJ");
     
      if(deleteIndicator == 1) 
      {
      ChartIndicatorDelete(ChartID(),0,"efface");
}
      
  }
//+------------------------------------------------------------------+

It works but I want to keep the first load. with that prog I erase all. the same 2 indicators !!

The trick will be to check before it load in the chart, but  ChartIndicatorsTotal(ChartID(),0);

need the loading before it can update the count + 1

Helps will be very usefull :))

Thanks

laurent

 
boobyditbeber:

Hello,

I need help about indicator.

1)  I have an indicator with the name file "test.mq4".

2) I load /link it with a chart EURUSD, all is good

3) now I do the same as before (line 2)

4) I got 2 identical indicators in the same chart

5) question : 

how to stop the second loading before it run ??

I did try with this :

It works but I want to keep the first load. with that prog I erase all. the same 2 indicators !!

The trick will be to check before it load in the chart, but  ChartIndicatorsTotal(ChartID(),0);

need the loading before it can update the count + 1

Helps will be very usefull :))

Thanks

laurent

Instead of calling OnDeinit you need to 

return INIT_FAILED;
 
nicholi shen:

Instead of calling OnDeinit you need to 

Hello nicholi shen :))

very good trick, tip, extra

I changed some of my prog to check the cancel about the name of the object (are the same of course cause it is the same indicator )

int OnInit()
  {
      
      IndicatorSetString(INDICATOR_SHORTNAME,"efface");
      totalIndicator = ChartIndicatorsTotal(ChartID(),0);
      int count = 0;
      for(int u = 0; u < totalIndicator; u++)
      {
         if(ChartIndicatorName(ChartID(),0,u) == "efface")
         {
            count++;
            if(count > 1)
            { 
              //IndicatorSetString(u-1,"cancel");
              //deleteIndicator = 1;
              //ChartIndicatorDelete(ChartID(),0,"cancel");
              //const int reason = NULL;
          //OnDeinit(reason);
          
          deleteIndicator = 2;
          return(INIT_FAILED);  
            
            }
         }
      }
      
      
//--- indicator buffers mapping
      EventSetMillisecondTimer(1000);
      f_LabelTexte();
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
  
  
//+------------------------------------------------------------------+
//| OnDeinit function                                                |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
    if(deleteIndicator != 2)
    {
      EventKillTimer();
      Comment("");
      if(!ObjectFind(0, labelID )) ObjectDelete(labelID);
      if(!ObjectFind(0, "PP_1")) ObjectDelete("PP_1");
      if(!ObjectFind(0, "PPJ")) ObjectDelete("PPJ");
     }
      if(deleteIndicator == 1) 
      {
      ChartIndicatorDelete(ChartID(),0,"efface");
}
      
  }
//+------------------------------------------------------------------+

Now it is perfect I give the prog in a raw form ,sorry , If you want to try it . put 2 time that file in the same chart and you will see that the daily pivot stay and the count down too

So nice, 

Only thing, if the guy change the name of file between the 2eme load.... I need to erase : IndicatorSetString(INDICATOR_SHORTNAME,"efface"); 

the indicator will take the name of the file, it is better.

you can change the value of the count down up to 60, it is synchronized with PC local Timer, it will count down automaticaly  every step you choiced, 15 for M15 or 10 for M10, no problem when you launch it , the count down is always perfect :)) , first field about indicator properties. it can do more, I need to update that part of the prog :))



thanks for all


laurent