Add a label to current candle - not shown correctly in mt4

 

Hi,

I would like draw a text label where the current candle is. I got the label but it starts at the previous candle not at the current one

This is what I am using at the moment

   ObjectCreate(0, label, OBJ_TEXT, 0, TimeCurrent(), price);
   ObjectSetInteger(0, label, OBJPROP_COLOR, color);
   ObjectSetInteger(0, label, OBJPROP_FONTSIZE, font_size);
   ObjectSetString(0, label, OBJPROP_TEXT, "Entry price");

Any idea why the text is not above the current candle? The exact same code works in mt5 and the label is displayed as expected.

Files:
label.PNG  5 kb
 
roniko1994:

Hi,

 at the previous candle not at the current one

The previous candle's time ? 

The previous candle's price ?

Open ? High ? Low ? Close ? 

The last candle is

datetime time  = iTime(Symbol(),PERIOD_CURRENT,0);
double   price = iOpen(Symbol(),PERIOD_CURRENT,0);// or close or high or low since you didnt specify

Also, notice this ANCHOR:

//+------------------------------------------------------------------+ 
//| Creating Text object                                             | 
//+------------------------------------------------------------------+ 
bool TextCreate(const long              chart_ID=0,               // chart's ID 
                const string            name="Text",              // object name 
                const int               sub_window=0,             // subwindow index 
                datetime                time=0,                   // anchor point time 
                double                  price=0,                  // anchor point price 
                const string            text="Text",              // the text itself 
                const string            font="Arial",             // font 
                const int               font_size=10,             // font size 
                const color             clr=clrRed,               // color 
                const double            angle=0.0,                // text slope 
                const ENUM_ANCHOR_POINT anchor=ANCHOR_LEFT_UPPER, // anchor type 
                const bool              back=false,               // in the background 
                const bool              selection=false,          // highlight to move 
                const bool              hidden=true,              // hidden in the object list 
                const long              z_order=0)                // priority for mouse click 
  { 
//--- set anchor point coordinates if they are not set 
   ChangeTextEmptyPoint(time,price); 
//--- reset the error value 
   ResetLastError(); 
//--- create Text object 
   if(!ObjectCreate(chart_ID,name,OBJ_TEXT,sub_window,time,price)) 
     { 
      Print(__FUNCTION__, 
            ": failed to create \"Text\" object! Error code = ",GetLastError()); 
      return(false); 
     } 
//--- set the text 
   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text); 
//--- set text font 
   ObjectSetString(chart_ID,name,OBJPROP_FONT,font); 
//--- set font size 
   ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size); 
//--- set the slope angle of the text 
   ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle); 
//--- set anchor type 
   ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor); 
//--- set color 
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); 
//--- display in the foreground (false) or background (true) 
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); 
//--- enable (true) or disable (false) the mode of moving the object by mouse 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); 
//--- hide (true) or display (false) graphical object name in the object list 
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); 
//--- set the priority for receiving the event of a mouse click in the chart 
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); 
//--- successful execution 
   return(true); 
  } 
//+------------------------------------------------------------------+ 
 
roniko1994: I would like draw a text label … but it starts at the previous candle not at the current one  … Any idea why the text is not above the current candle?
  1. There are labels (X & Y,) and text objects (Price & Time.) There is no such thing as a "text label."
  2. Your image shows it is centered over your time. Try changing how its anchored (like left.) Or rotate the text so you can see the anchor.
    Methods of Object Binding - Objects Constants - Constants, Enumerations and Structures - MQL4 Reference
    OBJ_TEXT - Object Types - Objects Constants - Constants, Enumerations and Structures - MQL4 Reference
  3. Anchor point is not lower left.
 

The text should be aligned next to the line(not above or below the candle high/low) and the X coordinate should be based on the current candle's time.

This is what I have in mt5 and I would like to achieve the same thing in mt4


Ps. The following did the job in mt4

ObjectSetInteger(0, label, OBJPROP_ANCHOR, ANCHOR_LEFT_UPPER);
Files:
mt5text.PNG  8 kb
 
William Roeder:
  1. There are labels (X & Y,) and text objects (Price & Time.) There is no such thing as a "text label."

Yes there is.


Reason: