Modelling the alternative support and resistance levels with the
application of the linear regression
Wojciech Jakub Podobas
Kozminski University Investment Club “Kapitalni”
info@tradingalgorithms.pl
1. Abstract
The aim of the article is to model a new formula that can calculate price corridor using the linear
regression and standard deviation instead of the moving average. The research will check the
possible application of the linear regression into the place of the standard moving average. The
application of the linear regression instead of moving average and Bollinger Bands could give
a better and closer estimated data about price trend, due to the mathematical nature of the linear
regression that uses squares from variables instead of the normal arithmetical mean. The
application of the linear regression could create a good analytical background for investors to
omit jigsaws, bear and bull traps.
Research question: How does the linear regression could improve predicting the price
movement in the foreign exchange market?
2. Introduction and the background information
To understand properly the content of the work few concepts need to be implemented.
Key definitions
Financial instrument- Every asset that could be traded at the stock exchange1
EUR/USD- currency pair comparing price of Euro [EUR] to American Dollar [USD] 2
Technical analysis- financial mathematics branch defining the price movement at the stock
exchange
Price trend- the main direction where the price of a financial instrument is going3
Moving average- the trend following technical analysis tool, the continuously changing mean
of the price of the financial instrument in the fixed number of time, for example MA20 relates
to the average price of the financial instrument in last 20 days4
1
Reuters-Report. (2001). Foreign currency market. New York: Reuters print. p.227
Ibid., p.229
3 Archelis S. (1998). Technical analysis from A to Z. New York: Irwin. p. 72
4 Ibid., p. 15
2
© Kozminski University Investment Club “Kapitalni”
1
Resistance level- the price considered as point where most of the investors starts to selling their
positions5
Support level- the price considered as point where most of the investors start to buying new
positions6
Price corridor- the price range between the resistance and support levels7
Jigsaw – an entry to the market that results in loses due to false analysis
What is the Foreign Exchange Market [FOREX]
Foreign Exchange is a non-centralized international market where investors and institutions are
exchanging currencies 8 . It was created to allow to exchange one currency to another
immediately. Nowadays forex is also a place where people are speculating – buying one
currency with hope it will be more vulnerable in future. Forex is inaccurately associated with
gambling, because financial markets are only burdened with risk that could be calculated. Base
on that, there are many ways to predict future price movements and one of this ways use
mathematics.
Base theory – the technical analysis
Mathematics is being used in predicting price movement of a currency in the form of technical
analysis of the stock exchange. The technical analysis assumes that future can be predicted
using information and events from the past. The technical analysis examines financial
instrument’s charts and behaviour of this charts in past. Technical analysis contains dozens of
tools 9 as moving averages from fixed number of period, oscillators or indexes. The linear
regression could be applied as one of the tools of technical analysis.
To understand how does the linear regression could be applied in the predicting the chart
movement it is necessary to realise basics and assumptions of the technical analysis.
Principles of the technical analysis
The history of price movement could be analysed by the stock bars called candlesticks10. There
are two types of candlesticks – increasing and decreasing. Each candlestick denotes a price
movement in a given period of time – candlesticks could be construct from seconds, hours to
days or even weeks. The timeframe used during the exploration will use candlesticks created
for one day. Figure 1. demonstrates notation of these bars.
5
Ibid., p. 17
Ibid., p. 18
7 Ibid., p. 19
8 Reuters-Report. (2001). Foreign currency market. New York: Reuters print. p. 12
9 Chan J. (2011). Technical analysis How to trade like a professional. London: Pearson Education Lt. p. 5
10 Walker W. (2017). Technical analysis for Forex explained. London: Amazon Print. p. 10
6
© Kozminski University Investment Club “Kapitalni”
2
Figure 1 – Candlesticks as a notation of price history (source: own elaboration)
There are three possible direction, where price of the financial instrument can move; upwards,
downwards and sideways. When price of the financial instrument is moving continuously to
the same direction the situation is called a trend. There are also three types of trends; upward
trend, downward trend and sideways trend 11 . The very important dependence of price
movement is that trend is never going only up or only down – there are always highs and lows.
The types of trends are presented at the Figure 2.
Figure 2 – The three types of price trend (source: own elaboration)
11
During the uptrend (A) every next highs and lows is higher than previous one.
During the downtrend (C) every next highs and lows in lower than previous one.
Milewski M. (2011). Forex. Warszawa: SamoSedno. p. 45
© Kozminski University Investment Club “Kapitalni”
3
During the sideways trend (B) there is no rule about highs and lows and price remain in
the similar level
The reason of this chart behaviour is psychological effect 12 that most of investors are holding
their positions only for short period of time and after a satisfactory profit or loss they sell them.
The mechanics of the Resistance and Support levels
It is easy to see that during a trend price is moving in fixed passage. The price corridor is the
range of the financial instrument’s price where investors are feeling confident13 – they think
this is real, appropriate price of the financial instrument and they are afraid when price in
breaking through. When price is going too low most of investors think that the price of a
financial instrument is underestimated and they are lifting price again higher by buying it, when
price of the financial instrument is going too high investors think that the price is overestimated
and they are selling their positions afraid of reverse in trend. Lower line of the price corridor is
called the support level, when higher line of price corridor is called the resistance level.
Figure 3. - The resistance and support level in the sideways trend (source: own elaboration)
Assuming that price is going in fixed corridor and it is bouncing from the support and the
resistance level it is possible to predict price movement and use this information in an investing
strategy. For example, an investor could try to buy the currency near to the support level and
selling it near to the resistance level.
The standard way of calculating resistance and support level is calculation of moving average
and stretching it up and down by standard deviation that is named as Bollinger Bands.
Moving Average 15 in daily perspective is a mean price of last 15 days middle prices – the
middle point between high and low of each day. Moving average is changing every day because
every next day is added and the oldest – 16th day is not still counted.
12
13
Chan J. (2011). Technical analysis How to trade like a professional. London: Pearson Education Lt. p. 52
Archelis S. (1998). Technical analysis from A to Z. New York: Irwin.p. 18
© Kozminski University Investment Club “Kapitalni”
4
Possible change in way that support and resistance level is calculated
As the aim of the article is to check whether the linear regression could model the price corridor
in the better way than the moving average, the linear regression theory needs to be introduced.
The work will introduce the method of calculation of the price corridor with linear regression.
The results obtained by the new formula will be compared and contrasted with the standard
method with Moving Average (Bollinger Bands).
Linear regression as a tool in the technical analysis
Linear regression attempts to model the relationship between two variables by fitting a linear
equation to observed data. One variable is considered to be an explanatory variable, and the
other is considered to be a dependent variable. For example, a modeler might want to relate the
weights of individuals to their heights using a linear regression model.14
A linear regression line has an equation of the form Y = ax + b, where x is the explanatory
variable and Y is the dependent variable15
In the modelling formulas with linear regression Y contributes to projected price of the pair
EUR/USD and x relates to the date.
In the foreign exchange the explanatory variable would be the period of time, when the
dependent variable will be the middle price during one period. After calculating the linear
regression of chosen time (for example one week, one month or even 24 hours) the linear
regression formula would give us the exact direction where price was moving and predict where
it is going to.
3. Classic methods of calculations for the price corridor by Bollinger Bands
The Standard method of calculation of support and resistance level uses moving average.
Price corridor for forex pair EUR/USD in May 2017
Calculation of moving average for currency graph shown at the Figure 4.
To calculate moving average the middle prices (mean of maximum and minimum day price) of
further periods need to be added – every next day will be the next variable in moving average
omitting the oldest day. The proper number of periods for moving average to calculate for fixed
time is half of periods that are in time that we are interested in 16. Therefore, for one month
period, where one period is one day the proper moving average will be for 15 days – MA15.The
Figure 5. shows average price for every day in MAY 2017 for EUR/USD pair.
14
http://www.stat.yale.edu/Courses/1997-98/101/linreg.htm (visited 10.08.2017)
15
Ibid. (visited 10.08.2017)
16
Archelis S. (1998). Technical analysis from A to Z. New York: Irwin. p. 72
© Kozminski University Investment Club “Kapitalni”
5
Figure 4. - Graph of price of EUR/USD in May 2017 (source: own elaborated screenshot via IQoptions)
Date
01.05.2017
02.05.2017
03.05.2017
04.05.2017
05.05.2018
06.05.2018
07.05.2018
08.05.2018
09.05.2019
10.05.2019
11.05.2019
12.05.2019
13.05.2020
14.05.2020
15.05.2020
16.05.2020
17.05.2021
18.05.2021
19.05.2021
20.05.2021
21.05.2022
22.05.2022
23.05.2022
24.05.2022
25.05.2023
26.05.2023
27.05.2023
28.05.2024
29.05.2024
30.05.2024
Average Price of EUR/USD
1.0910
1.0905
1.0908
1.0905
1.0910
1.0905
1.0933
1.0980
1.0960
1.0892
1.0873
1.08668
1.0896
1.0885
1.095
1.1030
1.1119
1.113
1.116
1.1213
1.1209
1.1214
1.1211
1.1209
1.1211
1.1193
1.1170
1.1171
1.1181
1.1151
Every point of moving average at the graph is calculating by the
formula1:
MA (for n periods of time) =
Where:
∑𝑛
𝑘=1 y
𝑛
𝑛
∑ y = 𝑦1 + 𝑦2 … + 𝑦𝑛
𝑘=1
MA – moving average for the n periods
y – middle price in the one period
k – first period
The moving average is being calculated automatically by the investing
platform and added to the graph (Figure 6.).
–
Figure 5. – The set of average price of EUR/USD in each day of May 2017 (source: own
elaboration via IQoptions)
© Kozminski University Investment Club “Kapitalni”
6
Figure 6. - Moving Average 15 of the EUR/USD in May 2017 (source: own elaborated screenshot via IQoptions)
Next, to calculate the support and resistance level the MA15 will be moved up and down by the
value of Standard Deviation [SD] for each day.
Calculating the standard deviation17:
𝑛
|y−y|2
∑
̅
SD=√ 𝑘=1
n
Where:
SD − standard deviation of the price set
y −value of average price in one period
y̅ − 𝑚𝑒𝑎𝑛 𝑝𝑟𝑖𝑐𝑒
n − number of periods
k −first period
Due to moving average is not constant the standard deviation needs to be calculated for every
day – then the moving average will be moved upwards and downwards by the value of SD each
day and a resistance and support level will be created continuously. Therefore support and
resistance level patter will be changing every day.
17
Chan J. (2011). Technical analysis How to trade like a professional. London: Pearson Education Lt. p. 89
© Kozminski University Investment Club “Kapitalni”
7
Modelling the support and resistance levels patterns:
Support level pattern (for one period) =
Where:
y −value of average price in one period
y̅ − 𝑚𝑒𝑎𝑛 𝑝𝑟𝑖𝑐𝑒
n − number of periods
k −first period
∑𝑛
𝑘=1 y
𝑛
𝑛
𝑛
∑
− √ 𝑘=1
|y−y
̅|2
n
𝑛
|y−y|2
∑
y
√∑𝑘=1 ̅
Resistance level pattern (for one period)= 𝑘=1
+
𝑛
n
Where:
y −value of average price in one period
y̅ − 𝑚𝑒𝑎𝑛 𝑝𝑟𝑖𝑐𝑒
n − number of periods
k −first period
The support and the resistance levels created using MA15 are shown at the Figure 7. The lines
are calculated using computer program (IQoptions), that calculates it more accurately – by
calculating it for every 15 minutes interval, therefore the lines are incessant, while my formulas
assumes that there is a constant value for each day.
Figure 7. - Price corridor of EUR/USD created using EUR/USD in May 2017 (source: own elaborated
screenshot via IQoptions)
It is easy to see that the resistance and the support level show clearly possible price corridor.
The discrepancies between my formula and the computer generated lines are not important, as
the mean value of support and resistance level for each level stay the same.
© Kozminski University Investment Club “Kapitalni”
8
4. Application of linear regression
To calculate the alternative price corridor the equation for resistance and support level needs to
be established.
Modelling the pattern
Using the linear regression it is pointless to use standard deviation for each day, so on one mean
standard deviation can be calculated. After that the linear regression will be moved up and down
by value of the average standard deviation for whole month.
Linear regression pattern:
Linear regression pattern=ax +b
For a=
And
𝑥
̅)
∑𝑘=1 (x−x̅)(𝑦−y
𝑥
∑
𝑘=1
(x−x̅)2
For b=y̅ − 𝑎x̅
Where:
x − number of day
y −average price for day x
x̅ − the mean day of set
y̅ − average price of the data set
k − first period
By moving linear regression line by standard deviation up and down the pattern for the support
and resistance level can be written as:
Resistance level pattern:
∑
𝑛
|y−y
̅|2
ax +b + √ 𝑘=1
n
Support level pattern:
∑
𝑛
|y−y
̅|2
ax+b - √ 𝑘=1
n
Where:
ax +𝑏 − the value of linear regression
y −average price for day x
y̅ − average price of the data set
n – number of periods
k − first period
Calculating the linear regression function for the EUR/USD price in May 2017.
To calculate the price corridor for EUR/USD pair in May 2017 we simply need to substitute
values to previously obtained formulas, but to do this it is necessary to calculate the linear
regression and standard deviation for whole month that values are shown in the Figure 5.
Calculating mean price from the Figure 5:
© Kozminski University Investment Club “Kapitalni”
9
∑𝑛
𝑦
𝑦̅= 𝑘=1
n
Where:
y −value of average price in one period
y̅ − 𝑚𝑒𝑎𝑛 𝑝𝑟𝑖𝑐𝑒
n − number of periods
k −first period
From GDC:
𝑦̅=1.1028
Calculating the Standard deviation:
To calculate the alternative price corridor the values of EUR/USD from May 2017 will be
substituted to the previous obtained equations.
∑
30
|y−1.1028|2
SD = √ 𝑘=1
30
Where:
y−value of the average price in one period
▲ substituting into values from Figure 5.
From GDC:
SD= 0.014
By moving linear regression line by standard deviation the support and resistance level will be
obtained:
Resistance level pattern:
𝑥
∑𝑘=1 (x −x̅)(𝑦−y̅)
∑
𝑥
(x − x̅)2
𝑘=1
𝑥 + y̅ −
Support level pattern:
𝑥
∑𝑘=1 (x −x̅)(𝑦−y̅)
∑
𝑥
(x − x̅)2
𝑘=1
𝑥 + y̅ −
𝑥
∑𝑘=1 (x −x̅)(𝑦−y̅)
∑
𝑥
𝑥
(x − x̅)2
𝑘=1
∑𝑘=1 (x −x̅)(𝑦−y̅)
∑
𝑥
(x − x̅)2
𝑘=1
x+√
∑𝑛𝑘=1|y − y̅|2
n
x−√
∑𝑛𝑘=1|y − y̅|2
n
Where:
x −number of day
y −value of average price for day x
y̅ − mean price of the data set
n − number of periods
x̅ − the mean day in the data set
k − first period
© Kozminski University Investment Club “Kapitalni”
10
▲ substituting into values from Figure 5.
30
30
∑𝑘=1 (x −15)(𝑦−1.1028)
∑𝑘=1 (x −15)(𝑦−1.1028)
𝑥 + 1.1028 −
x
30
30
2
2
∑ (x − 15)
∑ (x − 15)
𝑘=1
+
∑30 |y
√ 𝑘=1
− 1.1028|2
30
𝑘=1
=0.001356x + 1.0847 + 0.014= 0.001356x + 1.0987 (the value for the resistance level for
each day)
Hence Support level:
0.001356x + 1.0847 - SD= 0.001356x + 1.0707
The functions for both resistance and support level were calculated and now are added to the
graph with the linear regression to estimate the price corridor. Owing to the calculation via
IQoptions, the function is calculated more accurately, than for each day, therefore the linear
regression will have incessant slope.
The Figure 8. shows obtained results of the price corridor.
Figure 8. - Price corridor of EUR/USD created using linear regression in May 2017 (source: own elaborated
screenshot via IQoptions)
© Kozminski University Investment Club “Kapitalni”
11
5. Analysis of both methods of calculation
There are two main factors that decide about the analytical values created by the price
corridor18:
-
The number of periods that price is inside the range of corridor
The area of the corridor that shows how accurate it is
To check which of the two methods is better to predict the price movement and avoid jigsaws
both of the mentioned factors will be considered.
Comparison and Contrast of two methods of calculating the support and resistance level
Figure 9. - Comparison of obtained price corridors of EUR/USD in May 2017 (source: own elaborated
screenshot via IQoptions)
Analysis and evaluation
The graph above shows two price corridors obtained using other technics – moving average 15
and linear regression.
Analysing the support and resistance level created using MA15 it is easy to see that they are
broken by the price movement during 6th, 15th, 16th and 17th of May.
In contrast support and resistance level obtained using linear regression is never broken and the
price seems to bouncing from one level to the other.
The support and resistance level distance from middle established by MA15 is changing daily
what suggest smaller or bigger price movement in other periods. In contrast the support and
18
Archelis S. (1998). Technical analysis from A to Z. New York: Irwin. p. 18
© Kozminski University Investment Club “Kapitalni”
12
resistance level established by linear regression is constant that suggests constant growing value
of these levels.
When any moving average or linear regression direction in upward this is sign of uptrend. The
Moving Average 15 is directed upwards from 1st to 6th and 14th to 30th of May and directed
sideways from 7th to 13th of May. The change in direction after 6th of May suggests to investors
that situation is not sure and this is better to wait for situation become clearer. The advantage
of that is that it is possible to omit losses resulting of fall in EUR/USD price from 6th to 11th
May.
The linear regression of EUR/USD price in May 2017 is directed upwards that predicts
increases in price in future. The linear regression ignore the lows and hills and shows clearly
only the general trend. Assume that an investor bought EUR/USD in 5th of May. Unfortunately,
hi register loss in next five days. If he will be patient to let the trend works, he would work out
losses and register gains in longer period of time.
The reason of these result is nature of linear regression. Linear regression can establish a trend
more preciously because itis using squares of distances from average prices rather than simply
distance as moving average does.
Looking at the graph it is good to assume that support and resistance level created using linear
regression is a margin, last border for price movement. The bouncing of price from the support
level is giving perfect opportunity to open a position.
Calculation of the accuracy of both price corridors
The best way to see the accuracy of the price corridor is to calculate the area of the track. The
smaller the area the more accurate the corridor is, because the price range is tidier – hence it
predicts the price movement more accurate.
Figure 10. – Areas ticked by both price corridors (source: own elaborated screenshot via IQoptions)
© Kozminski University Investment Club “Kapitalni”
13
For the method with linear regression the area can be calculated using simple formula for the
area of trapeze. As the price corridor adopts the shape
𝑛
|y−y
̅|
∑
𝑛+2√ 𝑘=0
n
2
Area=
ℎ
2
Where:
y −value of average price for day x
y̅ − mean price of the data set
n − number of periods
x̅ − the mean day in the data set
k − first period
h – the value of two standard deviations between the support and resistance level
▲ substituting into values from Figure 5.
From GDC:
Area=33.28
The calculation of area for the method with moving average is more complicated. The easiest
way to calculate approximated area is the application definite integration. The area between the
support and resistance level could be measured, by calculating the definite integral for
resistance level and subtract the integral of support level. The area calculated under the bot
levels will be approximated, because the integral will be calculated for the mean value of the
both level for each day, not for the incessant line as it is shown at the Figure 10. The sum of
the integrals from each day will give the area between the line.
The area under the resistance level can be calculated by the equation:
𝐴𝑟𝑒𝑎 𝑢𝑛𝑑𝑒𝑟 𝑡ℎ𝑒 𝑟𝑒𝑠𝑖𝑠𝑡𝑎𝑛𝑐𝑒 𝑙𝑒𝑣𝑒𝑙 = ∫
𝑛
𝑘
𝑛 ∑𝑛 |y
∑𝑛𝑘=1 y
− y̅|2
𝑑𝑥
𝑑𝑥 + ∫ √ 𝑘=1
𝑛
n
𝑘
Where:
y −value of average price for day x
y̅ − mean price of the data set
n − number of periods (last day in the data set)
x̅ − the mean day in the data set
k − first period (first day is the data set)
© Kozminski University Investment Club “Kapitalni”
14
Than the area under the support level needs to be subtracted, and the whole procedure must take
place for every one day in the month, therefore the area of price corridor could be written as:
𝐴𝑟𝑒𝑎 𝑜𝑓 𝑡ℎ𝑒 𝑝𝑟𝑖𝑐𝑒 𝑐𝑜𝑟𝑟𝑖𝑑𝑜𝑟:
𝑛
𝑛 ∑𝑛 y
𝑑𝑥
∑
∫𝑘 𝑘=1
𝑛
𝑘=0
𝑛
∑
𝑘=0
+∑
𝑛
∫𝑘 √
𝑛
̅|2
∑𝑘=1|y−y
n
𝑛
𝑘=0
𝑑𝑥 )
𝑛
|y−y
̅|2
𝑛 ∑
∫𝑘 √ 𝑘=1n
𝑑𝑥 − ( ∑
𝑛
𝑘=0
𝑛 ∑𝑛
𝑘=1 y
∫𝑘
𝑛
𝑑𝑥 −
Where:
y −value of average price for day x
y̅ − mean price of the data set
n − number of periods (last day in the data set)
x̅ − the mean day in the data set
k − first period (first day in the data set)
▲ substituting into values from Figure 5.
Calculating atomically using Wolfram Alpha Calculator (visited 01.12.2017
https://www.wolframalpha.com):
Area = ~39.56
Comparing the two values – 33.28 and 39.56 we can say that the price corridor that uses the
linear regression is more accurate because it is tracking smaller area and, therefore is providing
more precise price range for the trader.
6. Conclusion and Further Evaluation
It is impossible to state which one method is absolutely better. Both methods consist advantages
and disadvantages. The good point of information is that linear regression can be better for an
investor that would like to buy EUR/USD for longer period of time, when MA15 will be better
for short-term investors. It is also proven that the method with linear regression is more accurate
and consists smaller error overall. It is very important for the trader to avoid jigsaws.
The application of modelled formulas for resistance and support level using linear regression is
giving a new future-proof technical analysis tool that could be combined with any investing
strategy. The observation that price corridor calculated using linear regression shows other
features of price graph than standard price corridor is very important for the technical analysis
because it could eliminate some mispredictions based only on moving average application.
In conclusion, obtained patterns for trend line and support and resistance level with an
application of linear regression can affect many trading strategies – including mine. Many
investors and traders could be better off by studying the results of alternative price corridor.
© Kozminski University Investment Club “Kapitalni”
15
Extension and an improvement of the paper
The mathematical exploration shows alternative method of calculation of price corridor for any
financial instrument. The method is flexible and established support and resistance levels
patterns could be used for more time frames.
The major weakness of the experiment is that the alternative price corridor was established only
for one month for one currency, that create many doubts about the method, as the positive
outcome could be caused only by fortune. What is more, the formulas for calculation the support
and resistance level using the moving average were not totally accurate, as the resistance and
support level are normally calculated for every second, not only for one day as during the
exploration. Therefore the integrals obtained using the self-created mathematical formulas were
approximate, and the area of the price corridor created by moving averages may differ a bit.
The possible improvement for the experiment is research for more data sets as more timeframes
of the EUR/USD pair, more assets as stocks or commodities. While the prediction of the linear
regression application was proven and the price corridor established via it works, the research
sample is too small to state if it will work for any time frame and any currency pair as for
example for people trading hourly at the pair GBP/JPY. The best improvement for the research
would be setting price corridors for bigger number of sets in many timeframes, not only for
monthly frame for the pair EUR/USD. What is more, to calculate the actual area of the price
corridor established using moving averages requires more computing power and more
sophisticated mathematical formulas that ought to be implemented to be clearly certain about
the new method.
7. Bibliography
Archelis S. (1998). Technical analysis from A to Z. New York: Irwin.
Chan J. (2011). Technical analysis How to trade like a professional. London: Pearson
Education Lt.
Walker W. (2017). Technical analysis for Forex explained. London: Amazon Print.
Milewski M. (2011). Forex. Warszawa: SamoSedno.
Reuters-Report. (2001). Foreign currency market. New York: Reuters print.
Internet resources:
http://www.stat.yale.edu/Courses/1997-98/101/linreg.htm (visited 10.08.2017)
https://www.wolframalpha.com/ (visited 01.12.2017)
© Kozminski University Investment Club “Kapitalni”
16