Is there a solution to get angle value on OBJ_TRENDBYANGLE by code?

 

Dear experts,
@Alain Verleyen
@whroeder1

To this day, I am still wondering why the angle value remains zero
when I create the OBJ_TRENDBYANGLE object based on a predefined trendline through code in EA or Indicator.

Example:

ObjectCreate(0,objnameline+"-Angle",OBJ_TRENDBYANGLE,0,0,0,0,0);
ObjectMove(0,objnameline+"-Angle",0,xtime,objprice);
ObjectMove(0,objnameline+"-Angle",1,xtime2,objprice2);
ChartRedraw();

double angle_value=ObjectGetDouble(0,objnameline+"-Angle",OBJPROP_ANGLE); //<<---- why angle value is still always 0 ?
ObjectSetText(objnameline+"-Angle","Angle is "+DoubleToString(angle_value,2));


Please advise me why angle value is still always 0,
is this a limitation on MQ4 and will not be improved,
or is there a solution to get angle value on OBJ_TRENDBYANGLE by code?

I know how OBJ_TRENDBYANGLE has no fixed point in chart,
but I really want to know how to get the angle value after the object have been created by code.

My last update MetaEditor MT4 is version 5.00 build 1601 (May 19, 2017)

Thank you,
Yohana

 
  1. It is zero because you never gave the object a angle value.
    //--- change trend line's slope angle; when changing the angle, coordinates of the second
    //--- point of the line are redefined automatically according to the angle's new value
       ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle);
              OBJ_TRENDBYANGLE - Object Types - Objects Constants - Standard Constants, Enumerations and Structures - MQL4 Reference

  2. It has a "fixed point on the chart." You moved it there.

 
whroeder1:
  1. It is zero because you never gave the object a angle value.

  2. It has a "fixed point on the chart." You moved it there.

Hi,
thanks for your time.

Yes, sure, because that I need is angle of the object :)
Is that still impossible although the chart can display angle value when mouse over the object?

Thank you

 
Yohana Parmi:To this day, I am still wondering why the angle value remains zero

when I create the OBJ_TRENDBYANGLE object based on a predefined trendline through code in EA or Indicator.


It's zero because it's not updated (available) immediately after the object is created. So you could use a timer, eventually chart event, or a loop.

string objnameline="test";
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   EventSetMillisecondTimer(1);
   OnTick();// market close currently, I force a tick event
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   ObjectCreate(0,objnameline+"-Angle",OBJ_TRENDBYANGLE,0,Time[10],Close[10],Time[50],Close[50]);
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   double angle_value=ObjectGetDouble(0,objnameline+"-Angle",OBJPROP_ANGLE);
   if(angle_value!=0)
     {
      Comment(StringFormat("%s: angle=%.1f",__FUNCTION__,angle_value));
      EventKillTimer();
     }
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
   double angle_value=ObjectGetDouble(0,objnameline+"-Angle",OBJPROP_ANGLE);
   if(angle_value!=0)
     {
      Comment(StringFormat("%s: angle=%.1f",__FUNCTION__,angle_value));
     }
  }
//+------------------------------------------------------------------+
 
Alain Verleyen:

It's zero because it's not updated (available) immediately after the object is created. So you could use a timer, eventually chart event, or a loop.

Oh thank you sir Alain,

I got your excellent point,
and I really appreciate that.

I am happy, it solved.
because this thing is my dream since last years :)

Thanks, and God bless you,
Yohana

 
Yohana Parmi:

Oh thank you sir Alain,

I got your excellent point,
and I really appreciate that.

I am happy, it solved.
because this thing is my dream since last years :)

Thanks, and God bless you,
Yohana

Yohana, I got interested about that angle, I want to ask you, what are the use of that angle object? How can I make use of it during market analysis?

 
Chris Mukengeshayi:

Yohana, I got interested about that angle, I want to ask you, what are the use of that angle object? How can I make use of it during market analysis?

Hi Chris,

Next week, I will continue my research on this subject.
Still need more effort and time to get it done.

Hope it not too far from now :)

Regards.

 
Yohana Parmi:

Hi Chris,

Next week, I will continue my research on this subject.
Still need more effort and time to get it done.

Hope it not too far from now :)

Regards.

Alright

 
Chris Mukengeshayi: Yohana, I got interested about that angle, I want to ask you, what are the use of that angle object? How can I make use of it during market analysis?
 
whroeder1:

Um! I have always thought what was the use of than angle object find int the MT platform?

I always ask where do people use such tool within the MT platform?

If its useless why did Meta Quote has include among analytical tools?

 
whroeder1:

Thank you,
that's useful for me

Reason: