Object text move to the right

 

Hello everyone, currently I'm using a lable but I would like to achieve the same result with a text object because label keeps refreshing when I move the chart. 

Here's desired outcome:

Example

The text basically have the same price coordinates of the white lines, here's the code:

   int x,y;
   ChartTimePriceToXY(0,0,Time[i],buffer[i],x,y);
   ObjectCreate(0,"Some text 1",OBJ_LABEL,0,0,0);
   ObjectSetText("Some text 1","Some text 1",12,"Arial",m_col);
   
   ObjectSet("Some text 1", OBJPROP_XDISTANCE, x+30);
   ObjectSet("Some text 1", OBJPROP_YDISTANCE, y-10);

When I try to convert this into a text object I do:

   ObjectCreate(0,"Some text 1",OBJ_TEXT,0,Time[i+30],buffer[i]);

But it does not works. Could someone point me out what I0m doing wrong? Thank's. 

 

This is the function I am using and it appears as in the attached image.

//+------------------------------------------------------------------+
void Disp_Symbol(string objname, int index, string symb, color col, double value)
{
   int TxtSize  = 8;
   string font  = "Arial Black";
   string dText = "";

   if (ObjectFind(objname) < 0)
   {
      dText = "                        " + symb + "  " + DoubleToString(value, 4);
      ObjectCreate(objname, OBJ_TEXT, index, Time[0], value + 0.001);
      ObjectSetText(objname, dText, TxtSize, font, col);
   }
   else
   {
      dText = "                        " + symb + "  " + DoubleToString(value, 4);
      ObjectSet(objname, OBJPROP_TIME1, Time[0]);
      ObjectSet(objname, OBJPROP_PRICE1, value + 0.001);
      ObjectSetText(objname, dText, TxtSize, font, col);
   }
}
//+------------------------------------------------------------------+
 
Nagisa Unada #:

This is the function I am using and it appears as in the attached image.

Hi, using your hack of "        " the text get correctly shifted to the right but it cuts out informations I have to display. Such as, instead of "Some text 1", it display "Some te". 

Any other solutions?

Edit: for example:

   ObjectCreate(name,OBJ_TEXT,index,iTime(0,0,-100),array[index]);
   ObjectSetText(name,text,12,"Arial",m_col);

Does not works because MT4 consider any time in the future as "-1"... Is really no other way to move text object on a x value in the future?

 
You cannot use -100 for bar numbers.

My other indicator shows longer text with no problem.

1

Can you display it in the following way?

dText = "              " + "Some" + " " + "text" + " " + "1";


 
ironhak #: Any other solutions?
Stop using text and use a label. (Convert price to Y)
 
William Roeder #:
Stop using text and use a label. (Convert price to Y)

That's already what I'm doing, it just pisses me off that when I move the chart then labels don't update until there's a new OnCalculate event. 

 
ironhak #:

That's already what I'm doing, it just pisses me off that when I move the chart then labels don't update until there's a new OnCalculate event. 

Anyone can help wth this? It's really impossibile to place text on time_current + x? 

 
ironhak #:

Anyone can help wth this? It's really impossibile to place text on time_current + x? 

Hello , for bars that go <0 use Time[0]+(Bar*(-1))*PeriodSeconds() otherwise just Time[bar]

void place_text(double price,
                int bar,
                string name,string text,
                int fontsize,
                color text_color,
                ENUM_ANCHOR_POINT anchor,
                bool selectable,
                bool back){
datetime time=0;
if(bar<0){time=Time[0]+PeriodSeconds()*(-1*bar);}else{
time=Time[bar];
}
ObjectCreate(ChartID(),name,OBJ_TEXT,0,time,price);
ObjectSetInteger(ChartID(),name,OBJPROP_FONTSIZE,fontsize);
ObjectSetInteger(ChartID(),name,OBJPROP_COLOR,text_color);
ObjectSetInteger(ChartID(),name,OBJPROP_ANCHOR,anchor);
ObjectSetInteger(ChartID(),name,OBJPROP_SELECTABLE,selectable);
ObjectSetInteger(ChartID(),name,OBJPROP_BACK,back);
ObjectSetString(ChartID(),name,OBJPROP_TEXT,text);
}
 
Lorentzos Roussos #:

Hello , for bars that go <0 use Time[0]+(Bar*(-1))*PeriodSeconds() otherwise just Time[bar]

Hello, thank's. 

Am I doing something wring? Nothing get plotted

 for(int iBar = Bars-1-MathMax(lookback, prev_calculated); iBar >= 0; --iBar)
     {

     
     string str = StringConcatenate("1","  -  ",DoubleToString(buff_dc_hh[iBar]-buff_dc_ll[iBar],5));
     place_text(buff_dc_hh[iBar],iBar,"hh",str,10,clrWhite,ANCHOR_RIGHT_UPPER,false,false);
        
      
     }
   return rates_total-1; // Recalculate current bar next tick.
// Return value of prev_calculated for next call
  };



void place_text(double price,
                int bar,
                string name,string text,
                int fontsize,
                color text_color,
                ENUM_ANCHOR_POINT anchor,
                bool selectable,
                bool back){
datetime time=0;
time=Time[0]+(bar*(-1))*PeriodSeconds();

ObjectCreate(ChartID(),name,OBJ_TEXT,0,time,price);
ObjectSetInteger(ChartID(),name,OBJPROP_FONTSIZE,fontsize);
ObjectSetInteger(ChartID(),name,OBJPROP_COLOR,text_color);
ObjectSetInteger(ChartID(),name,OBJPROP_ANCHOR,anchor);
ObjectSetInteger(ChartID(),name,OBJPROP_SELECTABLE,selectable);
ObjectSetInteger(ChartID(),name,OBJPROP_BACK,back);
ObjectSetString(ChartID(),name,OBJPROP_TEXT,text);
}
 
ironhak #:

Hello, thank's. 

Am I doing something wring? Nothing get plotted

To get the effect like in the screenshot you shared you will need to have your text at a fixed distance from the latest bar [0] so don't send iBar in the bar but -5 (for a distance of -5 bars to the right) and also don't update it on every bar of the past which is redundant.

if(iBar==0){
place_text(buff_dc_hh[iBar],-5,"hh",str,10,clrWhite,ANCHOR_RIGHT_UPPER,false,false);
}
 
Lorentzos Roussos #:

To get the effect like in the screenshot you shared you will need to have your text at a fixed distance from the latest bar [0] so don't send iBar in the bar but -5 (for a distance of -5 bars to the right) and also don't update it on every bar of the past which is redundant.

Hello, thank's so much for your help!!! 

Reason: