please how to make label for an Horizontal Line Object

 

Hello ;

at the moment I have created an horizontal line without Label like that :

but I would like to have an indicator with label like that

http://img.ibtimes.com/www/data/images/full/2010/09/15/45438.png

the code is like this

 if(!ObjectCreate("ligne1",OBJ_HLINE,0,temps1,valeur1))
           {
             Print("error: can't create text_object! code #",GetLastError());
            return(0);

           }

but I don't know how to make the label on horizontal line that is to say : to mark ligne1 on the appropriate line

I try to make like this because there are a lot of Line

      // we search the object 
// if ligne 1 we create the label 
    
         if(ObjectFind("ligne1") != 0)
         {
             
            ObjectCreate("ligne1label", OBJ_TEXT,??????);
            ObjectSetText("ligne1label", " ligne1 ", 8, "Arial", Red);
         }

the problem is I don't know the parameters on ObjectCreate("ligne1label", OBJ_TEXT,??????); to make the label according my case !!

I try to inspire this code :

http://www.ibtimes.com/articles/62546/20100915/camarilla-pivot-point-indicator-metatrader-4-mt4-forex-education-free-download-fx.htm

 

The OBJ_TEXT object needs a Price and Time, from the png you posted it seems to use the current bar time for it's time (Time[0]), then you can use the horizontal line Price1 value for its Price.

Something like this . .

ObjectCreate("ligne1label", OBJ_TEXT, 0, Time[0], ObjectGet("ligne1", OBJPROP_PRICE1) );
 

Hello RaptorUK ;

thank you very much it works

I have just 2 questions about that because I know that it's possible to get the value mainly the price by ObjectGet function and I review all the constant like (OBJPROP_TIME1, OBJPROP_PRICE1)

but is it possible to get instead of those constants another value for example : a value of my personnal indicator (MACD or RSI etc ..) . I mean, I would like to create an object (Text ) basing on indicator value . is it possible ?? if yes, How ??

my last question is, you know on this indicator I make a comment like this on the code

int init()
  {
//---- indicators
     Comment("RectangleTarget");
     
    

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

but when I delete the indicator the comment stay !!

on deinitialization function I do ike this to delete all objects

 ObjectDelete("ligne1");
         ObjectDelete("ligne2");
          ObjectDelete("milieu");
          ObjectDelete("hausse1");

but I don't know how to delete this comment ??

that's all !!

really thank you for your answer !!

 

To delete the comment try . . .

Comment("");

To get the value of an Indicator you need to use iCustom https://docs.mql4.com/indicators/iCustom make sure you pass ALL the Indicators extern variables in the iCustom call.

Once you have the value returned from iCustom you can add it to your chart as a Text Object.

 

Yes, I see this function and it is very useful !! let me take a simple example to understand really how to attach an indicator value to an object

for example in my personnal indicator we called : histogramtrend the code is like this

//+------------------------------------------------------------------+
//|                                               histogramtrend.mq4 |
//|                      Copyright © 2011, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net 
  //|
//+------------------------------------------------------------------+



//+------------------------------------------------------------------+
//|                                              Histogramtrend2.mq4 |
//|                      Copyright © 2011, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+

// represnete un histogramme des croisements

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Black
#property indicator_color2 Red
#property indicator_color3 Green
//--- input parameters
extern int       period1=13;
extern int       period2=7;
//--- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];


//


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
    IndicatorBuffers(3);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
   
   SetIndexStyle(2,DRAW_LINE,STYLE_DOT,1,Green);
   SetIndexBuffer(2,ExtMapBuffer3);
   
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   
   int    counted_bars=IndicatorCounted();
   int limit ;
   
//----
         if(counted_bars>0) counted_bars--;
                limit = Bars-counted_bars;
                        
                                for(int i=0;i<limit;i++)
                                {
                                  ExtMapBuffer1[i] = iMA(NULL,0,period1,0,MODE_EMA,PRICE_CLOSE,i);
                                }
                                
                                        for(i=0;i<limit;i++)
                                {
                                        ExtMapBuffer2[i] = iMA(NULL,0,period2,0,MODE_EMA,PRICE_CLOSE,i);
                                }
                                
                                for(i=0;i<limit;i++)
                                {
                                        ExtMapBuffer3[i] = ExtMapBuffer2[i]-ExtMapBuffer1[i];
                                }
                                
                                
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
My target is to show on chart the trend of ExtMapBuffer3[i] if it is above 0 or not (if MM7 is across MM13)

so as you can write we can use iCustom function so according to this code we can write another indicator like this (I simplify )

// for example in my indicator personnal I write that where there is ExtMapBuffer2
    SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);

// in the new code indicator we can do 

// for example for M5 

double M5 = iCustom(NULL,5, "histogramtrend",1,0);// here line index 1 review  SetIndexBuffer
double M15 = iCustom(NULL,15, "histogramtrend",1,0);
double M30 = iCustom(NULL,30, "histogramtrend",1,0);

if it is like this my question is how to attach M5 - M15 - M30 value to an object because in the function ObjectCreate() there are more parameters constant like Price and time ??

and here I would like to show in Text the value of ExtMapBuffer2 in multi time frame via M5 - M15 -M30

in order to know if >0 we write the text where there is the value in green if <0 in red something like that (The text on the right ) :

https://www.mql5.com/en/code/9090

thanks a lot for the function to delete comment !!

 

You can create the Objects and then afterwards change their position, their text content and their colour.

So, ObjectCreate 3 times for the 3 objects, then ObjectSet to change the position OBJPROP_TIME1 & OBJPROP_PRICE1 (see https://docs.mql4.com/objects/ObjectSet & https://docs.mql4.com/constants/objects/properties ) and also ObjectSetText to set the text you want to show on screen (see your other thread) and finally you can set the colour . . .

color TextColor;

if (value < 0) TextColor = Green  else if (value > 0) TextColor = Red;

ObjectSet("name", OBJPROP_COLOR, TextColor );

If this doesn't work when trying to set the colour you can do it when you set the text using ObjectSetText . .

 

Hello ;

I have many problem :( here is the code :

//+------------------------------------------------------------------+
//|                                          MultiTimeframeTrend.mq4 |
//|                                           rahan                  |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "rahan"
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
    
    // we get the value of custom indicator 
    double MM5 , MM15 ;
     string name ;
     color Textcolor ;
 
   int    counted_bars=IndicatorCounted();
    //
   
   int  obj_total = ObjectsTotal();  
//----


    // we try to get the value of custom indicator 
      MM5 = iCustom(0,5,"histogramtrend",1,0);
       MM15 = iCustom(0,15,"histogramtrend",1,0);

    // we create an object Text
    
   
         
             
             // at the begin we attribute the price of the text as 0
             // the problem is I don't know in the paramter the price1
             // here we create the Text for the M5
             if(!ObjectCreate("TextM5", OBJ_TEXT, 0, Time[0],0))
                  {
                     Print("error: can't create label_object! code #",GetLastError());
                        return(0);
                   }
                   
               else
                 // we change the value and the position 
                 
                  
               
               {
                   
                   // we change the price or the value 
                   // here we can 't use ObjectSetText("TextM5",MM5..) because MM5 is double 
                    ObjectSet("TextM5", OBJPROP_PRICE1,MM5);
                    
                    // we change the position 
                    ObjectSet("TextM5", OBJPROP_XDISTANCE,10);
                    ObjectSet("TextM5", OBJPROP_YDISTANCE,10);
                    
                    // we change the color
                    
                  if(MM5<0)
                  Textcolor=Red;
                  else if (MM5>0)
                   Textcolor=Green;
                   else
                    Textcolor=White;
                    ObjectSet("TextM5", OBJPROP_COLOR, Textcolor  );
                    
               
               }
               
               
               // here we create the Text for the M15
                   
               
                if(!ObjectCreate("TextM15", OBJ_TEXT, 0, Time[0],0))
                  {
                     Print("error: can't create label_object! code #",GetLastError());
                        return(0);
                   }
                   
               else
                
                
                {
                   
                   // we change the price or the value 
                   // here we can 't use ObjectSetText("TextM5",MM5..) because MM5 is double 
                    ObjectSet("TextM15", OBJPROP_PRICE1,MM15);
                    
                    // we change the position 
                    ObjectSet("TextM15", OBJPROP_XDISTANCE,10);
                    ObjectSet("TextM15", OBJPROP_YDISTANCE,10);
                    
                    // we change the color
                    
                  if(MM15<0)
                  Textcolor=Red;
                  else if (MM15>0)
                   Textcolor=Green;
                   else
                    Textcolor=White;
                    ObjectSet("TextM15", OBJPROP_COLOR, Textcolor  );
                    
               
               }
         
       
       
     

   
   
   
 
    
   


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

the first problem is I don't know if we get the value of the custom indicator like this and a simple question how it makes the update of this data ??

// we try to get the value of custom indicator 
      MM5 = iCustom(0,5,"histogramtrend",1,0);

my second problem is the way to create the Text (object), when we create a rectangle for example, at the beginning we draw manually it so we can get its Time and price . but here we don't draw, we are just show the value by text

so I define the default value of Text as 0.

 if(!ObjectCreate("TextM5", OBJ_TEXT, 0, Time[0],0))

after we try to change the value of the Text may be we can do : ObjectSetText("TextM5", M5, 10, "Times New Roman", Green); but we need String as a data type then MM5 is a double

so I use this function

  ObjectSet("TextM15", OBJPROP_PRICE1,MM15);

for the position and the color I procede like that, I don't know if there are something wrong

                   // we change the position 
                    ObjectSet("TextM5", OBJPROP_XDISTANCE,10);
                    ObjectSet("TextM5", OBJPROP_YDISTANCE,10);
                    
                    // we change the color
                    
                  if(MM5<0)
                  Textcolor=Red;
                  else if (MM5>0)
                   Textcolor=Green;
                   else
                    Textcolor=White;
                    ObjectSet("TextM5", OBJPROP_COLOR, Textcolor  );

and after I carry on for the MM15 in using the same process

I don't know if we can use ObjectSet for Text Object because there is the function ObjectSetText()

thanks :)

 

How many buffers does your Indicator have ? how many extern variables does it have ? the first parameter you pass using iCustom ( https://docs.mql4.com/indicators/iCustom ) is the symbol, 0 is not valid for that, use NULL for the current chart symbol.

You can only use X & Y pixel values with text labels, for Text you have to use time and price

If you look at your other thread you will see how to convert a double to a string https://docs.mql4.com/convert/DoubleToStr

 

here is all the code of the indicator

//+------------------------------------------------------------------+
//|                                               histogramtrend.mq4 |
//|                      Copyright © 2011, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net 
  //|
//+------------------------------------------------------------------+





// represnete un histogramme des croisements

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Black
#property indicator_color2 Red
#property indicator_color3 Green
//--- input parameters
extern int       period1=13;
extern int       period2=7;
//--- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer6[];


//

double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
    IndicatorBuffers(6);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
   
   SetIndexStyle(2,DRAW_LINE,STYLE_DOT,1,Green);
   SetIndexBuffer(2,ExtMapBuffer6);
   
    SetIndexBuffer(3,ExtMapBuffer3);
     SetIndexBuffer(4,ExtMapBuffer4);
      SetIndexBuffer(5,ExtMapBuffer5);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   
   int    counted_bars=IndicatorCounted();
   int limit ;
   
//----
         if(counted_bars>0) counted_bars--;
                limit = Bars-counted_bars;
                        
                                for(int i=0;i<limit;i++)
                                {
                                  ExtMapBuffer3[i] = iMA(NULL,0,period1,0,MODE_EMA,PRICE_CLOSE,i);
                                }
                                
                                        for(i=0;i<limit;i++)
                                {
                                        ExtMapBuffer4[i] = iMAOnArray(ExtMapBuffer3,0,period2,0,MODE_EMA,i);
                                }
                                
                                for(i=0;i<limit;i++)
                                {
                                        ExtMapBuffer5[i] = iMAOnArray(ExtMapBuffer4,0,period2,0,MODE_EMA,i);
                                }
                                
                                for(i=0;i<limit;i++)
                                {
                                    // histogram 
                                        ExtMapBuffer2[i] = ExtMapBuffer4[i] - ExtMapBuffer5[i];
                                   
                                }
                                
                                
                                for(i=0;i<limit;i++)
                                {
                                
                                   // ligne 
                                    ExtMapBuffer1[i] = iMAOnArray(ExtMapBuffer2,0,period2,0,MODE_EMA,i);  // 0 ; 
                                   
                                
                                }
                                
                                        for(i=0;i<limit;i++)
                                {
                                    ExtMapBuffer6[i] = ExtMapBuffer5[i] - ExtMapBuffer4[i];
                                
                                }
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

the most important is ExtMapBuffer2 and ExtMapBuffer1 because I would like to attach in main window if they are <0 or >0 . that is to say

if ExtMapBuffer2 > ExtMapBuffer1 then I show the value in green color

if ExtMapBuffer2 ExtMapBuffer1 then I show the value in red color

if ExtMapBuffer2 = ExtMapBuffer1 then I show the value in white color (neutral)

and I would make it for all time frame

oh yes, excuse you're right we must write the function like this

  MM5 = iCustom(NULL,5,"histogramtrend",1,0);
       MM15 = iCustom(NULL,15,"histogramtrend",1,0);

yes I see, the way to convert double to string and I want to correct the code !! but I really insist on the way to create the Text ??

 

I change the code like this because we need 2 get 2 buffers for each time

//+------------------------------------------------------------------+
//|                                          MultiTimeframeTrend.mq4 |
//|                                           rami                   |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright " Rami"
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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();  
//----


    // we try to get the value of custom indicator 
    // setindexbuffer 0 and 1
       MM5 = iCustom(NULL,5,"histogramtrend",0,0); // the value         ExtMapBuffer2 of histogramtrend
       MM5bis = iCustom(NULL,15,"histogramtrend",1,0); // the moving average    ExtMapBuffer1 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],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 
                   
                    
                    ObjectSet("TextM5", OBJPROP_XDISTANCE,100);
                    ObjectSet("TextM5", OBJPROP_YDISTANCE,200);
                    
                    
                    
                    // we change the color
                    
                  if(valueM5<0)
                  Textcolor=Red;
                  else if (valueM5>0)
                   Textcolor=Green;
                   else
                    Textcolor=White;
                    ObjectSet("TextM5", OBJPROP_COLOR, Textcolor  );
                    
               
               }
               
               
            
   
   
   
 
    
   


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

about the position

but as you can see we don't see anything may be there is something or we must change the position

 

You have this in your Indicator . . .

extern int       period1=13;
extern int       period2=7;

. . . you MUST pass values for these variables in iCustom.

Example . .

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