Calculation of support/resistance zones

Keywords: resistance zone, support zone, close price, original array, green zone, green candle, group, epsilon, list, programming, computer, logic. Powered by TextRank.

support/resistance zones are quite essential when trading breakouts. Support is a line below the price on the charts that the price bounced back from a couple of times. Resistance is the same, but above the price. When a human looks at a chart, it’s pretty easy for them to see these points on the chart:

ecosrz1.png

the shaded are is a support/resistance zone, as the price tries multiple times to go past that point and succeeds with that long green candle. How to get the computer to recognize these points it an interesting exercise in programming. The logic is this:

  1. gather all open, high, low close prices in an array and sort them.
  2. define a parameter, called epsilon that will be the sensitivity for the zone.
  3. start from the first price and group all prices less than epsilon away from this in a list.
  4. remove the added prices from the original array and continue group the remaining prices.

in the end you will have a list of lists. The more items in the list, the stronger the support/resistance around that area.

The worst case running time for the above algorithm is n^2 if all the prices are more than epsilon away from each other, which is not very good. So we need to improve on that.

We can build the groups as we are iterating the original array like this:

  1. maintain a list of groups, initialized with a single group containing the first price.
  2. as we are iterating over the array, if the current element is less than epsilon away from the head

of the group we add it to that group. Otherwise we create a new group and add it into that group.

Collections.sort(data);
        SuperList<SuperList<Double>> groups = new SuperList<>();
        groups.add(new SuperList<>());
        groups.get(0).add(data.get(0));
        for (int i = 1; i < data.size(); i++) {
            SuperList<Double> group = groups.getLast();
            Double x = data.get(i);
            if (Math.abs(x - group.get(0)) < epsilon) {
                group.add(x);
            } else {
                SuperList<Double> newList = new SuperList<>();
                newList.add(x);
                groups.add(newList);
            }
        }

I finally had the chance to plot the results of this, so I updated the post:

ecosrz2.png

The red zones are the resistance which is all tuples with price above the last close price and the green zones are the support zones.


Metadata

387 words

Similar posts

Powered by TF-IDF/Cosine similarity

First published on 2019-07-23

Generated on 13 Dec 2024 at 12:11 AM

Index

Mobile optimized version. Desktop version.