Get Angle in CChartObjectTrendByAngle

 

Hi Guys,

Metatrader 5 

Version: 5.00 Build 1940

02 nov 2018


I Created a trend line by angle like it:

#include <ChartObjects\ChartObjectsLines.mqh>

CChartObjectTrendByAngle trend;

trend.Create(0,"HowGetAngle",0,time1, price1, time2, price2));

When I try get a angle:

double trend_angle = trend.Angle();

I get 90.0 even if I change points coordinates like it.

trend_angle.SetPoint(0,new_time1,new_price1);
trend_angle.SetPoint(2,new_time2,new_price2);

I read many times this documentation: https://www.mql5.com/en/docs/standardlibrary/chart_object_classes/obj_lines/cchartobjecttrendbyangle

Thanks

Documentation on MQL5: Standard Library / Graphic Objects / Line Objects / CChartObjectTrendByAngle
Documentation on MQL5: Standard Library / Graphic Objects / Line Objects / CChartObjectTrendByAngle
  • www.mql5.com
Standard Library / Graphic Objects / Line Objects / CChartObjectTrendByAngle - Reference on algorithmic/automated trading language for MetaTrader 5
 
MT4 but should be similar. Please check if that helps.
Is there a solution to get angle value on OBJ_TRENDBYANGLE by code?
Is there a solution to get angle value on OBJ_TRENDBYANGLE by code?
  • 2018.04.08
  • www.mql5.com
Dear experts, @Alain Verleyen @whroeder1 To this day, I am still wondering why the angle value remains zero when I create the OBJ_TRENDBYANGLE obje...
 
Alain Verleyen:
MT4 but should be similar. Please check if that helps.

Excellent, Thanks

 

Hi!

Just plug in the coordinates of two points into this function. The angle will be the same as the TrendLinebyAngle on the chart. Absolutely no bugs!

        double getAngleTwoPoints(double price1,long time1,double price2,long time2, long chart_id = 0)
          {
           double result=0;

           int x1=0,x2=0;
           int y1=0,y2=0;
           long chart = ChartGetInteger(chart_id,CHART_HEIGHT_IN_PIXELS,0);

           ChartTimePriceToXY(chart_id,0,time1,price1,x1,y1);
           ChartTimePriceToXY(chart_id,0,time2,price2,x2,y2);
           int size = (int)chart;
           y1=size-y1;
           y2=size-y2;
           double angle =NormalizeDouble((MathArctan(((double)y2-(double)y1)/((double)x2-(double)x1))*180)/M_PI,1);
           result=angle;
           return(result);
          }