Forecasting Stock Trend Using Technical Indicators With R
Forecasting Stock Trend Using Technical Indicators With R
3, December 2016
Abstract- Technical analysis is a well proven method in monitoring the price action of free markets that
have broad participation in order to gain insight into the future price trend. This paper attempts to study
on the effectiveness of several technical indicators on share trading to assess the company financial
performance over period of time. The major technical indicators in Technical analysis includes Moving
Averages, Moving Average Convergence/Divergence, Average Directional Index, Trend Detection Index,
Aroon Indicator, Vertical Horizontal Filter, Relative Strength Index, Stochastic, Stochastic Momentum
Index, Williams %R, Commodity Channel Index, Chande’s Momentum Oscillator, Bollinger Bands,
Average True Range, Donchain Channel, Chaikin Money Flow, On balance Volume and Money Flow
Index. This study will help the investors to gain knowledge about the usage of these technical indicators so
as to increase their proportion of profitable trading and improve investment returns.
Keywords - technical indicators, trend, momentum, volatility, volume, charts, price trend
1. INTRODUCTION
Forecasting the trend of future stock prices is most widely studied topic in many fields including stock
trading, finance, statistics and computer science. The motivation behind the forecasting is naturally to predict
the direction of future prices such that stocks can be bought and sold at profitable positions. The methods used
to analyze securities and make investment decisions fall into two very broad categories: fundamental analysis
and technical analysis (Larsen, 2007). The fundamental analysis is traditional approach that attempts to
determine a security’s value by focusing on underlying factors that affect a company's actual business and its
future prospects. The technical analysis, on the other hand, is the evaluation of securities/assets by means of
studying statistics generated by market activity, such as past prices and volume. Therefore, technical analysis is
the analysis of human mass psychology and it is also called behavioral finance. Experts of technical analysis
study price charts for price patterns and use price data in different technical indicators assessment to forecast
future price movements. The technical analysis paradigm is thus that there is an inherent correlation between
price and company that can be used to determine when to enter and exit the market.
Despite all kind of exotic tools in stock market, technical analysis really studies supply and demand in
a market in an attempt to determine what direction, or trend, will continue in the future (Dahlquist, 2011).
Furthermore, technical analysis attempts to understand the emotions in the market by studying the market itself.
If we are able to understand the benefits and limitations of technical analysis, it can give a direction or skills that
will enable us to be a better trader or investor in stock market.
Also, technical analysis is all about studying stock price graphs and a few momentum oscillators
derived thereof. It must be understood that technical studies are based entirely on prices and do not include
balance sheets, P&L accounts, the assumption being that the markets are efficient and all possible price sensitive
information is built into the price graph of a security/index (Larsen, 2007). In this paper, we are discussing
major technical indicators which are using most predominately and study its performances in trend analysis.
2. REVIEW OF LITERATURE
The Dow Theory laid the foundations for the modern technical analysis (Theory, 2015). Of the many
theorems put forth by Dow, three stand out: Price Discounts Everything (www.ifcmarkets.com, 2013), Price
movements are not totally random and “What” is important than “Why”. Technical analysts believe that the
current price fully reflects all information. Because all information is already reflected in the price, it represents
the fair value, and should form the basis for analysis. Most of earlier research studies on technical analysis
focused on selective indicators and limits themselves with five/six indicators in their study.
The applicability of certain computational measures like Beta calculation, Relative Strength Index and
Simple Moving average (R, 2011) were discussed in stock analysis and also suggested various factors like
Government of India budget, company performance, political and social events, climatic conditions etc., are to
be considered before any decision is made in stock trading.
The effectiveness of technical tools like Relative Stock Index (RSI) and chart patterns (Dhutti, 2014)
were discussed elaborately in taking the investment decisions whether to buy or sell the stocks of five IT
companies viz: Tata Consultancy Services (TCS), Infosys Limited, Wipro, Hindustan Computers Technologies
Limited (HCL), Satyam Computers Limited (now Mahindra Satyam) of IT sector during the period of Jan-Dec
2012. Further the author illustrated how statistical methods like coefficient of variation and beta are used to
analyze the risk and return relationship of security with the market. Four enriched technical indicators- Relative
Strength Index, Bollinger Bands, Moving Average Convergence/Divergence and Simple Moving Average
(Vasantha S, 2012) used to take a decision on whether to buy or sell the stocks of the IT sector. Also it was
observed that Moving Average Convergence Divergence (MACD) value helps to identify the scripts that are
technically strong or not (V, 2015)and also showed that how MACD facilitates investors to recognize the
current trend and risks associated with the script at par with the market. He also confirmed that technical
analysis can be used neither the bull side nor the bear side of the stock market, but it is only the right side of
the stock market when to buy/sell the script.
In recent study on major technical indicators conducted by (C, 2014) revealed that Candlestick chart,
Exponential Moving average, RSI, MACD indictors are very helpful in making decisions to earn profit while
selling/buying stocks of five companies Wipro, SBIN, Gail, ONGC and ITC. The authors (Zhu, 2014)explained
the effectiveness of the derived technical indicator called volume weighted moving average (VWMA) against
Moving average value. Further he endorsed that need for inclusion of volume information to technical indicators
and its advantages over various matters like issuing of more trading signals, increasing the proportion of
profitable trading, reduction in the average draw down, and improving investment returns etc., A study was
conducted on selected stocks from Thai stock market data and performed clustering analysis on that data and
identified that a group of stocks that has the best trend and further the study highlighted that momentum
characteristics of these stocks indicates the outperformance of the market will be more during a short time
period (Peachavanish, 2016).
Based on the survey of research work done by various authors , we observed that limited technical
indicators alone used in their study and the role of other reliable stock market technical indicators are not
discussed so for. As a result, the following objected are framed.
3. METHODOLOGY
Technical analysis refers to a broad field and the list of technical market indicators is almost infinite.
Hence it is grouped under four categories such as Trend indicators, Momentum indicators, Volatility indicators
and Volume indicators (mwlibtoolkit, 2011). Each indicator dominates the other in predicting the trend of
different types of stocks. For example, RSI may lead WPR in predicting trend of TVS Motor Stock and WPR
may lead RSI in predicting trend of Tata Motors Stock. This study aims at analyzing the impact of major 22
technical indicators altogether on NSE Mid Cap Stock TVS Motor. Six months daily data of TVS Motor of
NSE Mid Cap index from January 2010 to June 2010 is used in this study. TVS Motor OHLCV (Open, High,
Low, Close, Volume) is retrieved from NSE websites and yahoo finance (TradingGeek, 2014). Twenty two
technical indicators are derived from OHLCV (Ulrich, 2016) are used in our case study. The gorgeous effect of
22 technical indicators which are available in TTR package is explained in an unsophisticated manner in
predicting trend of the market. As the study describes about each indicators and its uses, investors can use this as
207
International Journal of Computational Intelligence and Informatics, Vol. 6: No. 3, December 2016
a reference in making decisions whether to buy or sell stocks, thereby increase their profit in their investment.
They can also observe combination of these indicators such as Trend, Momentum, Volatility indicators to make
accurate decisions.
Fast and flexible technical analysis can be done with TTR package in R (TradingGeek, 2014).
Performance of all technical indicators against data set is depicted in 2-D plot. R is a language and environment
for statistical computing and graphics. R provides a wide variety of statistical and graphical techniques, and is
highly extensible. R Packages is also easy to learn and have all dependencies being installed automatically. The
graphical capabilities of R are outstanding, providing a fully programmable graphics language that surpasses
most other statistical and graphical packages. Because R is open source, unlike closed source software, it has
been reviewed by many internationally renowned statisticians and computational scientists. The brief details of
all technical indicators in each group are explained below.
Exponential Moving Average (EMA): Exponential moving average, unlike SMA gives higher priority
to the actual data. The current values get higher importance in the EMA calculation compared to the furthest
ones.
2
EMA = EMA(−1) + K x input − EMA −1 where K = (2)
(n+1)
Weighted Moving Average (WMA): Weighted Moving average gives higher importance to actual days
and lower importance to the furthest days usually. But the trader has to take decision which day should be more
or less significant.
Volume Adjusted Moving Average(VAMA): The Volume Weighted Moving Average is a weighted
moving average that uses the volume as the weighting factor, so that higher volume days have more weight. It is
a non-cumulative moving average, in that only data within the time period is used in the calculation.
n price × volume
1
VAMA = n volume (5)
1
208
International Journal of Computational Intelligence and Informatics, Vol. 6: No. 3, December 2016
In all moving averages, when close price is above its moving average then it indicates buy signal, when
it is below its moving average it signals to sell. The price and moving average will be frequent so the moving
average curve can be followed, if it is rising, it is a buy signal else it is a sell signal.
3.1.2. Moving Average Convergence/Divergence (MACD) Indicator:
MACD was proposed by Gerald Appel. MACD is a momentum oscillator that indicates the dynamics
and strength of the current trend and oscillates around the zero line in both directions. MACD consists of three
moving averages. Their normal settings are 9, 12 and 26 (V, 2015).Zero Line Crossover - The strategy is to buy
when the MACD crosses above the zero line, and sell when the MACD line crosses below the zero line. Signal
Line Crossover – The strategy is to buy when the MACD line crosses above the signal line else sell.
MACD line = 12 day EMA − 26 day EMA (6)
Signal line = 9 day EMA of MACD line
Where EMA = Exponential Moving Average
209
International Journal of Computational Intelligence and Informatics, Vol. 6: No. 3, December 2016
210
International Journal of Computational Intelligence and Informatics, Vol. 6: No. 3, December 2016
211
International Journal of Computational Intelligence and Informatics, Vol. 6: No. 3, December 2016
We have conducted preliminary study of 22 technical indicators which are classified into four major
groups such as Trend Indicators, Momentum indicators, Volatility indicators and Volume indicators. To get
clear view about all these 22 technicalindicators, a 2-D chart is plotted against each indicator andsignificance of
each indicator is analyzed. For our complete study, we have taken TVSMOTOR security data for 6 months
from January 2016 to June 2016 and 2-D plots are drawn with appropriate package that supports technical
212
International Journal of Computational Intelligence and Informatics, Vol. 6: No. 3, December 2016
The Moving average indicator advised that when the price is above the moving average indicator value
then themarket is in uptrend otherwise the market is in downtrend. Figure1 shows that 2-D plot of Exponential
Moving average (EMA) of TVSMOTOR security and that indicates that the market is in uptrend in March 2016
and in May 2016 it is in downtrend. The behaviors of other trend indicators such as SMA, WMA, VWMA, and
DEMA are same as EMA.
The Moving Average Convergence Divergence (MACD) indicator highlights that the market is in
uptrend when MACD line crosses above the zero line or the MACD line crosses above the signal line. On the
other hand, the market is in downtrend when MACD line crosses below the zero line or the MACD line crossed
below the signal line. Figure 2reveals that the MACD line crosses above 0 during the month ofMarch 2016 and
indicates the market is in uptrend and during the month of May MACD crosses below 0 indicating a downtrend.
And also, the MACD line crosses above the signal line by the end of February indicating uptrend and it occurs
before the Zero crossover of MACD. Similarly the downtrend is also indicated earlier by signal line crossover
before the zero crossovers.
The Average Directional Movement Index (ADX) indicator signal a strong trend if ADX value is
above 25 points along with the direction of the trend +DI and –DI on either side. That is, when +DI crosses
above –DI it indicates buy signal and when +DI crosses below –DI it indicates sell signal. In Figure3 ADX
indicator chart of TVSMOTOR security, ADX value is above 25 in March and indicates strong trend and also
+DI crosses above -DI indicates bearish market. In February, ADX value is less than 20 indicating the price is
flat. So, if the trend is strong, buy/sell direction can be decided using +DI and –DI.
213
International Journal of Computational Intelligence and Informatics, Vol. 6: No. 3, December 2016
The trend detection index (TDI) is used to detect when a trend has begun and when it has come to an
end. If the values of TDI and direction of indicator is positive it signals that there is a bullish market and if TDI
is positive and the direction indicator is negative then there will be a bearish market. In Figure 4TDI chart of
TVSMOTOR security indicates that in-betweenlast week of March and first week of May, both TDI and DI is
positive indicating uptrend, whereas in middle of May TDI is negative and DI is positive indicating a down
trend.
Vertical Horizontal Filter(VHF) indictor quantify that when the value is rising it shows prices are
trending, if it falls then it indicates trend is ending. Figure 6 shows that VHF chart of TVSMOTOR security,
during the month of March. VHF value is rising indicating an uptrend, during the end of the April, VHF value is
falling indicating downtrend.
214
International Journal of Computational Intelligence and Informatics, Vol. 6: No. 3, December 2016
In Relative Strength Index (RSI) indicator, if RSI value above 70 indicates stocks are overbought and it
is below 30 it indicates oversold condition of a security. If RSI reaches overbought/oversold condition then the
trend reversal occurs. Figure 7 reveals that the stocks are overbought twice during the month of March and once
in April 2016. During March there is gradual downtrend whereas in April there is a drastic downtrend. And by
the end of April, RSI value reaches nearer to 30 indicating oversold and there is an uptrend in the market.
The value of Stochastic Momentum Index (SMI) above 40 indicates overbought and below 40 indicates
oversold condition. If it reaches overbought/oversold levels then there will be trend reversal. Figure 9 gives
SMI chart of TVSMOTOR security and it divulges that during the month of March & April 2016, the SMI value
is above 40 indicating that the stocks are overbought and the start of downtrend can be visualized. During the
month of February SMI crosses above signal line and there bullish trend can be visualized, whereas during the
month of April SMI crosses below the signal line showing a bearish trend.
215
International Journal of Computational Intelligence and Informatics, Vol. 6: No. 3, December 2016
TVSMOTOR security lies between 0 and 20 during February, March and April months indicating overbought
condition and also it indicates the beginning of downtrend. WPR value reaches the range80 to 100 six times
between January to June indicating oversold condition and also indicates the beginning of uptrend. Some signals
may be a filtered by looking at other technical indicators to do safe trading.WPR value crosses above and below
-50 during January and February indicates uptrend and downtrend (Figure 10).
The Commodity Channel Index (CCI) of Momentum Indicator recommends that if the value crosses
above/below 100 it indicates overbought/oversold levels of stocks. After it reaches this level trend reversal
occurs. The value of CCI is above 100 and shows overbought condition and it also indicates uptrend during
early month of February and last week of March, April and June 2016. The CCI value is below -100 and
indicates oversold condition and also shows the beginning and ending of downtrend (Figure 12).
Bollinger Bandsare used to measure the volatility and indicates overbought and oversold conditions.
The upper and lower band acts as price targets, whereas the middle band acts as a support or resistance level.
Bollinger Bands of 2-D plot in Figure 13 highlights that, in the last week of February 2016, price touches the
lower band and bounce above the middle band so buy signal is generated. The price move above the middle
band at price Rs.280/- and we may expect a target of upper band at Rs.300/-. But in the middle of March it
reaches to price Rs.320/- . In April end the stock price goes below the middle band (Rs.325/-) and sell is
initiated and the target of lower band is Rs.315/ but actually it moves down to Rs.280/-. It also measures
216
International Journal of Computational Intelligence and Informatics, Vol. 6: No. 3, December 2016
volatility, stock is less volatile from end of May to June and stock is more volatile between middle of March and
middle of May.
The Average True Range (ATR) indicator value is high then it indicates high volatility and if the ATR
value is low, then it indicates the price is less volatile and the price is flat(Figure 14). The ATR value is so high
during the end of February and in the beginning of May. A bullish reversal with an increase in ATR would
show strong buying pressure and reinforce the reversal. ATR is low in middle of March and May indicates less
volatility. A bearish support break with an increase in ATR would show strong selling pressure and reinforce the
support break.
In Donchain Channel (DC) indicator, long is entered when price goes above upper channel and it is
exited from long when it penetrates lower channel. And short is entered when price goes below lower channel
and it is exit when it penetrates upper channel. Figure 15 articulate that, in the middle of March long can be
entered around level 290 and exit level is 310, but the stock moves to 330. During month of May and June, short
can be entered around price 310 and exit level is 285.
217
International Journal of Computational Intelligence and Informatics, Vol. 6: No. 3, December 2016
On Balance Volume (OBV) indicator exposes that OBV value increases in the middle of April and
foreshadow the rise in price. Falling OBV values in the beginning of May foreshadow fall in price. Volume is
less volatile in June and foreshadow that the price is flat (Figure 16).
Chaikin Money Flow (CMF) indicator is used to measure buying and selling pressure. In Figure 17,
CMF value crosses above/below 0 then there are many bullish/bearish signals. To reduce whipsaws threshold is
set at +0.05/-0.05 and numbers of whipsaws are reduced. In the months of January, March and June 2016,
buying pressure is more as it crosses the threshold +0.05. In February, March and June the value crosses the
threshold -0.05 indicating selling pressure.
5. CONCLUSION
Most of the trading types can be easily identified with just one or four chart indicators. Once we know
how to use trend indicators, momentum indicators, volatility indicators and volume indicators, we can find a
way to execute the trading plan. Moreover findings of this study will help the investors to gain knowledge about
the usage of these technical indicators so as to increase their proportion of profitable trading and improve
investment returns.The purpose of this preliminary study is to understand basis of share trading through
technical analysis and we extend our work towards forecasting of share prices by means of developing AI based
prediction models and explore how technical indicators contributing in prediction models.
218
International Journal of Computational Intelligence and Informatics, Vol. 6: No. 3, December 2016
REFERENCES
C, B. (2014). Technical Analysis In Select Stocks Of Indian Companies. International Journal of Business and
Administration Research Review, 2 (4).
Dahlquist, C. D. (2011). Technical analysis : The Complete Resource for Financial Market Technicians (2 ed.).
Dhutti, K. (2014). Stock Price Movement of Information Technology Sector through Technical Analysis.
Journal of Academia and Industrial Research (JAIR), 2 (9).
Larsen, F. (2007). Automatic stock market trading based on Technical Analysis. Norwegian University of
Science and Technology: NTNU Innovation and Creativity.
Peachavanish, R. (2016). Stock Selection and Trading Based on Cluster Analysis of Trend and Momentum
Indicators. International MultiConference of Engineers and Computer Scientists(IMECS) , 1.
R, C. (2011). Technical Analysis on Selected Stocks of Energy Sector. International Journal of Management &
Business Studies(ijmbs), 1 (1).
Ulrich, J. (2016). Technical Trading Rules(TTR package rerference). Retrieved from https://cran.r-
project.org/web/packages/TTR/TTR.pdf
V, S. (2015). Trading Through Technical Analysis: An Empirical Study From Indian Stock Market.
International Journal of Development Research, 5 (8), 5410-5416.
Vasantha S, D. V. (2012). Stock price movement through 6 technical analysis: Empirical evidence from the I.T
sector. Indian Journal of Finance, 6 (10), 4-17.
Zhu, G. L. (2014). Research on the Effectiveness of Technical Indicators with the Volume. International
Conference on Education, Management and Computing Technology (ICEMCT).
219