Angle of Trendline

 

i create Trend line by angle with code

    ObjectCreate(0,"a",OBJ_TRENDBYANGLE,0,iTime(_Symbol,PERIOD_H1,10),iClose(_Symbol,PERIOD_H1,10),iTime(_Symbol,PERIOD_H1,15),iClose(_Symbol,PERIOD_H1,15));
    ObjectSetInteger(0,"a",OBJPROP_COLOR,clrBlue);
    ObjectSetInteger(0,"a",OBJPROP_SELECTABLE,true);


and draw trend line and selectable ,  when i select trend line and go to properties i see angle in degrees , but when i want read angle with code:

Print( ObjectGetDouble(0,"a",OBJPROP_ANGLE));

after run this line of code trend line changed and print "90".

--------------------------------------

i see second trend line angle is '90' degree , but why trend line changed ? any advise ?

 
tinivini: i create Trend line by angle with code

ObjectCreate(0,"a",OBJ_TRENDBYANGLE,0,iTime(_Symbol,PERIOD_H1,10),iClose(_Symbol,PERIOD_H1,10),iTime(_Symbol,PERIOD_H1,15),iClose(_Symbol,PERIOD_H1,15))
  1. TL by angle only has one anchor point. Then you must set the OBJPROP_ANGLE.

    1. There is no angle from 2 anchor points. An angle requires distance divided by distance; a unit-less number. A chart has price and time. What is the angle of going 30 miles in 45 minutes? Meaningless!

    2. You can get the slope from a trendline: m=ΔPrice÷ΔTime. Changing the price scale, bar width, or window size, changes the apparent angle, the slope is constant. Angle is meaningless.

    3. You can create an angled line using one point and setting the angle (Object Properties - Objects Constants - Standard Constants, Enumerations and Structures - MQL4 Reference.) The line is drawn that angle in pixels. Changing the axes scales does NOT change the angle (and thus is meaningless.)

    4. If you insist, take the two price/time coordinates, convert them to pixel coordinates and then to apparent angle with arctan.
                How to get the angle of a trendline and place a text object to it? - Trend Indicators - MQL4 programming forum - Page 2

 
William Roeder #:
  1. TL by angle only has one anchor point. Then you must set the OBJPROP_ANGLE.

for create TL we need two point :

iTime(_Symbol,PERIOD_H1,10),iClose(_Symbol,PERIOD_H1,10),iTime(_Symbol,PERIOD_H1,15),iClose(_Symbol,PERIOD_H1,15)

when i can create this TL and going to properties and see angle in degrees value  , system automatic calculate this angle , so we must can read this value without any extra code .

When the system itself calculates it, why should I calculate it again? I just want to read the value of that variable



 
any solution?
 
tinivini #:
any solution?
Use ChartRedraw() function after setting up your object properties, then you're able to print/get values correctly.
 
_MAHA_ #:
Use ChartRedraw() function after setting up your object properties, then you're able to print/get values correctly.

i also using ChartRedraw() . when i using debugging mode , my code works fine ! but when i use backtest or real time my code work wrong !


please click on GIF and look my code.

حاجی دهنم سرویس شد هرچی باهاش ور رفتم درست کار نکرد . ببین میتونی یه کمکی کنی


 
tinivini #:

i also using ChartRedraw() . when i using debugging mode , my code works fine ! but when i use backtest or real time my code work wrong !


please click on GIF and look my code.

حاجی دهنم سرویس شد هرچی باهاش ور رفتم درست کار نکرد . ببین میتونی یه کمکی کنی


Wait for the market to be opened to run your ea in real time. ST sucks...
 
Maybe you could just change the existing object, instead of deleting and continuously recreating the object.

Change its coordinate points.
Reason: