Click here to Skip to main content
15,435,939 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can i locate AND label local minima and maxima in a dataset?

like when i have the following set as an example of floats like:



Python
400.510009765625, 423.8999938964844, 420.9800109863281, 438.0899963378906, 429.95001220703125, 421.260009765625, 410.3599853515625, 417.1300048828125, 411.760009765625,



and then i compare each adjacent value to the previous by this simple loop:



Python
for x in range(0,len(nfy)): 
    if nfy[x]<nfy[x+1]: 
        print('raising')
    elif="" nfy[x]="">nfy[x+1]:
        print('falling')





i will get a ongoing list of prints of that comparison like:

raising
falling
raising
falling
falling
falling
raising
falling
falling
falling
raising

and so on.

Now my question is: how can i remember, or label, if there is a local minima or a local maxima, compared or related to the surrounding values?

I need to be abble to apply these simple rules here:


The local minima of a falling value (the latest price in a single or a series of "falling" values), after (a series or single) raising values never retraces more than the initial startpoint (which has to be smaller than the next values: it has to be rising).
The turning point from rising to falling values needs to be labeled as "number 1" and is represented by a local maxima.
The turning point from the first falling values to the next rising values needs to be labeled as "number 2" and is a local minima.

When this conditions are met, there has to be a series of raising values which need to exceed the first "local maxima" which has been labeled as "number 1".

The next shift from rising to falling values need to be lebeled as "number 3" and would represent a local maxima.

I want to add in the additionall condition, that "number 3" needs to be higher than "number 1" AND also needs have the largest extend (range), which would be represented by: "number 1" - "startingpoint" < "number 3" - "number 2" (which means the total lenght of the impulse from the starting point to the first maxima needs to be smaller than the total lenght from the first local minima to the seond local maxima.

Then, if these conditions are met, i want to add in the condition, that the next local minima (after local maxima "number 3") is valid, when there is a change from falling values after "number 3" has been labeled to rising values again, which would be labeled as "number 4" and would be represented by a local minima.
Additionally i like to add in the condition, that "number 4" cannot be equal or smaller than the value of "number 1".

**How the hell do i set up this loops?**
How can i translate that into working code?

this is, by the way, a very complicated extraction of the Rules that are based on Elliott Wave Theory. I want to apply this on Stockcharts to count waves.


Best wishes and many thanks,
Benjamin

What I have tried:

for x in range(0,len(nfy)):
if nfy[x]<nfy[x+1]:
="" print('raising')
="" elif="" nfy[x]="">nfy[x+1]:
print('falling')
Posted
Updated 6-Oct-21 2:56am
v3

1 solution

This is essentially the same question as How can I set up a programm that counts waves on a chart?[^]. You just need to make a note in a list for each of the values that you are interested in. So when you transition from rising to falling, the current value is the maximum of the previous set, so save the index in your maxima list. Do the same for minimum values. You should then be able to traverse your lists and print the values you have identified.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900