please how to change or to update a value on Label Object

 

Hello ;

the indicator that I create is to indicate if line 1 > line 2 or line 2 > line 1 for all time frame : as you can see on the picture I would like to know if black line crosses over the red one (the indicator on down ) or not : and I calculate the difference :

so I must call this indicator that I call histogramtrend on my new indicator (left on the top )

so the problem is when the value of black and red line changes the indicator on the top with Label doesn't do the same I write the code just for one period in order to show you what 's the problem

#property indicator_chart_window
//#property indicator_separate_window

//extern int  periode = 65 ;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
     //  WindowRedraw();
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
ObjectsDeleteAll();
   Comment("");
//----
   return(0);
  }
  
  
   
  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
    
    // we get the value of custom indicator 
    double MM1 , MM1bis ;
    double MM5 , MM5bis ;
    double MM15 , MM15bis ;
    double MM30 , MM30bis ;
    double MMH1 , MMH1bis ;
    double MMH4 , MMH4bis ;
    double MMD1 , MMD1bis ;
    double MMW1 , MMW1bis ;
    double MN , MNbis ;
    int normeM1,normeM5,normeM15,normeM30,normeH1,normeH4,normeD1,normeW1,normeMN;
    int labelM1,labelM5,labelM15,labelM30,labelH1,labelH4,labelD1,labelW1,labelMN ,labelEurUsd;
    
    double valueM1,valueM5,valueM15,valueM30,valueH1,valueH4,valueD1,valueW1,valueMN ;
   
    
    
  //   string name ;
      color Textcolor1,Textcolor5,Textcolor15,Textcolor30,TextcolorH1,TextcolorH4,TextcolorD1,TextcolorW1,TextcolorMN ;
      
      
      // couleur Label
      color color_label = Black;
      
      
      // pour le franc suisse 
//------------------------------------------

   double CHFMM1 , CHFMM1bis ;
    double CHFMM5 , CHFMM5bis ;
    double CHFMM15 , CHFMM15bis ;
    double CHFMM30 , CHFMM30bis ;
    double CHFMMH1 , CHFMMH1bis ;
    double CHFMMH4 , CHFMMH4bis ;
    double CHFMMD1 , CHFMMD1bis ;
    double CHFMMW1 , CHFMMW1bis ;
    double CHFMN , CHFMNbis ;
         int CHFnormeM1,CHFnormeM5,CHFnormeM15,CHFnormeM30,CHFnormeH1,CHFnormeH4,CHFnormeD1,CHFnormeW1,CHFnormeMN;
          double CHFvalueM1,CHFvalueM5,CHFvalueM15,CHFvalueM30,CHFvalueH1,CHFvalueH4,CHFvalueD1,CHFvalueW1,CHFvalueMN ;
          //   string name ;
      color CHFTextcolor1,CHFTextcolor5,CHFTextcolor15,CHFTextcolor30,CHFTextcolorH1,CHFTextcolorH4,CHFTextcolorD1,CHFTextcolorW1,CHFTextcolorMN ;
          int labelChfUsd ;


//--------------------------------------

// pour la periode 13
 // we get the value of custom indicator 
    double MM113 , MM1bis13 ;
    double MM513 , MM5bis13 ;
    double MM1513 , MM15bis13 ;
    double MM3013 , MM30bis13 ;
    double MMH113 , MMH1bis13 ;
    double MMH413 , MMH4bis13 ;
    double MMD113 , MMD1bis13 ;
    double MMW113 , MMW1bis13 ;
    double MN13 , MNbis13 ;
    int normeM113,normeM513,normeM1513,normeM3013,normeH113,normeH413,normeD113,normeW113,normeMN13;
    int labelM113,labelM513,labelM1513,labelM3013,labelH113,labelH413,labelD113,labelW113,labelMN13 ,labelEurUsd13;
    
    double valueM113,valueM513,valueM1513,valueM3013,valueH113,valueH413,valueD113,valueW113,valueMN13 ;
   
    
  //   string name ;
      color Textcolor113,Textcolor513,Textcolor1513,Textcolor3013,TextcolorH113,TextcolorH413,TextcolorD113,TextcolorW113,TextcolorMN13 ;
      
  //************************************
  
    
      // pour le franc suisse periode13
//------------------------------------------

   double CHFMM113 , CHFMM1bis13 ;
    double CHFMM513 , CHFMM5bis13 ;
    double CHFMM1513 , CHFMM15bis13 ;
    double CHFMM3013 , CHFMM30bis13 ;
    double CHFMMH113 , CHFMMH1bis13 ;
    double CHFMMH413 , CHFMMH4bis13 ;
    double CHFMMD113 , CHFMMD1bis13 ;
    double CHFMMW113 , CHFMMW1bis13 ;
    double CHFMN13 , CHFMNbis13 ;
         int CHFnormeM113,CHFnormeM513,CHFnormeM1513,CHFnormeM3013,CHFnormeH113,CHFnormeH413,CHFnormeD113,CHFnormeW113,CHFnormeMN13;
          double CHFvalueM113,CHFvalueM513,CHFvalueM1513,CHFvalueM3013,CHFvalueH113,CHFvalueH413,CHFvalueD113,CHFvalueW113,CHFvalueMN13 ;
          //   string name ;
      color CHFTextcolor113,CHFTextcolor513,CHFTextcolor1513,CHFTextcolor3013,CHFTextcolorH113,CHFTextcolorH413,CHFTextcolorD113,CHFTextcolorW113,CHFTextcolorMN13 ;
          int labelChfUsd13 ;

     
       int    counted_bars=IndicatorCounted();
    //
    
    
      int limit ;

  // I try to get the 2 value of black and red one on the histogramtrend file 

        MM113 = iCustom(NULL,1,"histogramtrend",13,7,0,0); // the value         ExtMapBuffer1 of histogramtrend
       MM1bis13 = iCustom(NULL,1,"histogramtrend",13,7,1,0); // the moving average      ExtMapBuffer2 of histogramtrend

    // I calculate the difference 

      valueM113 = (MM113-MM1bis13);
        
        // I create the object 
         normeM113 = CreerObjet("valeurM113",valueM113,40,80,Textcolor113);
         // error 
         if(normeM113==0)
         {
             Print("error: can't create label_object! code #",GetLastError());
         }

           // I create the label M1

           labelM1= CreerLabel ("labelM1","M1" ,50,36,color_label);


//----
   return(0);
  }

// I create 2 functions 
// function 
  
   int CreerObjet(string label_name,double value_name,int distance_X,int distance_Y,color name_textcolor)
  
   {
   
        int  obj_total = ObjectsTotal();  
   
       if(!ObjectCreate(label_name,OBJ_LABEL,0,0,0))
        {
            Print("error: can't create label_object! code #",GetLastError());
                        return(0);
        
        }
        else
        {
            // I create label 
           ObjectCreate (label_name,OBJ_LABEL,0,Time[0],0);
// I change the value 
            ObjectSetText(label_name,DoubleToStr(value_name,5),6,"Arial");
// it's position 
            ObjectSet(label_name,OBJPROP_CORNER,0);
            ObjectSet(label_name,OBJPROP_XDISTANCE,distance_X);
             ObjectSet(label_name,OBJPROP_YDISTANCE,distance_Y);
             
                  if(value_name<0)
                  name_textcolor=Red;
                  else if (value_name>0)
                   name_textcolor=Green;
                   else if (value_name==0)
                    name_textcolor=Gold;
                    
                    ObjectSet(label_name, OBJPROP_COLOR, name_textcolor );
                    
                     WindowRedraw();
                    
                    return (1);
            
        
        }
  
      
      
   }
   
   //
   int CreerLabel (string label_name,string vrai_nom ,int distance_X,int distance_Y,color name_textcolor)
   
   {
        int  obj_total = ObjectsTotal();  
   
       if(!ObjectCreate(label_name,OBJ_LABEL,0,0,0))
        {
            Print("error: can't create label_object! code #",GetLastError());
                        return(0);
        
        }
        else
        
        {
           
          ObjectSetText(label_name,vrai_nom,8,"Arial",name_textcolor);
          ObjectSet(label_name,OBJPROP_CORNER,0);
            ObjectSet(label_name,OBJPROP_XDISTANCE,distance_X);
             ObjectSet(label_name,OBJPROP_YDISTANCE,distance_Y);
             
              WindowRedraw();
             return(1);
        }
        
        
   
   
   }

so probably the problem is on the function CreerObjet () because he can't to update the value when the the red and black line change

so my last remark is when I delete the indicator and when I insert it again, the value change .

thanks for your answer

 
if (ObjectFind(...)...) //first
   ObjectDelete(...); //& then
   ObjectCreate(...); 
 
Can you attach your histogramtrend Indicator as a file and I'll test . .
 

Hello

and the other indicator :

 

I modified your Functions . . . if the object exists and you try to create it again you will get an error . . . check your Experts tab . . . if you get an error the ObjectSet doesn't happen so nothing changes . . .

int CreerObjet(string label_name,double value_name,int distance_X,int distance_Y,color name_textcolor)
   {
   int  obj_total = ObjectsTotal();  
   
   if (ObjectFind(label_name) < 0)                    // <---- added,  only create the object if it doesn't exist
      if(!ObjectCreate(label_name,OBJ_LABEL,0,0,0))
         {
         Print("error: can't create label_object! code #",GetLastError());   
         return(0);
         }
//      else
//         {
         // I create label 
//         ObjectCreate (label_name,OBJ_LABEL,0,Time[0],0);
         // I change the value 
         ObjectSetText(label_name,DoubleToStr(value_name,5),16,"Arial");
         // it's position 
         ObjectSet(label_name,OBJPROP_CORNER,0);
         ObjectSet(label_name,OBJPROP_XDISTANCE,distance_X);
         ObjectSet(label_name,OBJPROP_YDISTANCE,distance_Y);
             
         if(value_name<0)
            name_textcolor=Red;
         else if (value_name>0)
            name_textcolor=Lime;
         else if (value_name==0)
            name_textcolor=Gold;
                   
         ObjectSet(label_name, OBJPROP_COLOR, name_textcolor );
         WindowRedraw();
         return (1);
                   
//         }
   }
   
   //
int CreerLabel (string label_name,string vrai_nom ,int distance_X,int distance_Y,color name_textcolor)
   {
   int  obj_total = ObjectsTotal();  
   
   if (ObjectFind(label_name) < 0)                     // <---- added,  only create the object if it doesn't exist
      if(!ObjectCreate(label_name,OBJ_LABEL,0,0,0))
      {
      Print("error: can't create label_object! code #",GetLastError());
      return(0);
      }
//   else
//      {
      ObjectSetText(label_name,vrai_nom,16,"Arial",name_textcolor);
      ObjectSet(label_name,OBJPROP_CORNER,0);
      ObjectSet(label_name,OBJPROP_XDISTANCE,distance_X);
      ObjectSet(label_name,OBJPROP_YDISTANCE,distance_Y);
            
      WindowRedraw();
      return(1);
//      }
   }
 

thank you it works !! great !!

the function ObjectFind test if the object exist !!

thanks

 
qjol:
if (ObjectFind(...)...) //first
   ObjectDelete(...); //& then
   ObjectCreate(...); 
Or my pattern: if(!ObjectMove(...) ObjectCreate(...)
void TLine( string name, datetime T0, double P0, datetime T1, double P1
          , color clr, bool ray=false ){                #define WINDOW_MAIN 0
    if (!Show.Objects)  return;
    if      (ObjectMove( name, 0, T0, P0 ))     ObjectMove(name, 1, T1, P1);
    else if (!ObjectCreate( name, OBJ_TREND, WINDOW_MAIN, T0, P0, T1, P1 ))
        Alert("ObjectCreate(",name,",TREND) failed: ", GetLastError() );
    else if (!ObjectSet( name, OBJPROP_RAY, ray ))
        Alert("ObjectSet(", name, ",Ray) failed: ", GetLastError());
    if (!ObjectSet(name, OBJPROP_COLOR, clr )) // Allow color change
        Alert("ObjectSet(", name, ",Color) [2] failed: ", GetLastError());
    string  P0t = PriceToStr(P0);           if (MathAbs(P0 - P1) >= Point)
            P0t = StringConcatenate(P0t, " to ", PriceToStr(P1));
    if (!ObjectSetText(name, P0t, 10))
        Alert("ObjectSetText(",name,") [2] failed: ", GetLastError());
}
Reason: