0

I'm dealing with some datasets of OHLC data, and I'm trying to find a way to determine the steepness of that data at a given point.

Literally, given a specific point, I need to find a way to know if at that point the line is going up, down, or sideways, so I would need to find some sort of coefficient that tells how steep the line is at the specific point.

Here is a sample of a dataset, it's very specific stuff:

Close
2021-03-04 07:00:00  1571.53
2021-03-04 08:00:00  1571.11
2021-03-04 09:00:00  1547.29
2021-03-04 10:00:00  1557.74
2021-03-04 11:00:00  1561.59
2021-03-04 12:00:00  1561.28
2021-03-04 13:00:00  1567.00
2021-03-04 14:00:00  1574.28
2021-03-04 15:00:00  1577.22
2021-03-04 16:00:00  1584.92
2021-03-04 17:00:00  1562.29
2021-03-04 18:00:00  1507.77
2021-03-04 19:00:00  1526.71
2021-03-04 20:00:00  1531.00
2021-03-04 21:00:00  1517.97
2021-03-04 22:00:00  1529.71
2021-03-04 23:00:00  1539.23
2021-03-05 00:00:00  1478.94
2021-03-05 01:00:00  1463.28
2021-03-05 02:00:00  1480.97
2021-03-05 03:00:00  1481.67
2021-03-05 04:00:00  1465.48
2021-03-05 05:00:00  1472.41
2021-03-05 06:00:00  1479.99
2021-03-05 07:00:00  1474.17
2021-03-05 08:00:00  1456.06
2021-03-05 09:00:00  1469.80
2021-03-05 10:00:00  1471.51
2021-03-05 11:00:00  1480.15
2021-03-05 12:00:00  1482.47
2021-03-05 13:00:00  1489.47
2021-03-05 14:00:00  1493.41
2021-03-05 15:00:00  1481.41
2021-03-05 16:00:00  1477.98
2021-03-05 17:00:00  1507.11
2021-03-05 18:00:00  1521.66
2021-03-05 19:00:00  1533.58
2021-03-05 20:00:00  1533.36
2021-03-05 21:00:00  1531.68
2021-03-05 22:00:00  1536.38
2021-03-05 23:00:00  1528.31
2021-03-06 00:00:00  1542.00
2021-03-06 01:00:00  1534.70
2021-03-06 03:00:00  1531.70
2021-03-06 04:00:00  1529.28
2021-03-06 05:00:00  1574.67
2021-03-06 06:00:00  1578.37
2021-03-06 07:00:00  1589.31
2021-03-06 08:00:00  1574.99
2021-03-06 09:00:00  1564.03
2021-03-06 10:00:00  1563.93
2021-03-06 11:00:00  1564.07
2021-03-06 12:00:00  1542.18
2021-03-06 13:00:00  1528.55
2021-03-06 14:00:00  1541.65
2021-03-06 15:00:00  1544.41
2021-03-06 16:00:00  1580.20
2021-03-06 17:00:00  1600.98
2021-03-06 18:00:00  1615.63
2021-03-06 19:00:00  1620.71
2021-03-06 20:00:00  1653.09
2021-03-06 21:00:00  1642.97
2021-03-06 22:00:00  1665.29
2021-03-06 23:00:00  1650.35
2021-03-07 00:00:00  1671.00
2021-03-07 01:00:00  1641.96
2021-03-07 02:00:00  1656.10
2021-03-07 03:00:00  1648.98
2021-03-07 04:00:00  1656.85
2021-03-07 05:00:00  1663.31
2021-03-07 06:00:00  1662.99
2021-03-07 07:00:00  1684.54
2021-03-07 08:00:00  1668.45
2021-03-07 09:00:00  1684.10
2021-03-07 10:00:00  1675.01
2021-03-07 11:00:00  1678.36
2021-03-07 12:00:00  1669.22
2021-03-07 13:00:00  1663.43
2021-03-07 14:00:00  1648.96
2021-03-07 15:00:00  1652.00
2021-03-07 16:00:00  1669.16
2021-03-07 17:00:00  1675.99
2021-03-07 18:00:00  1655.52
2021-03-07 19:00:00  1658.26
2021-03-07 20:00:00  1649.31
2021-03-07 21:00:00  1664.14
2021-03-07 22:00:00  1678.61
2021-03-07 23:00:00  1726.16
2021-03-08 00:00:00  1742.21
2021-03-08 01:00:00  1736.80
2021-03-08 02:00:00  1723.35
2021-03-08 03:00:00  1723.68

Here is what I tried:

I tried to find a way to calculate the slope of the line, and it partially works. I used a library called pandas_ta, here is the code it uses:

def slope( close, length=None, as_angle=None, to_degrees=None, vertical=None, offset=None, **kwargs):
    """Indicator: Slope"""
    # Validate arguments
    length = int(length) if length and length > 0 else 1
    as_angle = True if isinstance(as_angle, bool) else False
    to_degrees = True if isinstance(to_degrees, bool) else False
    close = verify_series(close, length)
    offset = get_offset(offset)

    if close is None: return

    # Calculate Result
    slope = close.diff(length) / length
    if as_angle:
        slope = slope.apply(npAtan)
        if to_degrees:
            slope *= 180 / npPi

    # Offset
    if offset != 0:
        slope = slope.shift(offset)

    # Handle fills
    if "fillna" in kwargs:
        slope.fillna(kwargs["fillna"], inplace=True)
    if "fill_method" in kwargs:
        slope.fillna(method=kwargs["fill_method"], inplace=True)

    # Name and Categorize it
    slope.name = f"SLOPE_{length}" if not as_angle else f"ANGLE{'d' if to_degrees else 'r'}_{length}"
    slope.category = "momentum"

    return slope

Here is the problem: The problem now is that the output of that function works and it gives me what I'm looking for but it depends heavily on the magnitude of the data I'm feeding (of course) and this is a problem because I'm using other datasets with much lower numbers.

Instead, is there a way to get some sort of coefficient or number that tells me the inclination of the line for every point? Any kind of advice is appreciated

mike_thecode
  • 171
  • 2
  • 6
JayK23
  • 287
  • 1
  • 15
  • 49
  • 1
    this post may help https://stackoverflow.com/q/55649356/13273054 – kiranr Apr 14 '21 at 23:36
  • Do you have lat/long or x/y? – wwnde Apr 14 '21 at 23:37
  • instead of giving your full data set, could you give two small data sets with 5 points each, and are different in "magnitude" and give "lower numbers", and then some idea of what type of coefficient that you'd like based on these. (It's hard to understand what you're looking for hear since you're very clear in the setup but are using vague descriptors in the problem statement.) – tom10 Apr 15 '21 at 03:24
  • Yes, sorry for not being specific enough. As for the other datasets, I'm dealing with stock prices, so consider another dataset same as the one I provided but with much lower prices such as 10, 12, 15 instead of 1500, I will add it to the question. As for the coefficient, I just need to get some way to know the inclination of the line on each point when that dataset is plotted – JayK23 Apr 15 '21 at 06:45
  • @JayK23: OK. Skip my last suggestion, and say as your second data set you took the original times just as they are, but took the original values and divided them all by 10. Would this be representative of the two types of data sets you're considering? Now, if you did this, the "inclination of the line on each point" would also be divided by 10. Is this not what you want? Or maybe, eg, it's that you want the slope scaled by the axes, so that if it looks like a line at 45° it says "45°", regardless of the units and scaling of the axes? – tom10 Apr 15 '21 at 19:15
  • ps.. if you put @tom10 in your response I'll be notified if/when you answer my question, and otherwise I may not see it. – tom10 Apr 15 '21 at 19:17
  • @tom10 Thanks! Yes, I'm looking for something that doesn't depend on the magnitude of my data, such as an angle. These datasets are OHLC data so they are simple prices, the problem is that the price of an asset might range around 1500, like in this case, while another assets will have a price range around 0.10, for example; so the slope values are going to be a lot different and it becomes hard for me to perform some analysis. – JayK23 Apr 15 '21 at 19:59
  • I think I'm making it sound more complicated than it actually is, since what I need to know is "is the line at X point going up or down?", I need to work on that – JayK23 Apr 15 '21 at 20:00
  • @JayK23: I dont' think it's getting more clear. you say you want to know, "is the line at X point going up or down?" What line? Is this the line from one point to the previous data point, or a line between two other points, or a fit to a range of data, etc? Do you really just want "increasing vs decreasing", which is probably easier. Overall, data of different scales shouldn't be hard to deal with, it's just a question of stating clearly what you want. – tom10 Apr 15 '21 at 21:34
  • So basically these numbers i provided are moving average values. When i plot these values, at any point the line plotted is going to have a certain inclination, so i want to find a way to determine for any point if the direction of the line (at that point) is down or up. It's the same thing done here with the derivative of the line https://miro.medium.com/max/300/1*dunz7C-rCGs1zajsYWI45w.gif – JayK23 Apr 15 '21 at 21:50
  • For reference, here is where i got that gif and the idea: https://medium.com/swlh/using-the-average-slope-as-a-trading-indicator-deb15fdc4e82 – JayK23 Apr 15 '21 at 21:53

0 Answers0