Volume 12 Issue 04 April 2024, Page no.
– 4155-4161
Index Copernicus ICV: 57.55, Impact Factor: 8.316
DOI: 10.47191/ijmcr/v12i4.07
Gain Profitable Insights by Focusing on Moving Averages for Intelligent
Trading Solutions
Dr. D. Shalinigayathri1* , Dr. D.Shunmuga kumari2*
1
Assistant Professor, Department of Computer Science, Augurchand Manmull Jain College, Mennambakkam, Chennai, Tamilnadu,
India.
2
Assistant Professor, Department of Information Technology, V.V. Vanniaperumal College for Women, Virudhunagar, Tamilnadu,
India.
ARTICLE INFO ABSTRACT
Published Online: It is more important than ever to find intelligent trading strategies as financial markets
29 April 2024 get more complex. This paper offers a thorough investigation into the use of moving averages
in Python programming for the creation of intelligent trading algorithms. This study explores
the complex relationship between data analysis and profitable decision-making, providing a
sophisticated viewpoint on the use of moving averages in financial planning. An overview of
the Python programming language as a flexible tool for algorithmic trading and quantitative
analysis opens the investigation. The discussion then turns to the use of moving averages, a key
instrument in technical analysis, in the context of trading strategies. We highlight Python's
flexibility by showcasing how moving averages can be easily incorporated into the trading
process to improve decision support.
To sum up, this paper provides an invaluable resource for traders, scholars, and algorithmic
enthusiasts who want to learn more about the relationship between moving averages and Python
programming. The framework that is being presented not only broadens the range of tools
Corresponding Author: available for algorithmic trading, but it also emphasises how important data-driven decision-
Dr. D. Shalinigayathri making is in turning information into profits.
KEYWORDS: Bollinger Bands, Relative Strength Index, Technical Analysis, Stock Trading, Buy-Sell Signals, Volatility,
Momentum.
1. INTRODUCTION (time-weighted average price) are used to execute algorithmic
Using algorithms—computer-generated trading.
instructions—to automate the process of trading financial Computer programmes and automated instructions are used
instruments in the stock, forex, and other markets is known as in algorithmic trading to execute trades. Known by several
algorithmic trading. The algorithmic trading feature of the names such as black-box or algorithmic trading, it currently
given code is used when the script automatically generates accounts for more than half of all trading activity in US
buy and sell signals based on the given conditions without the markets.
need for human intervention. This is what algorithmic trading This is an interesting story of how algorithmic trading has
is all about. changed over time and become more popular.
Algorithmic trading uses financial markets and computer In the past few decades, there has been a significant
programming to execute trades at specific times. In addition transformation in the securities trading industry. The term
to ensuring the most effective trade execution, placing orders "Algorithmic Trading," or "Algo Trading," has taken control
instantly, and potentially lowering trading fees, algorithmic in the modern era, when exchanges carry out orders supported
trading aims to remove emotion from trading. Trend- by automated and recorded instructions. Algorithmic trading
following tactics, arbitrage opportunities, and index fund is used by larger brokerages and institutional investors to
rebalancing are examples of common trading strategies. manage huge orders and save costs. It is even used by mutual
Moreover, volume (volume-weighted average price) and time funds, pensions, and other sizable investment entities.
4155 Dr. D. Shalinigayathri, IJMCR Volume 12 Issue 04 April 2024
“Gain Profitable Insights by Focusing on Moving Averages for Intelligent Trading Solutions”
Market-making firms often generate liquidity through prices) (Singh et al., 2016). The authors (Khaidem et al.,
algorithmic transactions. In 2020, 10% of US and European 2016) suggest an alternate technique of hedging against stock
hedge funds derived over 80% of their value from algorithmic market volatility by forecasting future stock returns using a
trading. class of powerful machine learning algorithms. (Chen et al.,
Big organisations have advanced much farther, starting to 2017) provide a simple hybridised framework consisting of
trade in nanoseconds using supercomputers. High-frequency feature weighted SVM and K-nearest neighbour to precisely
trading is a relatively recent development in the field of anticipate stock market indices. We tried to predict the
algorithmic trading. Additional algorithmic traders entered following day's closing price for five businesses across
the market in 1998 following the US Securities and Exchange sectors using both an ANN and a Random Forest model (Vijh
Commission's (SEC) approval of ECNs for use in equity et al., 2020). When compared to the random forest strategy,
trading. After the SEC implemented decimalization in 2000, the LSTM model enhanced equity return projection accuracy
a lot of spread-profiting participants were forced to move to from 14.3% to 27.2%. Chen and colleagues (2015) Because
high-frequency trading in order to increase their trading the stock market is such an important aspect of the financial
volume. Over the past ten years, there has been an exponential system, studying how to predict swings in stock values is
rise in high-speed trading. The majority of the trade volume quite appealing. Deep learning is applied to forecast stock
is made up of this activity. The goals of algorithmic trading values in the future (Gao et al., 2018).
are to maximise market opportunities, enhance efficiency, and
maximise trade execution. It can cover a range of time 3. METHODOLOGY
frames, from immediate to distant. While HFT demands ultra- 3.1 Moving Average
high speed, algorithmic trading may not need the same level A moving average (MA) is a stock indicator
of speed in order to optimise trade execution according to commonly used in technical analysis. The moving average
predetermined rules. Technical indicators, quantitative helps to level the price data over a specified period by creating
models, and historical price data are just a few of the data a constantly updated average price. A simple moving average
sources it can use. We have following benefits from (SMA) is a calculation that takes the arithmetic mean of a
Algorithmic Trading: given set of prices over a specific number of days in the past.
Best Execution: The best prices are frequently used An exponential moving average (EMA) is a weighted average
to execute trades. that gives greater importance to the price of a stock in more
Low Latency: Trade orders can be placed accurately recent days, making it an indicator that is more responsive to
and instantly, with a high probability of being new information. Moving averages are used to calculate a
executed at the specified levels. Trades are executed stock's support and resistance levels as well as the direction
promptly and at the right time to prevent large price of its trend. Due to its historical price basis, this indicator is
swings. known as a trend-following or lagging indicator. The lag
lower expenses for transactions. increases with the length of the moving average's period.
Automated checks on several market circumstances Because it includes prices for the previous 200 days, a 200-
simultaneously. day moving average will lag significantly more than a 20-day
No Human Error: Lower chance of blunders or MA. Investors and traders frequently monitor the 50-day and
manual errors during trade placement. Additionally 200-day moving average values, which are regarded as
refutes the inclination of human traders to be crucial trading signals.
influenced by psychological and emotional Depending on their trading goals, investors can
elements. determine moving averages for a variety of durations and
Back testing: To determine if algorithm trading is a lengths. Longer-term investors are better served by longer-
profitable trading method, back testing can be done term moving averages, whereas shorter moving averages are
with current and previous data. usually employed in short-term trading. Even if it is
impossible to forecast a stock's future movement, research
2. RELATED WORKS and technical analysis can help forecast more accurate
The researchers examined the various machine movements. A rising moving average denotes an upward
learning approaches ANN, SVM, random forest, and naive- tendency for the security, while a descending moving average
Bayes in a study comparing two input methods with four denotes a downward trend. Similar to this, a bullish crossover
distinct prediction models (Patel et al., 2015). Support Vector that is, the crossing of a short-term moving average above a
Regression is presented as the first phase of a two-stage longer-term moving average confirms upward momentum.
fusion strategy (Patel et al., 2015). (SVR). The domain of On the other hand, a bearish crossover which happens when
voice time series data is appropriate for the paper's teachings. a short-term moving average crosses below a longer-term
A deep learning approach for stock forecasting was built and moving average confirms downward momentum.
tested using multimedia data (a chart of NASDAQ stock
4156 Dr. D. Shalinigayathri, IJMCR Volume 12 Issue 04 April 2024
“Gain Profitable Insights by Focusing on Moving Averages for Intelligent Trading Solutions”
The average change in a data series over time is 3.3. Exponential Moving Average
captured by a statistic called a moving average. Technical In an effort to make prices more responsive to fresh
analysts in the financial industry frequently utilise moving information, the exponential moving average assigns greater
averages to monitor price patterns for certain securities. A weight to recent values. The simple moving average (SMA)
moving average's upward trend could indicate an increase in for a given time must first be determined in order to compute
the price or momentum of an asset, whilst a downward trend an EMA. Next, determine the "smoothing factor," or
would be seen as a decline. multiplier, by weighting the EMA. This can be done using the
Technical analysis, a subset of investing that aims to following formula: [2/(selected time period + 1)]. The
comprehend and capitalise on the price movement patterns of multiplier for a 20-day moving average would be [2/(20+1)]=
stocks and indexes, makes extensive use of moving averages. 0.0952. To get the current value, the smoothing factor and the
Moving averages are typically used by technical analysts to prior EMA are combined. As a result, the SMA gives all
determine whether an investment is experiencing a change in values the same weighting, whereas the EMA provides recent
momentum, such as a sharp decline in price. prices a higher weighting.
EMA=Price(t) X k+EMA(y) X (1-k)
3.2. Simple Moving Average
Where
The computation of a simple moving average
T=today
(SMA) involves determining the arithmetic mean of a given
Y=yesterday
set of variables over a designated time frame. The sum of a
N=number of days in EMA
group of numbers, or stock prices, is divided by the total
K=2/(N+1)
number of prices in the group. The following formula can be
3.3.1. Dataset
used to determine a security's simple moving average:
In this work, we use a TATACOFFEE and ITC dataset.
SMA=A1+A2+A3+…+An/n
We have the dataset with the time period form 2019-2023.
where:
Finally we have 993 rows of data and divided them in to two
An= the price of an asset at period n
category. 900 rows of data for Training purpose and 100 rows
n= the number of total periods
of data for Testing purpose.
Table 1. Sample TATACOFFEE Data Set
Date Open High Low Close Adj Volume
Close
26-12-2019 91.7 92.4 91.55 91.75 87.37885 151209
27-12-2019 91.9 92.3 91.2 91.85 87.47408 194738
30-12-2019 92.3 92.45 91.05 92.05 87.66456 247880
31-12-2019 92 94.25 91.2 92.1 87.71217 746744
01-01-2020 92.5 92.7 91.3 91.5 87.14076 147147
02-01-2020 91.9 93.25 91.55 92.45 88.04549 271918
03-01-2020 92.7 96.2 92.5 93.9 89.42642 1281570
06-01-2020 92.75 93.25 90.1 90.35 86.04555 319848
07-01-2020 91.05 92.55 90.5 91.55 87.18838 229694
08-01-2020 91 91.55 88.6 89.15 84.90271 341567
09-01-2020 90.3 92.8 90 91.45 87.09315 456659
10-01-2020 91.8 93.95 91.8 93.3 88.85501 703285
13-01-2020 95 99.85 94.3 97.55 92.90253 2665181
14-01-2020 97.75 102.95 97.05 100.35 95.56913 2996657
15-01-2020 100.5 101.55 99.5 99.9 95.14057 801667
16-01-2020 99.9 104 99.85 101.95 97.0929 1609691
17-01-2020 102.9 103.85 98.5 99.35 94.61677 776970
20-01-2020 99.35 102.8 98.85 100.45 95.66436 1170980
21-01-2020 99.5 106.95 99.5 102.95 98.04525 3702445
4157 Dr. D. Shalinigayathri, IJMCR Volume 12 Issue 04 April 2024
“Gain Profitable Insights by Focusing on Moving Averages for Intelligent Trading Solutions”
Table 2. Sample ITC Data Set
Date Open High Low Close Adj Volume
Close
26-12-2019 238.9 239.4 236.35 236.8 200.0162 14460325
27-12-2019 237.5 238.45 236.45 236.9 200.1007 8712539
30-12-2019 238 240.9 237.5 238.2 201.1987 13173134
31-12-2019 238.55 238.95 237.4 237.7 200.7764 7142051
01-01-2020 238.6 238.6 237.1 238.1 201.1142 4208837
02-01-2020 238.2 240.95 238.1 239.85 202.5924 8402979
03-01-2020 241 241 238 238.5 201.4521 9284478
06-01-2020 237.5 238.3 235 235.1 198.5803 7636617
07-01-2020 236.05 237.9 234.6 235.35 198.7914 8416741
08-01-2020 234 235.8 233.25 234.2 197.8201 7043211
09-01-2020 235.6 236.6 235.05 235.8 199.1715 9452653
10-01-2020 237.6 238.75 236.8 238 201.0298 9973746
13-01-2020 238.5 240.5 238.25 239.25 202.0856 12243639
14-01-2020 240.25 243.8 238.3 243.25 205.4643 11843444
15-01-2020 242.55 243 241.1 242.4 204.7463 5476729
16-01-2020 242.5 243.9 240.1 240.75 203.3526 9369668
17-01-2020 240.75 242.1 239.4 239.95 202.6769 7392403
20-01-2020 240.05 243.25 240.05 241.9 204.324 8020816
21-01-2020 241.45 241.45 238 238.45 201.4099 9571070
We have found Adjacent close price history for TATACOFFEE
Fig.1 Adjacent Close Price history(TATACOFFEE)
Fig.2 Adjacent Close Price history(ITC)
RESULT feasible under the law. By effectively capturing the nonlinear
Financial institutions, stock brokers, and large-scale behaviour of complex systems, recent breakthroughs in
investors must sell and buy the shares in the shortest time
4158 Dr. D. Shalinigayathri, IJMCR Volume 12 Issue 04 April 2024
“Gain Profitable Insights by Focusing on Moving Averages for Intelligent Trading Solutions”
Machine Learning approaches have created valuable tools for
anticipating chaotic circumstances such as the stock market.
Fig.3 Buy / Sell signal(TATACOFFEE)
In Fig there are 8 buy signals are recorded and 7 signals are and suggests good accuracy. However, the acceptability of
recorded in various time period. We have found RMSE Error MAPE can vary by industry and application.
is 8.5076 and MAPE Error is 2.1687. A MAPE of 2.1687 In summary, whether your RMSE and MAPE values are
means, on average, predictions are off by about 2.17% from considered good depends on the specific requirements and
the actual values. This is generally considered a low MAPE expectations for your prediction task.
Fig. 4 Buy / Sell signal(ITC)
In Fig there are 8 buy signals are recorded and 6 REFERENCES
signals are recorded in various time period. We have found 1. Robert P. Schumaker; Hsinchun Chen; "Textual
RMSE Error is 6.4106 and MAPE Error is 1.0247. Analysis of Stock Market Prediction Using Breaking
In summary, whether your RMSE and MAPE values are Financial News: The AZFin Text System", ACM
considered good depends on the specific requirements and TRANS. INF. SYST., 2009.
expectations for your prediction task. 2. Chih-Fong Tsai; Yuah-Chiao Lin; David C. Yen; Yan-
Min Chen; "Predicting Stock Returns By Classifier
Ensembles", APPL. SOFT COMPUT., 2011.
4159 Dr. D. Shalinigayathri, IJMCR Volume 12 Issue 04 April 2024
“Gain Profitable Insights by Focusing on Moving Averages for Intelligent Trading Solutions”
3. A. Gupta; B. Dhingra; "Stock Market Prediction Using Prediction Model Using LSTM", JOURNAL OF
Hidden Markov Models", 2012 STUDENTS DIGITAL CONVERGENCE, 2020.
CONFERENCE ON ENGINEERING AND 16. Chandrasekar Ravi; "Fuzzy Crow Search Algorithm-
SYSTEMS, 2012. Based Deep LSTM for Bitcoin Prediction", INT. J.
4. Michael Hagenau; Michael Liebmann; Dirk Neumann; DISTRIBUTED SYST. TECHNOL., 2020.
"Automated News Reading: Stock Price Prediction 17. Md. Arif Istiake Sunny; Mirza Mohd Shahriar
Based on Financial News Using Context-capturing Maswood; Abdullah G. Alharbi; "Deep Learning-
Features", DECIS. SUPPORT SYST., 2013. Based Stock Price Prediction Using LSTM and Bi-
5. Jigar Patel; Sahil Shah; Priyank Thakkar; K. Kotecha; Directional LSTM Model", 2020 2ND NOVEL
"Predicting Stock and Stock Price Index Movement INTELLIGENT AND LEADING EMERGING
Using Trend Deterministic Data Preparation and SCIENCES CONFERENCE (NILES), 2020.
Machine Learning Techniques", EXPERT SYST. 18. Shile Chen; Changjun Zhou; "Stock Prediction Based
APPL., 2015. on Genetic Algorithm Feature Selection and Long
6. Jigar Patel; Sahil Shah; Priyank Thakkar; K. Kotecha; Short-Term Memory Neural Network", IEEE
"Predicting Stock Market Index Using Fusion of ACCESS, 2021.
Machine Learning Techniques", EXPERT SYST. 19. Jaydip Sen; Sidra Mehtab; Gourab Nath; "Stock Price
APPL., 2015. Prediction Using Deep Learning Models", 2021.
7. Ritika Singh; Shashi Srivastava; "Stock Prediction 20. Ya Gao; Rong Wang; Enmin Zhou; "Stock Prediction
Using Deep Learning", MULTIMEDIA TOOLS AND Based on Optimized LSTM and GRU Models", SCI.
APPLICATIONS, 2016. PROGRAM., 2021.
8. Luckyson Khaidem; Snehanshu Saha; Sudeepa Roy 21. B UmaDevi; D Sundar; P Alli; "An Effective Time
Dey; "Predicting The Direction Of Stock Market Prices Series Analysis for Stock Trend Prediction Using
Using Random Forest", ARXIV, 2016. ARIMA Model for Nifty Midcap-50",
9. Yingjun Chen; Yongtao Hao; "A Feature Weighted INTERNATIONAL JOURNAL OF DATA MINING
Support Vector Machine and K-nearest Neighbor & KNOWLEDGE MANAGEMENT PROCESS,
Algorithm for Stock Market Indices Prediction", 2013.
EXPERT SYST. APPL., 2017. 22. C. Narendra Babu; B. Eswara Reddy; "A Moving-
10. Mehar Vijh; Deeksha Chandola; Vinay Anand average Filter Based Hybrid ARIMA-ANN Model for
Tikkiwal; Arun Kumar; "Stock Closing Price Forecasting Time Series Data", APPL. SOFT
Prediction Using Machine Learning Techniques", COMPUT., 2014.
PROCEDIA COMPUTER SCIENCE, 2020. 23. C. Narendra Babu; B. Eswara Reddy; "Selected Indian
11. Kai Chen; Yi Zhou; Fangyan Dai; "A LSTM-based Stock Predictions Using A Hybrid ARIMA-GARCH
Method for Stock Returns Prediction: A Case Study of Model", 2014 INTERNATIONAL CONFERENCE
China Stock Market", 2015 IEEE INTERNATIONAL ON ADVANCES IN ELECTRONICS COMPUTERS
CONFERENCE ON BIG DATA (BIG DATA), 2015. AND COMMUNICATIONS, 2014.
12. Shao En Gao; Bo Sheng Lin; Chuin-Mu Wang; "Share 24. Mehak Usmani; Syed Hasan Adil; Kamran Raza; Syed
Price Trend Prediction Using CRNN with LSTM Saad Azhar Ali; "Stock Market Prediction Using
Structure", 2018 INTERNATIONAL SYMPOSIUM Machine Learning Techniques", 2016 3RD
ON COMPUTER, CONSUMER AND CONTROL INTERNATIONAL CONFERENCE ON COMPUTER
(IS3C), 2018. AND INFORMATION SCIENCES (ICCOINS), 2016.
13. Sneh Jain; Roopam Gupta; Asmita A. Moghe; "Stock 25. Sreelekshmy Selvin; R. Vinayakumar; E. A.
Price Prediction on Daily Stock Data Using Deep Gopalakrishnan; Vijay Krishna Menon; K. P. Soman;
Neural Networks", 2018 INTERNATIONAL "Stock Price Prediction Using LSTM, RNN and CNN-
CONFERENCE ON ADVANCED COMPUTATION sliding Window Model", 2017 INTERNATIONAL
AND TELECOMMUNICATION (ICACAT), 2018. CONFERENCE ON ADVANCES IN COMPUTING,
14. Masud Rana; Md. Mohsin Uddin; Md. Mohaimnul COMMUNICATIONS AND INFORMATICS
Hoque; "Effects of Activation Functions and (ICACCI), 2017.
Optimizers on Stock Price Prediction Using LSTM 26. M Hiransha; E. A. Gopalakrishnan; Vijay Krishna
Recurrent Networks", PROCEEDINGS OF THE 2019 Menon; K. P. Soman "NSE Stock Market Prediction
3RD INTERNATIONAL CONFERENCE ON Using Deep-Learning Models", PROCEDIA
COMPUTER SCIENCE AND ARTIFICIAL COMPUTER SCIENCE, 2018.
INTELLIGENCE, 2019. 27. S. Al Wadi; Mohammad Almasarweh; Ahmed Atallah
15. Jung Jong-Jin; Jiyeon Kim; "A Performance Analysis Alsaraireh "Predicting Closed Price Time Series Data
By Adjusting Learning Methods in Stock Price
4160 Dr. D. Shalinigayathri, IJMCR Volume 12 Issue 04 April 2024
“Gain Profitable Insights by Focusing on Moving Averages for Intelligent Trading Solutions”
Using ARIMA Model", MODERN APPLIED
SCIENCE, 2018.
28. Hyeong Kyu Choi; "Stock Price Correlation
Coefficient Prediction With ARIMA-LSTM Hybrid
Model", ARXIV, 2018.
29. Ayaz Hussain Bukhari; Muhammad Asif Zahoor Raja;
Muhammad Sulaiman; Saeed Islam; Muhammad
Shoaib; Poom Kumam; "Fractional Neuro-Sequential
ARFIMA-LSTM for Financial Market Forecasting",
IEEE ACCESS, 2020.
4161 Dr. D. Shalinigayathri, IJMCR Volume 12 Issue 04 April 2024