How to read TrendLIne(object) value

 

Hello,

I want to read the price from the trend line object.



I just want to get the price (upper and lower line ) on the current bar.



    for(int k=0;k<ObjectsTotal(0,0, OBJ_TREND);k++) 
      { 
         string name = ObjectName(0, k, 0, OBJ_TREND); 
           
        if(ObjectGet(name,OBJPROP_TIME1)==Time[0])
         {
            double VALUE= ObjectGetDouble(0, name, OBJPROP_PRICE1);
            double time= ObjectGetDouble(0, name, OBJPROP_TIME1);
          Print(name+"="+VALUE+time);
            
        }
      }
   

This is my code.

To get the onject price on the current bar, I used Time[0]

But it is not working.

Is this correct?

 
OBJPROP_TIME
OBJPROP_PRICE
 
Cromo: To get the onject price on the current bar, I used Time[0] But it is not working. Is this correct?
  1. Your code only select a trend line what has the first coordinate at Time[0]. Were they both drawn from bar zero backwards? Otherwise, you will not select them.
  2. Your code reads one of the two trend line coordinates; has nothing to do what you want.
  3. Perhaps you should read the manual.
              ObjectGetValueByShift - Object Functions - MQL4 Reference
 

Hi, William

Great hint.

Thanks.

ObjectGetValueByShift

solve the issue!


 

Thanks for the ObjectsTotal() / ObjectName() cycle. I haven't figured this one out myself. :)

I have a slightly different problem. I can read the price values of trendlines, but I need to know the upcoming price value too. If I hover the mouse over them it appears on screen so the data is there. (I use ray_right=true parameter when I create a trendline.) The following code works in Strategy Tester but it always gives me 0.0 in live conditions:

MqlDateTime dTimeStruc;
TimeLocal(dTimeStruc);

if ( ObjectFind(0, "SupportTL") >= 0 )
{
        PriceData.PeriodTempUpdate();                   //sets iPeriodTemp variable
        dTimeStruc.min += iPeriodTemp / 60;
        double dPrice1 = ObjectGetValueByTime(0, "SupportTL", StructToTime(dTimeStruc), 0);                             //test
        Print("TEST: Support Trend Line Price value for next bar: ", DoubleToString(dPrice1, Digits()));
}

What am I'm missing?

 
ObjectGetValueByTime()
Time = Time[0]
Reason: