problem with value of ObjectGetValueByTime for OBJ_TRENDBYANGLE

 

Hi, I have a problem with value of Trend_Line_By_Angle function. I can't get value of slope on any bars. I saw some same difficulties on forum, but none of answers could help me. 

apparently its because of  (line_id   //line_number). i tried 0, OBJ_TRENDBYANGLE, and some other numbers, but it is useless and return value for all of bars is zero, please help on.



 
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   Trend_Line_By_Angle(0,"slope",0,iTime(_Symbol,PERIOD_H1,105),iLow(_Symbol,PERIOD_H1,105),349,clrRed,STYLE_SOLID,2,false,true,true);
   ChartRedraw();
   Sleep(1000);
   double obj_value=ObjectGetValueByTime(0,"slope",iTime(_Symbol,PERIOD_H1,60),OBJ_TRENDBYANGLE);
   Comment("obj_value  ",obj_value);

  return(INIT_SUCCEEDED);
  }
//-----------------------------------------------------------------------------
bool Trend_Line_By_Angle(const long           chart_ID=0,// ای دی چارت
                         const string          name="TrendLine",  // اسم خط
                         const int             sub_window=0,      // شماره پنجره
                         datetime              time=0,            // اولین نقطه زمان
                         double                price=0,           // اولین نفطه قیمت
                         const double          angle=45.0,        // مقدار زاویه
                         const color           clr=clrRed,        // رنگ خط
                         const ENUM_LINE_STYLE style=STYLE_SOLID, // استایل خط
                         const int             width=1,           // اندازه خط
                         const bool            back=false,        // قرار گرفتن در پشت
                         const bool            selection=true,    // قابلیت حرکت
                         const bool            ray_right=true,    // ادامه دار بودن خط
                         const bool            hidden=true,       // مخفی شدن از لیست
                         const long            z_order=0)         // اولویت برای کلیک ماوس
  {
   datetime time2=0;
   double   price2=0;
   ResetLastError();
   if(ObjectCreate(chart_ID,name,OBJ_TRENDBYANGLE,sub_window,time,price,time2,price2)) // در صورت وجود داشتن ابجیکت
     {
      ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle);
      ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
      ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
      ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);
      ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
      ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
      ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
      ObjectSetInteger(chart_ID,name,OBJPROP_RAY_RIGHT,ray_right);
      ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
      ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
      ChartRedraw();
      return(true);
     }
   else
     {
      if(ObjectCreate(chart_ID,name,OBJ_TRENDBYANGLE,sub_window,time,price,time2,price2))
        {
         ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle);
         ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
         ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
         ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);
         ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
         ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
         ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
         ObjectSetInteger(chart_ID,name,OBJPROP_RAY_RIGHT,ray_right);
         ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
         ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
         ChartRedraw();
         return(true);
        }
      else
        {
         Print(__FUNCTION__,
               ": failed to create => ",name," object! Error code = ",GetLastError());
         return(false);
        }
     }
  }
//+------------------------------------------------------------------+
 
Hello it's not possible to get the angle directly like that but in stead you can use use ObjectGetDouble() with OBJPROP_PRICE from the points and then calculate the difference that way.
 
337252: Hi, I have a problem with value of Trend_Line_By_Angle function. I can't get value of slope on any bars. I saw some same difficulties on forum, but none of answers could help me. 

apparently its because of  (line_id   //line_number). i tried 0, OBJ_TRENDBYANGLE, and some other numbers, but it is useless and return value for all of bars is zero, please help on.

The ObjectGetValueByTime() function fails totally for Trendline by angle (OBJ_TRENDBYANGLE). Unfortunately MetaQuotes has not recognized the bug nor have they attempted to fix it.

 

As far as i know it never existed for that particular object type so i don't think it's a bug if it was never implemented.

I could be wrong though but i never found any reference that it existed in the documentation either.

 
Marco vd Heijden:
Hello it's not possible to get the angle directly like that but in stead you can use use ObjectGetDouble() with OBJPROP_PRICE from the points and then calculate the difference that way.
Hello, I don't want to get the angle. I want to get the value of trendline on each bar, and check if the price e.g iLow breaks the line or not.
 
Marco vd Heijden:

As far as i know it never existed for that particular object type so i don't think it's a bug if it was never implemented.

I could be wrong though but i never found any reference that it existed in the documentation either.

Is a bug because the documentation states that it is supported.

Note

The function uses a synchronous call, which means that the function waits for the execution of all commands that have been enqueued for this chart prior to its call, that is why this function can be time consuming. This feature should be taken into account when working with a large number of objects on a chart.

An object can have several values in one price coordinate, therefore it is necessary to specify the line number. This function applies only to the following objects:

  • Trendline (OBJ_TREND)
  • Trendline by angle (OBJ_TRENDBYANGLE)
  • Gann line (OBJ_GANNLINE)
  • Equidistant channel (OBJ_CHANNEL) - 2 lines
  • Linear regression channel (OBJ_REGRESSION) - 3 lines
  • Standard deviation channel (OBJ_STDDEVCHANNEL) - 3 lines
  • Arrowed line (OBJ_ARROWED_LINE)
 
337252:
Hello, I don't want to get the angle. I want to get the value of trendline on each bar, and check if the price e.g iLow breaks the line or not.

Objectgetvaluebytime

 
amandoObjectgetvaluebytime

That is what the OP is using but it has not worked ever. It is a bug which as never been fixed.

Reason: