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

Contributor:
QuantInsti
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]))
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.