Python Forum
An important question is how to create a zigzag in price data? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: An important question is how to create a zigzag in price data? (/thread-31025.html)



An important question is how to create a zigzag in price data? - epsilon - Nov-18-2020

Example "argrelextrema" lists:
""liste_1 = list(argrelextrema(price_high.values, np.greater, order=1)[0])""
""liste_2 = list(argrelextrema(price_low.values, np.less, order=1)[0])""

list_1 = [2, 11, 13, 21, 27, 33, 35, 40, 43, 45, 47, 53, 55, 57, 59, 62, 69, 74, 76, 81, 84, 86, 89, 98]
list_2 = [4, 6, 8, 14, 17, 20, 25, 32, 41, 44, 49, 54, 56, 58, 61, 63, 72, 75, 78, 81, 83, 85, 90, 95]
total_list = []

These lists are prepared with the "argrelextrema" of the high and low values of a price (parity). Now, to be able to zigzag, each element in the total_list must have an element from the opposite list to the left and right. (up and down) But the problem is, for example list_2 has between "4 and 6" and "6 and 8" have no elements from list_1. In the method I tried, there are no 4 and 6 in the total list, but there is 8 (because there is an element from list_1 between 8 and 14) Thus, points up and down are determined. But maybe instead of 8 it should have been 4 or 6 in total_list. (There is an original price list, maybe 4th and 6th prices are lower than 8th.)

In short, I want to draw a correct zigzag.
Of course, later I will check if the difference between the prices represented by each element of this list is greater than 0.0025.