I'll leave this here if anyone else is searching. But I made a silly mistake. I was using the bar numbers and prices as is when I fed it to atan2(). Since I wanted the angle that *is on the screen* I needed to use bar_to_pixel() and price_to_pixel(). I am embarrassed that it took me a couple hours this morning to figure out my mistake.

~~~
Hi All,
I am trying to calculate the angle of a trendline via Qscript. For the life of me I cannot find my mistake.

Here is a picture for reference. I have the tops and bottoms labeled in red with the variable names I used for the bar and price values. In teal I print the angle. And as you can see the angle is nowhere close to what the protractor is saying it should be. Here is a snippet of my QScript (mround() is a simple function I wrote to just truncate. Similar to the Excel variant.):
Code: Select all
tl = trendline(lastTopBar, lastTop, newBottomBar, newBottom, red);
#trendline(bar1, price1, bar2, price2, color)
#atan2(bar2-bar1,price2-price1)
redAngle = 270-mround(atan2(newBottomBar-lastTopBar,lastTop-newBottom),1);
thanks

Steven