Anchor Text to vertical line?

 

Hey guys,

how can I anchor a text to a vertical line. Any hints to go about it? I created a line for every hour. Works great. Now when I create a text I want to anchor it to this line. Ideally to the bottom with offset. And when I change TF or zoom in or out it should always keep this relative position. What function works for this? So far I am using something like this:

   datetime t1, t2;
   double   p1, p2;
   int      b1, b2;

   t1=StringToTime(TimeToString(dt, TIME_DATE)+" "+time);
   t2=StringToTime(TimeToString(dt, TIME_DATE)+" "+time);

   b1=iBarShift(_Symbol, PERIOD_CURRENT, t1);
   b2=iBarShift(_Symbol, PERIOD_CURRENT, t2);

   p1=iHigh( _Symbol, PERIOD_CURRENT, iHighest(_Symbol, PERIOD_CURRENT, MODE_HIGH, b1-b2, b2) );
   p2=iLow(_Symbol, PERIOD_CURRENT, iLowest (_Symbol, PERIOD_CURRENT, MODE_LOW , b1-b2, b2) );

   ObjectSetInteger(0, name_line, OBJPROP_TIME, 0 , t1);
   ObjectSetInteger(0, name_line, OBJPROP_TIME, 1 , t2);

   int x=0, y=0;

   ChartTimePriceToXY(0, 0, t1, t2, x, y);

   Print(x, " | ", y);

   ObjectSetInteger(0, name_text, OBJPROP_XDISTANCE, x-500);
   ObjectSetInteger(0, name_text, OBJPROP_YDISTANCE, -53);


Can anyone point me to a solution?


Greetings


 

Hi

You can try to use TEXT object instead of Label OBJ_TEXT are set on the chart by time and price. So, you could use the time of the line or time with some additional buffer (next candle or something like that). And as for the price you can use also the lowest price of the chart.

double priceMin=ChartGetDouble(0,CHART_PRICE_MIN,0);

Of course, you would have to still update the price distance when chart is changed,because the price would change then too, but it’s inevitable.

Have a nice day👍📊