# We are looking for patterns on the stock exchange

If you decide to learn how to trade on the exchange, then you need to learn how to find patterns on it. A pattern is a certain condition (for example, a characteristic price movement or some kind of event), after which you will know where the price will go next.

In training courses, brokers teach novice traders to find and use patterns. But almost all newcomers in the end lose their money. Below I will show why this is happening.

## The basics

The entire exchange trading industry revolves around two methods of price forecasting:

- technical analysis;
- fundamental analysis;

Technical analysis says that price movement can be predicted based on its previous movement. For example, if the price chart draws a “Head and Shoulders” figure, then the likelihood that the price will unfold increases.

**Figure 1 - figure "Head and shoulders"**

In contrast to it, fundamental analysis says that price movements can be predicted by analyzing external information factors (for example, financial statements, past events, etc.).

## Check if the technical analysis works

There are thousands of ways to predict prices. These are various patterns of movement (patterns), indicators, oscillators, neural networks, etc.

All of them are united by one common feature: they allow us to predict the future price movement based on its previous values.

## Put forward a hypothesis

Now imagine the situation that over the next hour, the price will move in the same way as it did over the course of an hour 3 years ago.

If you apply the same methods of technical analysis inside these identical sections of the graph, then they will give the same readings.

This thought experiment proves that instead of looking for a working method of technical analysis, you can look for similar parts of the chart, after which the price behaves in a similar way. Further I will call such sites "models".

The obvious advantage of searching for models is that you save time on finding a working method of technical analysis. There are thousands of such methods, and every day brokers, dealers, and various "educators" of stock trading come up with several more new methods. The problem is that you don’t have enough life to test all the trading methods that you are offered to work (by the way, this is the calculation).

## Let's do an experiment

To search for models, we will write a program that analyzes minute charts of the assets of interest to us over the past few years and identifies patterns.

#### 1. Data preparation

Download the charts for the tool we are interested in. In my example, I used the per-minute quote of the EUR / USD currency pair over the past 10 years.

We pre-process the data: we sparsim from unloading only the closing price of each minute, we break the schedule into weekly sections and eliminate sharp price spikes due to the non-working time of the exchanges.

Now we break this chart into 2 halves of 5 years. In the first half, we will look for working models, and in the second, we will check how well the models found will work in reality.

#### 2. Search for models

In the first 5-year period, we:

- iterate over all the values of the graph;
- for each value, remember N previous values (N will be successively changed from 10 to 1000) and M subsequent (you can take any value <= N, in this experiment M = 0.3 * N);
- each plot section (length N) obtained in (paragraph 2) is comparable to all other sections of this 5-year schedule (length N), and its extensions (length M) are comparable to the extensions of the corresponding sections;

*Note on p. 3: To compare pairs of sections of the graph, I used the least squares method, minimizing the quadratic deviation (hereinafter referred to as standard deviation). The lower it is, the more similar 2 fragments of the graph are.*

**Figure 2 - Illustration comparing two sections of a graph of length N**

*RMS is calculated by the formula:*

*where:*

*X1i is the value of the first plot of the graph at time i;**X2i is the value of the second plot of the graph at time i;**X0 - shift of the reference point along the vertical axis (calculated from the same formula);**i is the time;**n is the length of the compared sections of the graph;*

As a result of such enumeration (see p. 3), we get a large number of comparison results for each section of the graph and its continuation (see p. 2). Further, we will call these sections potential models.

In order to understand whether the potential model is working, for each enumeration (see section 3), it is necessary to determine whether there is a relationship between:

- The magnitude of the standard deviation between the potential model and the plot being compared (hereinafter - standard deviation 1);
- and the standard deviation between the continuation of the potential model and the continuation of the plot being compared (hereinafter - standard deviation 2);

**Figure 3 - Illustration of the search for dependencies between RMS1 and RMS2**

namely:

- If, with a decrease in RMS1, RMS2 will also decrease - then the potential model is working and it can be used in trade;
- If, with a decrease in RMS1, RMS2 will change randomly - then the potential model turned out to be inoperative;

We exclude from the list of potential models those in which, with a decrease in RMS1, RMS2 does not decrease.

Thus, we get a large number of models with which you can predict the movement of prices in the market.

#### 3. Checking models on real data

Now, for each model found, we calculate how much money she would have earned in the first 5-year section (on it we trained the system to look for models) and in the second 5-year section (until now we did not touch this data, so checking the models on them will allow reliably assess the earning potential).

We apply the obtained values to the coordinate plane, where:

- along the X axis, we note the profit that the models we found would receive in the first 5-year period of the chart;
- along the Y axis, we note the profit that the models we found would receive in practice (in the second 5-year period);

To make the data easier to read with the naked eye, the chart below:

- only 0.1% of the total number of calculated points is displayed;
- only the results of those models were derived, trading on which would be profitable in the first 5-year period;
- the horizontal axis is divided into 10 equal sections, for each of which the average value is calculated (marked with blue lines)

**Figure 4 - a graph of the dependence of the real profitability of the models (Y) on their profitability in the area used for training (X)**

As you can see, the better the model found works on the test plot of the chart, the better it works in combat conditions.

It turns out that there are models on the exchange that work.

#### 4. Forecasting the profitability of trade

Before you consider how much money you can earn on the models, you need to add the spread and / or broker commission to our calculations.

According to my calculations, when trading with the EUR / USD pair, on average you will pay from 2 points per transaction (about 0.015% of the current value of the currency pair).

To begin with, let's try to add 1 point of commissions to the algorithms for searching and checking models. We get the graph:

**Figure 5 - a graph of the dependence of the real profitability of the models (Y) on their profitability in the area used for training (X), taking into account commissions, the size of 1 point**

Now increase the size of commissions to 2 points

**Figure 6 - a graph of the dependence of the real profitability of the models (Y) on their profitability in the area used for training (X), taking into account commissions, the size of 2 points**

It turns out that if the size of the spread and commissions in the amount exceeds 1 point, then trading on models on the EUR / USD currency pair will bring losses.

## findings

In this experiment, we found similar sections of the charts and checked in which direction the price would move after they passed.

Those sections, after the passage of which the price moved in the same direction, we considered patterns (models) and turned out to be right (see Figure 4).

However, using the same models in a real situation, we could not get a profit the size of which would exceed the size of the spread and broker commission.

Based on this, we can draw the following conclusions:

- There are patterns on exchanges and they can be found using technical analysis;
- Most of these patterns do not allow you to earn amounts that exceed the size of the spread and broker commissions;
- From the first two points it follows that most brokers and dealers who advertise trading on the exchange as a means of earning money are deceiving people. They appeal to our emotions, promising a better life, but in fact they teach to lose money. It's my personal opinion.

If you liked the article, I can post the results of several more experiments.