# The method of linear regression on Forex – all the secrets of application In the most common Forex trading platform Metatrader, as well as in other terminals, you can find linear regression. It is included in the standard set of graphical tools, representing a channel of equidistant parallel segments, automatically constructed by the program.

In today’s article, we will try to figure out what linear regression is and how it can be applied in trading. It will be difficult and interesting) The indicator “breaks off” on the last formed candle. The absence of any trading signals after constructions and projections into the future made linear regression not the most popular and mentioned trading tool. It’s hard to believe that with the help of three drawn lines you can:

• Predict the next day’s closing level;
• Determine the probability of a reversal or continuation of the trend;
• Get a full-fledged trading strategy.

## What is linear regression and why is it suitable for trading? The idea of linear regression (LRI) was discovered in the XIX century by the famous English anthropologist and psychologist Sir Francis Galton through observations of people. A relative of Charles Darwin, fascinated by statistics, noticed a pattern of frequent birth of tall children from small fathers and vice versa – short children from tall men. Francis Galton called this regression to the mean: the natural desire to keep the population size at the level of the average values, which made it possible to predict a sharp “genetic response” to any abnormal deviations.

Currency fluctuations are the best demonstration of such a law. Trends do not happen without corrections, the probability of which increases with increasing volatility more than the average trading range. To identify and evaluate such deviations and corrections, traders often use moving average lines or a Bollinger indicator, which includes a formula for the standard deviation of the upper and lower bounds of the indicator.

Unlike the above indicators, linear regression allows you to more accurately determine the average line to which prices tend. This is clearly shown in the figure below – the Bollinger Bands envelope significantly loses to the average linear regression in terms of the number of returns and crossings of quotes. This accuracy is achieved thanks to a more complex formula and statistical methods for calculating LRI. The middle line is constructed as the most optimal straight line that linearly describes all the “scattered” points in a two-dimensional coordinate system. In the case of trading, these are closing prices (Y–axis) and session times (X-axis). The loss method helps to determine the optimality of constructing a linear regression by calculating the smallest error of the distances between each closing price and a point on the median regression line using the least squares method. The solution of the equation will be a line described by a function of the form f(x)= m*x + b, where b sets the shift of the straight line along the Y axis (exchange rate), and the multiplier m determines the slope or strength of the trend (the larger the angle, the higher it is).

The described method is used in econometrics and in the construction of neural networks to predict future values of exchange rates of currency pairs, stocks, commodities, etc. Using Excel or other specialized programs, the parameters of a linear multiple regression equation are found that allow calculating the closing levels of the next day or week.

If we carry out calculations according to all the rules of econometrics to obtain future closing prices of the day and put them on the chart, then we can see by experience that in small LRI segments in five to ten sessions, approximately the same forecast results are obtained.

To get the estimated closing price of the next session based on a linear regression conducted through five candles, it is necessary to draw horizontal lines from the upper and lower LRI channels parallel to the time axis of the previous candles.

If the trend is growing, then the upper level will be considered the most likely closing price, and the lower level provides for a trend change as the least possible option. This is not a graphical analysis, the data is obtained mathematically, so they work more reliably in a trading strategy than other indicators. ## Forex pair trading strategy based on linear regression data

The Forex linear regression trading strategy will be conditionally divided into two parts. The first one is based on graphical analysis and simple rules. The second part involves using the Excel program to obtain the r2 correlation coefficient, which determines the strength and possible trend reversals.

## Characteristics of the strategy

Platform: Metatrader 4 or any other terminal with the function of building linear regression
Currency pairs: any
Timeframe: D1
Recommended brokers: Alpari, RoboForex, AMarkets

## Rules for building the channel and closing levels of the next day’s candle Linear regression is located in the Metatrader 4 program in the “Channels” section, the “Insert” menu. After selecting the tool, draw a segment by counting 4 figures to the left of the last candle. In total, there should be a segment of five figures in the channel. The trader will have to rebuild the channel on his own every day after the close of trading. The selection should not include the candle of the current day, which is in the process of formation. Along with the channel, the horizontal levels constructed from the upper and lower boundaries of the channel should be updated. ## Strategy rules After building horizontal levels of linear regression, the trader sets two orders:

• Buy stop – 5 (old) points above the horizontal level built from the upper channel;
• Sell stop – lower by 5 points from the horizontal level of the lower regression channel.

After one of the orders is triggered, the second one is canceled and a stop loss is placed:

• At the minimum of the candle of the last session, if the trader entered the market by Buy Stop;
• At the maximum of the previous candle, if the Sell Stop was triggered. In the future, the stop loss, depending on the direction of the open transaction, moves to the Sell Stop or Buy Stop level of the next day. The trader independently determines the possibility of building a pyramid of orders, based on money management considerations, so as not to go beyond the risk of 1-2% of the deposit when a stop loss is triggered. All long positions are closed if the angle of inclination of the LRI becomes negative, short orders are closed at its positive value.

## Determination of trend strength by linear regression correlation coefficient Linear regression can be calculated in an Excel file – it is enough to enter five closing prices of daily sessions and select regression in the “Data Analysis” block via the Excel “Data” menu. The data analysis unit is enabled after activating the “Analysis Package” add-in. Excel add-ins can be accessed via the File menu and the Options option. The correlation coefficient r2 is calculated automatically, the trader selects the “Regression” item and in the window that appears indicates the area of input parameters – exchange rates on the Y axis and session days on the X axis. Regression calculations appear on a separate sheet, where the r2 data is located. The values of the correlation coefficient are interpreted as follows:

• 0.1 and below – a close trend change, a ban on opening deals;
• 0.6 and higher – the market is trending.

Another option for determining the trend reversal is a measure of the discrepancy between the forecasted values of the closing session in the form of horizontal levels and real closing prices. The smaller the margin of error, the closer the trend reversal is.

Naturally, a significant excess of the horizontal lines (breakdown) indicates a very close change in the direction of the exchange rate of the currency pair. Therefore, the best deal is the first entry on a trend reversal when:

• A Sell Stop is triggered on a growing trend or
• A Buy Stop order is activated on a falling trend.

If a trader uses pyramid tactics, then it is better to make additional transactions short-term or significantly shorten the stop loss on these positions, trying to move the protective order to breakeven if possible.

## Conclusion Econometrics is considered a promising direction for forecasting market trends, but complex calculations sometimes do not differ in efficiency from simple calculations of linear regression on a fairly short market segment.

Comparing projections of forecasted closing prices based on LRI channels with real candle closures, it is possible to determine in advance with a high degree of reliability the moments of market reversal. The linear regression indicator and pending orders allow the trader to enter the market at the initial point of reversal and accompany the trend almost to the complete completion of the movement.