Indicator don't delete obbject.

To add comments, please log in or register
80613536
75
80613536  

Hi guys, My indicator create a lot of trend line (that are the same of Hline) and for every trend line create a EventChartCustom with the conditions their delete. But the code don't make your goal. Can you help me please. here there is my code:

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {

//---

      


    Controlla_Nuova_Barra();

 


   if(Contaciclo==0){

      ArrayInitialize(GlitchBuffer,0);

      NB=rates_total-5;

   }

    if(Conta_Barre>1){

       Controlla_Glitch="Si";

    }   


    

//--- calculation

    if(New_Bar==true){


       Rileva_Glitch(rates_total,prev_calculated,high,low,close,volume,time,open,GlitchBuffer);


       i=0;

       Contaciclo=Contaciclo+1;

    }   

   return(rates_total);

  }

//+------------------------------------------------------------------+

//+------------------------------------------------------------------+ 

//| Calculating indicator values                                     | 

//+------------------------------------------------------------------+

void Rileva_Glitch(int rates_total,int prev_calculated,const double &high[],const double &low[],const double &close[],const long &volume[],const datetime &time[],const double &open[],double &buffer[]){

//     Qnt_Symb=FileWrite(FileOUT," rileva glitch 1 i ", i);    /// volume[i] ", volume[i], " volume[i-1] ", volume[i-1], " volume[i+1] ", volume[i+1], " i ", i);

     

     

     if(Contaciclo>0){ 

//        invia="Si";

       

        NB=3;

     }


     ArraySetAsSeries(high,true);


     ArraySetAsSeries(low,true);


     ArraySetAsSeries(close,true);

     ArraySetAsSeries(volume,true);


     ArraySetAsSeries(open,true);


     ArraySetAsSeries(buffer,true);

//     Qnt_Symb=FileWrite(FileOUT," rileva glitch 2 i ", i , " start_index ", start_index);

     for(i=NB; i>0; i--){  

//           Qnt_Symb=FileWrite(FileOUT,"ciclo for rileva glitch 3 i ", i, " start_index ", start_index, "volume[i] ", Volume[i], " volume[i-1] ", Volume[i-1], " volume[i+1] ", Volume[i+1], " ", TimeToString(time[i],TIME_MINUTES));

           

          if(i>0 && Volume[i]>=Volume[i-1]+(Volume[i]*MMV) && Volume[i]>Volume[i+1]+(Volume[i]*MMV)){


              Cerca_Gap(rates_total, prev_calculated, high, low, close, volume, time, open);

    }  

//     Qnt_Symb=FileWrite(FileOUT," fine ciclo for rileva glitch 3 i ", i, " start_index ", start_index, "volume[i] ", Volume[i], " volume[i-1] ", Volume[i-1], " volume[i+1] ", Volume[i+1], " ", TimeToString(time[i],TIME_MINUTES));    

  }


 




void Cerca_Gap(int rates_total, int prev_calculated, const double &high[], const double &low[], const double &close[], const long &volume[], const datetime &time[], const double &open[]){

//     Qnt_Symb=FileWrite(FileOUT," Inizio cerca gap contaglitch  ", Conta_Glitch, " ObjectTotal ", ObjectsTotal(), " CHARTEVENT_CUSTOM ", CHARTEVENT_CUSTOM, " ContaGap ", ContaGap, " i ", i, " ", TimeToString(time[i],TIME_DATE), " ", TimeToString(time[i],TIME_MINUTES));

//     Qnt_Symb=FileWrite(FileOUT," Inizio high[i] ",high[i]," low[i-1] ", low[i-1], " high[i-1] ", high[i-1], " low[i] ", low[i], " close[i] ", close[i], " open[i] ", open[i], " close[i-1] ", close[i-1], " open[i-1] ", open[i-1]," close[i+1] ", close[i+1], " open[i+1] ", open[i+1]);

    int CustomEvent_ID;

    

    if(low[i-1]>high[i]){

      TG=high[i];

      Colore="clrGreen";

      Stile=3;

       Qnt_Symb=FileWrite(FileOUT,"1 creaaOBJ  OpenI ", open[i], " CloseI ", close[i], " highI-1 ", high[i-1], " lowI-1 ", low[i-1]);

      Crea_OBJ(rates_total, prev_calculated, high, low, close, volume, time, open);

      ContaGap=ContaGap+1;

      OBJNC2=Conta_Glitch;

      CustomEvent_ID=CHARTEVENT_CUSTOM+ContaGap;

//      Qnt_Symb=FileWrite(FileOUT,"1 customEvent_ID ",CustomEvent_ID, "CustomEvent_ID-CARTEVENT_cUSTOM ",CustomEvent_ID - CHARTEVENT_CUSTOM);

     

              if(!EventChartCustom(0,CustomEvent_ID-CHARTEVENT_CUSTOM,1,high[i],OBJNC2)){ 

                 Qnt_Symb=FileWrite(FileOUT," 1 Errore creazione evento getlasterror ", GetLastError(), " OBJNC2 ", OBJNC2, " CustomEvent_ID ", CustomEvent_ID);

              }else

              {

                Qnt_Symb=FileWrite(FileOUT," 1 creazione evento OBJNC1 ", OBJNC1, "  ", TimeToString(DataBarraD1,TIME_DATE), " ",TimeToString(DataBarraD1,TIME_SECONDS), " CustomEvent_ID ", CustomEvent_ID); 

              }    

          


//      OBJNC1=Conta_Glitch;

      TG=low[i-1];

      Qnt_Symb=FileWrite(FileOUT,"2 creaaOBJ  OpenI ", open[i], " CloseI ", close[i], " highI-1 ", high[i-1], " lowI-1 ", low[i-1]);

      Crea_OBJ(rates_total, prev_calculated, high, low, close, volume, time, open);

      ContaGap=ContaGap+1;

      OBJNC2=Conta_Glitch;

      CustomEvent_ID=CHARTEVENT_CUSTOM+ContaGap;

//      Qnt_Symb=FileWrite(FileOUT,"2 customEvent_ID ",CustomEvent_ID, "CustomEvent_ID-CARTEVENT_cUSTOM ",CustomEvent_ID - CHARTEVENT_CUSTOM);

      

              if(!EventChartCustom(0,CustomEvent_ID-CHARTEVENT_CUSTOM,1,low[i-1],OBJNC2)){ 

                 Qnt_Symb=FileWrite(FileOUT,"2 Errore creazione evento getlasterror ", GetLastError(), " OBJNC2 ", OBJNC2, " CustomEvent_ID ", CustomEvent_ID);

              }else

              {

                Qnt_Symb=FileWrite(FileOUT," 2 creazione evento OBJNC1 ", OBJNC2, "  ", TimeToString(DataBarraD1,TIME_DATE), " ",TimeToString(DataBarraD1,TIME_SECONDS), " CustomEvent_ID ", CustomEvent_ID); 

              }    

          

//      OBJNC2=Conta_Glitch;

//      Prezzo_Target=low[i-1];

//      AttualizzaEvento();

//    Il gap precedente si chiude quando il prezzo raggiunge il low[i-1] e deve cancellare due obj

      }

      

    if(high[i-1]<low[i]){

      TG=high[i-1];

      Colore="clrGreen";

      Stile=3;

      Qnt_Symb=FileWrite(FileOUT,"3 creaaOBJ  OpenI ", open[i], " CloseI ", close[i], " highI-1 ", high[i-1], " lowI-1 ", low[i-1]);

      Crea_OBJ(rates_total, prev_calculated, high, low, close, volume, time, open);

      ContaGap=ContaGap+1;

      OBJNC2=Conta_Glitch;

      CustomEvent_ID=CHARTEVENT_CUSTOM+ContaGap;

//      Qnt_Symb=FileWrite(FileOUT,"3 customEvent_ID ",CustomEvent_ID, "CustomEvent_ID-CARTEVENT_cUSTOM ",CustomEvent_ID - CHARTEVENT_CUSTOM);

     

              if(!EventChartCustom(0,CustomEvent_ID-CHARTEVENT_CUSTOM,0,high[i-1],OBJNC2)){ 

                 Qnt_Symb=FileWrite(FileOUT,"3 Errore creazione evento getlasterror ", GetLastError(), " OBJNC2 ", OBJNC2, " CustomEvent_ID ", CustomEvent_ID);

              }else

              {

                Qnt_Symb=FileWrite(FileOUT,"3 creazione evento OBJNC1 ", OBJNC2, "  ", TimeToString(DataBarraD1,TIME_DATE), " ",TimeToString(DataBarraD1,TIME_SECONDS), " contaGap ", ContaGap, " CustomEvent_ID ", CustomEvent_ID); 

              }    

           

      

//      OBJNC1=Conta_Glitch;

      TG=low[i];

      Qnt_Symb=FileWrite(FileOUT,"5 creaaOBJ  OpenI ", open[i], " CloseI ", close[i], " highI-1 ", high[i-1], " lowI-1 ", low[i-1]);

      Crea_OBJ(rates_total, prev_calculated, high, low, close, volume, time, open);

      ContaGap=ContaGap+1;

      OBJNC2=Conta_Glitch;

      CustomEvent_ID=CHARTEVENT_CUSTOM+ContaGap;

//      Qnt_Symb=FileWrite(FileOUT,"4 customEvent_ID ",CustomEvent_ID, "CustomEvent_ID-CARTEVENT_cUSTOM ",CustomEvent_ID - CHARTEVENT_CUSTOM);

      

              if(!EventChartCustom(0,CustomEvent_ID-CHARTEVENT_CUSTOM,0,low[i],OBJNC2)){ 

                 Qnt_Symb=FileWrite(FileOUT,"4 Errore creazione evento getlasterror ", GetLastError(), " OBJNC2 ", OBJNC2, " CustomEvent_ID ", CustomEvent_ID);

              }else

              {

                Qnt_Symb=FileWrite(FileOUT,"4 creazione evento OBJNC1 ", OBJNC2, "  ", TimeToString(DataBarraD1,TIME_DATE), " ",TimeToString(DataBarraD1,TIME_SECONDS), " contaGap ", ContaGap, " CustomEvent_ID ", CustomEvent_ID); 

              }    

           

//      OBJNC2=Conta_Glitch;

//      As=high[i-1];

//      Attualizza_Evento();

//    Il gap precedente si chiude quando il prezzo raggiunge high[i-1] e deve chiudere due obj      

      }  


// if di controllo

//    if(TimeToString(time[i],TIME_MINUTES)=="14:35"){

//      Qnt_Symb=FileWrite(FileOUT,"5 if prima creazione blu close[i] ", close[i], " open[i] ", open[i], " high[i-1] ", high[i-1], " low[i-1] ", low[i-1]);  

//      }

    if((close[i]>high[i-1] && close[i]<=open[i]) || (close[i]<low[i-1] && close[i]>open[i])){

//      Qnt_Symb=FileWrite(FileOUT,"5 creazione blu  ");

      TG=close[i];

      Colore="clrBlue";

      Stile=4;

      Qnt_Symb=FileWrite(FileOUT,"5 creaaOBJ  OpenI ", open[i], " CloseI ", close[i], " highI-1 ", high[i-1], " lowI-1 ", low[i-1]);

      Crea_OBJ(rates_total, prev_calculated, high, low, close, volume, time, open);

      OBJNC1=Conta_Glitch;

      ContaGap=ContaGap+1;

//      Qnt_Symb=FileWrite(FileOUT,"5 creazione evento ChartEvent_cUSTOM ", CHARTEVENT_CUSTOM); 

      CustomEvent_ID=CHARTEVENT_CUSTOM+ContaGap;

//      Qnt_Symb=FileWrite(FileOUT,"5 customEvent_ID ",CustomEvent_ID, "CustomEvent_ID-CARTEVENT_cUSTOM ",CustomEvent_ID - CHARTEVENT_CUSTOM);

      if(close[0]<=open[i]){

           

              if(!EventChartCustom(0,CustomEvent_ID-CHARTEVENT_CUSTOM,0,close[i],OBJNC1)){ 

                 Qnt_Symb=FileWrite(FileOUT,"5 Errore creazione evento getlasterror ", GetLastError(), " OBJNC1 ", OBJNC1, " CustomEvent_ID ", CustomEvent_ID);

              }else

              {

                Qnt_Symb=FileWrite(FileOUT,"5 creazione evento OBJNC1 ", OBJNC1, "  ", TimeToString(DataBarraD1,TIME_DATE), " ",TimeToString(DataBarraD1,TIME_SECONDS), " CustomEvent_ID ", CustomEvent_ID); 

              }    

           

         }else

         {

           

              if(!EventChartCustom(0,CustomEvent_ID-CHARTEVENT_CUSTOM,1,close[i],OBJNC1)){

                 Qnt_Symb=FileWrite(FileOUT,"6 Errore creazione evento getlasterror ", GetLastError(), " OBJNC1 ", OBJNC1, " CustomEvent_ID ", CustomEvent_ID);

              }else

              {

                Qnt_Symb=FileWrite(FileOUT,"6 creazione evento OBJNC1 ", OBJNC1, "  ", TimeToString(DataBarraD1,TIME_DATE), " ",TimeToString(DataBarraD1,TIME_SECONDS), " CustomEvent_ID ", CustomEvent_ID); 

              }    

          

      }   

      

         

//    il gap pecedente viene chiuso quando il prezzo raggiunge high[i-1] oppure low[i-1] e deve cancellare un solo obj.      

    }

//    Qnt_Symb=FileWrite(FileOUT," fine cerca gap contaglitch  ", Conta_Glitch, " ObjectTotal ", ObjectsTotal(), " CHARTEVENT_CUSTOM ", CHARTEVENT_CUSTOM, " ContaGap ", ContaGap, " i ",i ," ", TimeToString(time[0],TIME_MINUTES), " ", TimeToString(time[i],TIME_MINUTES));

}

void Crea_OBJ(int rates_total, int prev_calculated, const double &high[], const double &low[], const double &close[], const long &volume[], const datetime &time[], const double &open[]){

     Conta_Glitch=Conta_Glitch+1;

     Obj_Name=Conta_Glitch;

     Qnt_Symb=FileWrite(FileOUT,"CreaOBJ ", TimeToString(time[i],TIME_DATE), " ", TimeToString(time[i],TIME_MINUTES),  " i ", i, " Close[i] ", close[i], "  CG ", Conta_Glitch, " TG ", TG, " ST ",Stile, " COL ",Colore);

     if(!ObjectCreate(ChartID(),Obj_Name,OBJ_TREND,0,time[i],TG,time[i-1],TG)){

         Qnt_Symb=FileWrite(FileOUT,"Errore creazione oggetto getlasterror ", GetLastError(), " OBJ_Name ", Obj_Name);

         }

     ObjectSetInteger(ChartID(),Obj_Name,OBJPROP_COLOR,Colore); 

     ObjectSetInteger(ChartID(),Obj_Name,OBJPROP_STYLE,Stile);

//     DataBarraD1=iTime(Symbol(),PERIOD_M1,i);

//     DataBarraD1StringMinuti=TimeToString(DataBarraD1,TIME_MINUTES);

//     Qnt_Symb=FileWrite(FileOUT," CreaOBJ i ", i, " Obj_Name ",Obj_Name, " TG ", TG," ", TimeToString(time[i],TIME_DATE), " ",DataBarraD1StringMinuti , " Colore ", Colore, "Stile ", Stile);

//     Qnt_Symb=FileWrite(FileOUT," CreaOBJ i ", i, " Obj_Name ",Obj_Name, " TG ", TG, " ", "  ", TimeToString(time[0],TIME_DATE), " ",  TimeToString(time[0],TIME_MINUTES)); 

     if(TG>AttrattoreMax){

       AttrattoreMax=TG;

     }

     if(TG<AttrattoreMin){

       AttrattoreMin=TG;

     }

    Qnt_Symb=FileWrite(FileOUT," CreaOBJ i ", i, " Obj_Name ",Obj_Name, " TG ", TG, "  ", TimeToString(time[0],TIME_DATE), " ", TimeToString(time[0],TIME_MINUTES), " AttrattoreMax ",AttrattoreMax, "AttrattoreMin ", AttrattoreMin); 








//#include <StopFor000.mqh>


void Controlla_Nuova_Barra()

  {

    New_Bar=false;                              

   if(New_Time!=Time[0])                        

     {

      New_Time=Time[0];                         

      New_Bar=true; 

     Conta_Barre=Conta_Barre+1;                            

//      Qnt_Symb=FileWrite(FileOUT," New_Bar ", New_Bar, " New_Time ", New_Time, " Time[0] ", Time[0]," TotaleOrdini ", TotaleOrdini,  " DataBarraD1 ", DataBarraD1, " DataBarraD1Close ", DataBarraD1Close, " OpenT ", OpenT);

     }

  }

  



void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam){

     Qnt_Symb=FileWrite(FileOUT," OnChartEvent  id", id, " lparam ", lparam, " dparam ", dparam, " Sparam ", sparam, "chartevent custom ", CHARTEVENT_CUSTOM);

  

     

       if(id>CHARTEVENT_CUSTOM){  

         if(lparam==0){

            if(Ask>=dparam){

              if(!ObjectDelete(sparam)){

                 Qnt_Symb=FileWrite(FileOUT,"0 Errore delete oggetto getlasterror ", GetLastError(), " sparam ", sparam);

              }else

              { 

              Qnt_Symb=FileWrite(FileOUT,"0 cancellato oggetto OBJNC1 ",sparam); 

               

              }

           }

       

        }else

        { 

          if(lparam==1){

             if(Bid<=dparam){

               if(!ObjectDelete(sparam)){

                 Qnt_Symb=FileWrite(FileOUT,"1 Errore delete oggetto getlasterror ", GetLastError(), " sparam ", sparam);

               }else

               { 

                Qnt_Symb=FileWrite(FileOUT,"1 cancellato oggetto OBJNC1 ",sparam);  

                

               }

          }      

        } 

     }

   }

   ChartRedraw();

Tank you for all help.

To add comments, please log in or register