1
$\begingroup$

Before anybody asks please let me confirm this question is related to trading technical analysis.

The problem is quite simple, but I lack the scientific background required to solve it.

Data comes as an array of float values equally spaced temporally. Some local minimums (same apply for maximums) tend to repeat over time (although not at the very same value, but in a rather tight range), because of human psychology: if some price level was important in the past, stopping the price to go below, it will tend to resurface a few times, blocking again the price from going below.

What I'm interested in is to find the most significant levels over a given past period (say 5000 time intervals). Basically the "importance" of a level is determined by the number of times it was tested (meaning the number of times the price tried go past that level and failed); however, a level tested three times at relatively large time intervals (like once each month for a daily chart) is more significant than a level tested three times in a short period (like within a week for a daily chart).

Again, data is as follows:

  • data comes as an array of float values
  • data points are equally spaced temporally (however, time is of little to no importance)
  • some local extremes are more important than others and tend to repeat over time

Can somebody help me with some Python code to extract important levels? Or at least point me to some theory/frameworks to learn? I know about pandas/numpy but I lack the math background required to a least identify what could be used of these...

Thank you!

enter image description here

$\endgroup$
4
  • $\begingroup$ So you're trying to find which local maxima and minima occur most frequently? $\endgroup$
    – user4710
    Sep 20 '16 at 16:38
  • $\begingroup$ Basically yes, keeping in mind they may be grouped in a range instead of touching the exact same value. $\endgroup$ Sep 21 '16 at 14:20
  • $\begingroup$ Can you plot your values, to get an idea of the how your data typically looks like? $\endgroup$
    – daniel451
    Sep 22 '16 at 5:53
  • $\begingroup$ Hi @ascenator, here's a graph onto which I marked in red an "important" level, as it was tested multiple times (aka the price tried to go higher but the level "resisted"): dwq4do82y8xi7.cloudfront.net/x/ht49yWn8 $\endgroup$ Sep 26 '16 at 12:30
1
$\begingroup$

You could define a window (distance between red and blue line) and slide it from top to bottom over the y-axis and then count the local minima and maxima in that slice. One way with scipy is argrelextrema(x, np.less) for minima and argrelextrema(x, np.greater) for maxima which gives you the indices of the extrema. With len(argrelextrema(x, np.less)) you would get the number of minima.

Each slice would be a level and the results of counting the minima and maxima the corresponding importance. The size of the window is up to you. If your data is very granular you might want to consider smoothing it first (e.g. with numpy.convolve()

$\endgroup$
2
  • $\begingroup$ Haha, nice one, although it doesn't address significance (far apart extremes are more significant than those grouped in a small time range). Thank you! $\endgroup$ Sep 27 '16 at 13:40
  • $\begingroup$ Since your data is equally spaced you can simply compute the differences in the indices to compute the time between two extrema (e.g. with pandas' diff function). $\endgroup$
    – oW_
    Sep 27 '16 at 16:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.