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.

Price Action Trading Concepts – Part IV


Visit: 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]))
                       loc_maxima.append((i, points[i]))

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

    return loc_minima, loc_maxima
Minima 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:

Disclosure: Interactive Brokers

Information posted on IBKR Traders’ Insight that is provided by third-parties and not by Interactive Brokers does NOT constitute a recommendation by Interactive Brokers that you should contract for the services of that third party. Third-party participants who contribute to IBKR Traders’ Insight 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 permission from QuantInsti. The views expressed in this material are solely those of the author and/or QuantInsti and IBKR 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 sell or the solicitation of an offer to buy any security. To the extent that this material discusses general market activity, industry or sector trends or other broad based economic or political conditions, it should not be construed as research or investment advice. To the extent that it includes references to specific securities, commodities, currencies, or other instruments, those references do not constitute a recommendation to buy, sell or hold such security. 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.

In accordance with EU regulation: The statements in this document shall not be considered as an objective or independent explanation of the matters. Please note that this document (a) has not been prepared in accordance with legal requirements designed to promote the independence of investment research, and (b) is not subject to any prohibition on dealing ahead of the dissemination or publication of investment research.

Any trading symbols displayed are for illustrative purposes only and are not intended to portray recommendations.

trading top