1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Find minimum and maximum values in OHLC data

Discussão em 'Python' iniciado por Stack, Setembro 14, 2024.

  1. Stack

    Stack Membro Participativo

    I would like to find (in python) the local minimum and maximum values in OHLC data, under the condition that the distance between these values is at least +-5%.

    Temporal Condition

    Note that

    • for an UP movement (close>open), low price comes BEFORE high price
    • for a DOWN movement (close<open), low price comes AFTER high price

    The best way to explain what I would like to achieve is by a graphical example:

    [​IMG]

    OHLC data is in this format:

    open_time open high low close
    2023-07-02 0.12800000 0.12800000 0.12090000 0.12390000
    2023-07-03 0.12360000 0.13050000 0.12220000 0.12830000
    2023-07-04 0.12830000 0.12830000 0.12320000 0.12410000
    2023-07-05 0.12410000 0.12530000 0.11800000 0.11980000
    2023-07-06 0.11990000 0.12270000 0.11470000 0.11500000


    The result should be something like:

    date1 val1 date2 val2 <---up
    date2 val2 date3 val3 <---down
    date3 val3 date4 val4 <---up
    date4 val4 date5 val5 <---down
    .
    .
    .


    As for the data in the example the result should be:

    2023-07-02 0.1280 2023-07-02 0.1209 -5.55%
    2023-07-02 0.1209 2023-07-03 0.1305 7.94%
    2023-07-03 0.1305 2023-07-06 0.1147 -12.11%


    Is there a name for this task?


    ADDENDUM

    I add a new example, with a different condition (+-3%).

    This is the data:

    2022-02-25 38340.4200 39699.0000 38038.4600 39237.0600
    2022-02-26 39237.0700 40300.0000 38600.4600 39138.1100
    2022-02-27 39138.1100 39881.7700 37027.5500 37714.4300
    2022-02-28 37714.4200 44200.0000 37468.2800 43181.2700
    2022-03-01 43176.4100 44968.1300 42838.6800 44434.0900


    And the final result shold be:

    2022-02-25 38038 2022-02-26 40300 5.95%
    2022-02-26 40300 2022-02-26 38600 -4.22%
    2022-02-26 38600 2022-02-27 39881 3.32%
    2022-02-27 39881 2022-02-27 37027 -7.16%
    2022-02-27 37027 2022-02-28 44200 19.37%
    2022-02-28 44200 2022-03-01 42838 -3.08%

    Continue reading...

Compartilhe esta Página