1

I have a time-series data and i am trying to calculate angle (degree) between two points. Here is what i did so far but it doesn't seem to give the correct solution:

bars = 2
df = pd.read_csv("EURUSD.csv")
df = df.reset_index()
df['A'] = np.rad2deg(np.arctan2(df['Low']-df['Low'].shift(pts), df['index']-df['index'].shift(pts)))
df.dropna(inplace=True)

However, sometimes this gives me weird outputs like:

2693    3.141258
2702   -3.141383
2708   -3.141451
2719   -3.141033
2724   -3.140893
2734    3.141550

I have also tried the following code:

df['A'] = ((df['Low']-df['Low'].shift(pts))/(df['index']-df['index'].shift(pts)))

2693   -0.000334
2702    0.000210
2708    0.000142
2719    0.000560
2724    0.000700
2734   -0.000043

what am i doing wrong here?

EDIT:

Here is the screenshot i'm trying to do. I'm simply trying to find that -48 degree in Python. I am not trying to get these points automatically. I have spotted them manually and just need to do calculation.

enter image description here

Don Coder
  • 526
  • 5
  • 24
  • Those numbers are awfully close to (+/-) pi and 0... Seems reasonable to me. – erip Oct 04 '18 at 01:00
  • but how can i calculate the degree? Like 45-90-170 and etc? Also this one sometimes calculates 90 or 95 degree which can not be trus for pair pricing – Don Coder Oct 04 '18 at 08:08

2 Answers2

0

I guess that your question is how do I calculated the angle between two lines? Where those lines are each of them defined by a single point and a common origin. Then you want to perform this operation for a series of x1, x2 points recorded over time.

Here you can find the arithmetics and here an example.

braulio
  • 543
  • 2
  • 13
0

To get your line angle between the two points, you'll need the following:

  • price difference (looks like 1.29250 - 1.29650 = -0.004)
  • number of bar between the two points (That appears to be 10 bars)
  • Price to Bar ratio (you'll have to look at the settings for that particular graph)
price_diff = -0.004

bars = 10

price_to_bar = unknown

X = bars * price_to_bar

Final output:

import numpy as np

round(np.angle(complex(x, price_diff), deg=True), 0)
Flair
  • 2,609
  • 1
  • 29
  • 41
Derek F
  • 1
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 13 '21 at 04:46