Close Navigation
Learn more about IBKR accounts
Price Action Trading Concepts – Part IV

Price Action Trading Concepts – Part IV

Posted November 3, 2021
Kevin Patrao
QuantInsti

See Part I for an overview of price action trading and the different types of charts, and Part II & Part III to get insight on the concept of support and resistance.

Next, we will plot and compare the normal close price graph with the smoothened close price graph.

Normal vs Smoothened close price of asset

To identify the local minima and local maxima points we have created two functions namely: the pythg() function and the loc_min_max() function.

# Pythagoras function to calculate distance between two points
def pythg(pt1, pt2):
    a_sq = (pt2[0] - pt1[0]) ** 2
    b_sq = (pt2[1] - pt1[1]) ** 2
    return sqrt(a_sq + b_sq)

# Function to calculate Local minima and maxima points
def loc_min_max(points):
    loc_minima = []
    loc_maxima = []
    prev_pts = [(0, points[0]), (1, points[1])]
    for i in range(1, len(points) - 1):
        append_to = ''
        if points[i-1] > points[i] < points[i+1]:
            append_to = ‘min’
        elif points[i-1] < points[i] > points[i+1]:
            append_to = ‘max'
        if append_to:
            if loc_minima or loc_maxima:
                prev_distance = pythg(prev_pts[0], prev_pts[1]) * 0.5
                curr_distance = pythg(prev_pts[1], (i, points[i]))
                if curr_distance >= prev_distance:
                   prev_pts[0] = prev_pts[1]
                   prev_pts[1] = (i, points[i])
                   if append_to == ‘min’:
                       loc_minima.append((i, points[i]))
                   else:
                       loc_maxima.append((i, points[i]))

            else:
                prev_pts[0] = prev_pts[1]
                prev_pts[1] = (i, points[i])
                if append_to == ‘min’:
                    loc_minima.append((i, points[i]))
                else:
                    loc_maxima.append((i, points[i]))

    return loc_minima, loc_maxima
Minima maxima.py hosted with ❤ by GitHub

The loc_min_max() function loops through all the points ranging from index 1 to -1.

If any given point is smaller than the previous point and the next point, it is a local minima. Similarly, if a point is greater than the previous point and next point, it is termed a local maxima.

You will notice that we may have many local minima and local maxima points if we follow the above logic. To avoid encountering this problem, we have defined the pythg() function. We use the pythg() function to compute the distance between the current point and the previous point along with the distance between the current point and the next point.

We select a point as a local minima or local maxima only if the distance between the current point and the next point is greater than half the distance between the current and previous points.

The following is the plotted result of the local minima and maxima points computed using the above functions.

Local minima and maxima points

In the next step, we will try to identify all potential support and resistance lines.

For additional insight on this topic visit QuantInsti blog: https://blog.quantinsti.com/price-action-trading/.

Disclosure: Interactive Brokers

Information posted on IBKR Campus that is provided by third-parties does NOT constitute a recommendation that you should contract for the services of that third party. Third-party participants who contribute to IBKR Campus are independent of Interactive Brokers and Interactive Brokers does not make any representations or warranties concerning the services offered, their past or future performance, or the accuracy of the information provided by the third party. Past performance is no guarantee of future results.

This material is from QuantInsti and is being posted with its permission. The views expressed in this material are solely those of the author and/or QuantInsti and Interactive Brokers is not endorsing or recommending any investment or trading discussed in the material. This material is not and should not be construed as an offer to buy or sell any security. It should not be construed as research or investment advice or a recommendation to buy, sell or hold any security or commodity. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.

IBKR Campus Newsletters

This website uses cookies to collect usage information in order to offer a better browsing experience. By browsing this site or by clicking on the "ACCEPT COOKIES" button you accept our Cookie Policy.