please how to make label for an Horizontal Line Object - page 2

 
      MM5 = iCustom(0,5,"histogramtrend",1,0);
       MM15 = iCustom(0,15,"histogramtrend",1,0);
These will not work in the tester, you can't get bar zero data for other TFs
 

yes I put like this :

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

the value before the last is the Line index.

 

here we try to get 2 value on buffer for one time so

we must change 15 by 5 on MM5bis

at the moment the code is like this :

int start()
  {
    
    // we get the value of custom indicator 
    double MM5 , MM5bis ;
     string name ;
     color Textcolor ;
     double valueM5 ;
 
   int    counted_bars=IndicatorCounted();
    //
   
   int  obj_total = ObjectsTotal();  
//----

//MM15 = iCustom(NULL,15,"histogramtrend", 13, 7, 1,0);

    // we try to get the value of custom indicator 
    // setindexbuffer 0 and 1
       MM5 = iCustom(NULL,5,"histogramtrend",13,7,0,0); // the value    ExtMapBuffer1 of histogramtrend
       MM5bis = iCustom(NULL,5,"histogramtrend",13,7,1,0); // the moving average        ExtMapBuffer2 of histogramtrend

    // we create an object Text
    // we make the difference and we show this value
    
        valueM5 = MM5-MM5bis;
    
                
            
             // here we create the Text for the M5
           if(!ObjectCreate("TextM5", OBJ_TEXT, 0, Time[0],WindowPriceMin()+0.05*(WindowPriceMax()-WindowPriceMin())))
           
         //  if(!ObjectCreate("TextM5", OBJ_TEXT, 0, Time[0],valueM5))
                  {
                     Print("error: can't create label_object! code #",GetLastError());
                        return(0);
                   }
                   
               else
                 // we change the value and the position 
                 
                                
               {
                   
           
                    ObjectSetText("TextM5", DoubleToStr(valueM5,Digits), 12 );
                    
                    // we change the position 
                   
                    
                    ObjectSetText("TextM5", OBJPROP_XDISTANCE,10);
                    ObjectSetText("TextM5", OBJPROP_YDISTANCE,500);
                    
                    
                    
                    // we change the color
                    
                  if(valueM5<0)
                  Textcolor=Red;
                  else if (valueM5>0)
                   Textcolor=Green;
                   else
                    Textcolor=White;
                    ObjectSet("TextM5", OBJPROP_COLOR, Textcolor  );
                    
               
               }
               
           // for M15 
               
               
            
   
   
   
 
    
   


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

and it shows a value

but if you just calculate the values on the 2 indicators on histogratrend and the value in green : there is different .

 

I try to use something like this :

                  Comment("value5 - ",valueM5,"\n",
                  "value15 -",valueM15);

it works but I don't know how to change the color of the value because here it's not an object : in the left on the top . I would like something like that Comment () but I don't know how to change the color

 
ludo31:

I try to use something like this :

it works but I don't know how to change the color of the value because here it's not an object : in the left on the top . I would like something like that Comment () but I don't know how to change the color

The colour of the Comment text is the Chart foreground colour, you can't change it on it's own.
 

Hello ;

I mean how to change the color of value (red if <0 and green if >0) without changing manually the chart foreground by using comment () ??

so, I change the code and I use finally Label . the simple code

int start()
  {
    
    // we get the value of custom indicator 
    double MM1 , MM1bis ;
    double MM5 , MM5bis ;

   // there is a lot of declaration here 

    // we try to get the value of custom indicator 
    // setindexbuffer 0 and 1
    
        MM1 = iCustom(NULL,1,"histogramtrend",13,7,0,0); // the value   ExtMapBuffer1 of histogramtrend
       MM1bis = iCustom(NULL,1,"histogramtrend",13,7,1,0); // the moving average        ExtMapBuffer2 of histogramtrend
    
    
       MM5 = iCustom(NULL,5,"histogramtrend",13,7,0,0); // the value    ExtMapBuffer1 of histogramtrend
       MM5bis = iCustom(NULL,5,"histogramtrend",13,7,1,0); // the moving average        ExtMapBuffer2 of histogramtrend
       

       valueM1 = (MM1-MM1bis);
        
        
         normeM1 = CreerObjet("valeurM1",valueM1,297,20,Textcolor1);
         // error 
         if(normeM1==0)
         {
             Print("error: can't create label_object! code #",GetLastError());
         }
           
           // M5
  
        valueM5 = (MM5-MM5bis);
        
        
         normeM5 = CreerObjet("valeurM5",valueM5,365,20,Textcolor5);
         // error 
         if(normeM5==0)
         {
             Print("error: can't create label_object! code #",GetLastError());
         }
         

 //  the Labels H1 H5 etc ..
       
            // int labelM1,labelM5,labelM15,labelM30,labelH1,labelH4,labelD1,labelW1,labelMN ;
            labelM1= CreerLabel ("labelM1","M1" ,314,2,color_label);
             labelM5 = CreerLabel ("labelM5","M5" ,381,2,color_label);
     // marque Euro
                         labelEurUsd = CreerLabel ("labelEUR","Eur/Usd" ,194,20,color_label);


return (0);
}

// 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
        {
            //ObjectSetText("labelM5",DoubleToStr(valueM5,4),10,"Arial",Black);
            ObjectSetText(label_name,DoubleToStr(value_name,Digits));
            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
                    name_textcolor=Orange;
                    ObjectSet(label_name, OBJPROP_COLOR, name_textcolor );
                    
                    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);
             return(1);
        }
        
        
   
   
   }

my question is how to refresh or to update the value or the data ???

 
ludo31:

Hello ;

I mean how to change the color of value (red if <0 and green if >0) without changing manually the chart foreground by using comment () ??

so, I change the code and I use finally Label . the simple code

my question is how to refresh or to update the value or the data ???

I'm not 100% sure I understand your question . . . but you can change the text and text colour of the Text Label Object using the following . . .

It will change the value to the current value of the variable value and change the color to the value of NewColour

ObjectSetText("name", DoubleToStr(value, Digits), 24, "Arial", NewColour);
 

Yes, in the function CreerLabel I use this function

 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);

but I think that the value or the data don't change according the current chart that is to say, may be the value are the same at anytime . just to make an exemple :

in this code I try to create an extern variable

extern int  periode = 13 ;

int start()
  {
     

      MM1 = iCustom(NULL,1,"histogramtrend",periode,7,0,0); // the value        ExtMapBuffer1 of histogramtrend
       MM1bis = iCustom(NULL,1,"histogramtrend",periode,7,1,0); // the moving average   ExtMapBuffer2 of histogramtrend
    
    
       MM5 = iCustom(NULL,5,"histogramtrend",periode,7,0,0); // the value       ExtMapBuffer1 of histogramtrend
       MM5bis = iCustom(NULL,5,"histogramtrend",periode,7,1,0); // the moving average   ExtMapBuffer2 of histogramtrend


   valueM1 = (MM1-MM1bis);
        
        
         normeM1 = CreerObjet("valeurM1",valueM1,297,20,Textcolor1);
         // error 
         if(normeM1==0)
         {
             Print("error: can't create label_object! code #",GetLastError());
         }
           
           // M5
  
        valueM5 = (MM5-MM5bis);
        
        
         normeM5 = CreerObjet("valeurM5",valueM5,365,20,Textcolor5);
         // error 
         if(normeM5==0)
         {
             Print("error: can't create label_object! code #",GetLastError());
         }




  }



// 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
        {
            //ObjectSetText("labelM5",DoubleToStr(valueM5,4),10,"Arial",Black);
            ObjectSetText(label_name,DoubleToStr(value_name,Digits));
            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
                    name_textcolor=Orange;
                    ObjectSet(label_name, OBJPROP_COLOR, name_textcolor );
                    
                    return (1);
            
        
        }
  
      
      
   }


 
         

the problem is when I insert the indicator ; the periode is 13 (default ) and the result i like this :

the indicator in down is histogramtrend( and here we see black line < red then <0 and red and that's right when we see D1 Eur/usd 0.00070 . now let change the parameter of histogramtrend and our indicator

as you can see there is a differnce between histogramtrend in 13 and in 65 . in 65 the black line is superior of red one so > 0 and the value must green . so when we change the parameter of our indicator (Multitimetrend) the value are the same and stay red like in period 13 .

now, I try to change the code and make 65 as a default parameter ! I delete all object and I compile again the code and the real result in 65 is like this

remark that D1 become green .

so I don't know wha's wrong and how to update the value :

may be we must make loop like this

 if(counted_bars>0) counted_bars--;
      limit=Bars-counted_bars;
       for(int i=0; i<limit; i++)
    {

      we make all here 

      // so we change the index by i 

             MM1 = iCustom(NULL,1,"histogramtrend",13,7,0,i); // the value      ExtMapBuffer1 of histogramtrend
       MM1bis = iCustom(NULL,1,"histogramtrend",13,7,1,i);

    }