Everything is political

I was reading a book, "If I want to change the world" by sociologist Sabrina Fernandes and I came across one of the chapters, which was about class consciousness and neutrality and how neutrality…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Defining Technical Chart Patterns Programmatically

Ever wondered how to programmatically define technical patterns in price data?

At the fundamental level, technical patterns come from local minimum and maximum points in price. From there, the technical patterns may be defined by relative comparisons in these min/max points.

Let’s see if we could have played this by algorithmically identifying any inverse head & shoulders patterns!

The following code can easily be retooled to work as a screener, backtester, or trading algo, with any timeframe or patterns you define.

I wrote this function to grab data beyond the one request limit of 2,000 minute bars. Later we’ll resample to our timeframe of choice.

We’ll resample data separately, in case we want to try out different timeframes later.

For this step we’ll use a function from scipy’s signal processing library to find peaks in the data.

This code looks complicated, but the point is to return the integer index values with price, for each min/max point.

Let’s plot it with the resampled price data to visually confirm we’re on the right track.

To find patterns, we simply iterate over all our min max points, and find windows where the points meet some pattern criteria.

For example, an inverse head and shoulders can roughly be defined as:

C < A, B, D, E

A, E < B, D

To filter for head and shoulders with even necklines:

abs(B-D) < np.mean([B, D])*0.05

(The difference between the necklines must not be more than 5%.)

Here’s the code:

And a plot for visual confirmation:

As you can see, we are getting more patterns than we need. Our params (smoothing and window range) are too sensitive for this timeframe (60 minutes).

In order to find the best params, I reorganized my code into functions and iterated through multiple stocks, smoothing, and window parameters.

Run the above like so:

Now we can see how our timeframes, patterns, and params are playing out!

To use this live, I made the following changes to screener():

And ran like so:

Finding the right params for your pattern to play out may take experimentation. See the results() function in the notebook to confirm whether your patterns have a positive edge or not.

Add a comment

Related posts:

One thing great copywriters do is this.

It can be traveling to a new country or the city/state next door. When you experience a new environment, your senses react and you embrace novelty. In my 32 years of life, I’ve been on many trips…

Why FVEY could help Huawei to really boost 4G and push FVEY backwards

When you look at the FVEY regions and how they are deciding that Huawei potentially should not be any part of/involved in the 5G roll out starting this year, the regions across Africa, Asia and the…

The Scrum Software Development Process

The product backlog is a list of all features that should be implemented during the development process. It’s ordered by priority and it’s every item is called a User story or Features. Every feature…