Stock Trading Indicator using Reinforcement Learning

Ashish Tiwari, Anand Kumar Sah, Gaurav Pandeya, Laxmi Prasad BhattJournal of Advanced College of Engineering and Management 2025 · DOI

Abstract

Traditional trading strategies often struggle to consistently achieve profitable results in highly volatile and complex financial markets. This research explores the potential of Reinforcement Learning (RL) to develop a trading indicator capable of learning and adapting to market changes. By leveraging RL, the trading indicator aims to improve decision-making and enhance trading performance through continuous learning from experiences. The outcomes of this research include a flexible and adaptive RL-based trading indicator, trading strategies that generate higher returns with better risk management, and a thorough comparison with traditional methods. This study demonstrates how advanced machine learning can be effectively applied to enhance trading in financial markets. In contrast to traditional technical analysis, which focuses on statistical trends from trading activity, RL offers an experience-driven approach that can adapt to evolving market conditions. The RL-based trading indicator utilizes Q-learning, a model-free reinforcement learning algorithm, to learn optimal action-selection policies. Through iterative updates of Q-values, the agent can derive the optimal policy by selecting the action with the highest Q-value in any given state. The research evaluates the performance of the RL-based trading indicator against traditional indicators like MACD and RSI across multiple stocks. The results consistently demonstrate the superior performance of the RL-based indicator in terms of profitability and adaptability.

Introduction

Financial markets are characterized by high volatility and non-linear dynamics, making consistent profitability a challenge for traditional trading strategies. Conventional technical analysis relies on indicators such as the Moving Average Convergence Divergence (MACD) and the Relative Strength Index (RSI). While these tools are widely used, they possess inherent limitations: they are often reactive rather than proactive, rely on rigid parameters that may not suit all market conditions, and typically focus on a narrow set of historical price data.

To address these shortcomings, this research proposes a Reinforcement Learning (RL) approach. Unlike static indicators, an RL agent learns an optimal trading strategy through trial and error within a simulated environment, allowing it to adapt to shifting market trends and optimize for long-term rewards.

Methodology

The research followed a structured machine learning pipeline, beginning with data acquisition and culminating in rigorous validation.

General research methodology flowchart

The Q-Learning Framework

The core of the proposed system is the Q-learning algorithm, a model-free RL technique. The agent's objective is to learn a policy that maximizes the cumulative reward by estimating the value of taking specific actions in given states. This is achieved through the Bellman equation, which updates the Q-values based on the immediate reward and the discounted future value of the next state.

The trading environment was modeled using the OpenAI Gym framework (StockTradingEnv). The agent's action space consists of three primary decisions: Buy, Hold, or Sell. To balance the discovery of new strategies with the exploitation of known profitable ones, an epsilon-greedy policy was implemented.

Detailed workflow of the Q-learning trading agent

As shown in the detailed workflow above, the process is divided into a training phase and a testing phase. During training, the agent iteratively updates its Q-table over multiple episodes. In the testing phase, the learned policy is applied to unseen data to evaluate its real-world applicability.

Experimental Setup

The study utilized historical daily stock data from the Nepal Stock Exchange (NEPSE), specifically focusing on three stocks: Nepal Telecom (NTC), Nabil Bank (NABIL), and Upper Tamakoshi Hydropower (UPPER). The dataset included standard features: Open, Close, High, Low, and Volume. The data was partitioned into training and testing sets to ensure the model's ability to generalize to new market conditions.

Results and Discussion

The performance of the RL-based indicator was compared against traditional MACD and RSI strategies over a 63-day testing period. The primary metric for evaluation was the total reward, representing the capital gain.

Stock RL Reward MACD Reward RSI Reward
NTC 37,149.90 781.50 -8,334.50
NABIL 25,456.80 449.20 -15,294.60
UPPER 2,465.10 -218.00 -2,863.80

The results indicate that the RL agent significantly outperformed traditional indicators across all tested stocks. While RSI often resulted in net losses, the RL agent maintained high profitability. Visual analysis of the agent's behavior revealed that it was more proactive, capturing smaller price fluctuations that traditional "lagging" indicators often missed. For instance, in the case of NABIL—which experienced a downward trend—the RL agent adapted more effectively than the RSI strategy, which issued buy signals during "oversold" periods that failed to recover.

Conclusion and Future Work

This research demonstrates that Reinforcement Learning provides a robust and adaptive alternative to traditional technical indicators. By learning from experience rather than following fixed rules, the RL agent can navigate volatile markets more effectively.

Future research will focus on:

  1. Deep Reinforcement Learning: Implementing architectures like DQN or PPO to handle more complex, high-dimensional state spaces.
  2. Enhanced Feature Engineering: Incorporating sentiment analysis from news and social media, alongside additional technical indicators like Bollinger Bands.
  3. Risk Management: Integrating explicit risk controls, such as automated stop-loss mechanisms and drawdown limits, into the reward function.

Summary updated

Abstract

Traditional trading strategies often struggle to consistently achieve profitable results in highly volatile and complex financial markets. This research explores the potential of Reinforcement Learning (RL) to develop a trading indicator capable of learning and adapting to market changes. By leveraging RL, the trading indicator aims to improve decision-making and enhance trading performance through continuous learning from experiences. The outcomes of this research include a flexible and adaptive RL-based trading indicator, trading strategies that generate higher returns with better risk management, and a thorough comparison with traditional methods. This study demonstrates how advanced machine learning can be effectively applied to enhance trading in financial markets. In contrast to traditional technical analysis, which focuses on statistical trends from trading activity, RL offers an experience-driven approach that can adapt to evolving market conditions. The RL-based trading indicator utilizes Q-learning, a model-free reinforcement learning algorithm, to learn optimal action-selection policies. Through iterative updates of Q-values, the agent can derive the optimal policy by selecting the action with the highest Q-value in any given state. The research evaluates the performance of the RL-based trading indicator against traditional indicators like MACD and RSI across multiple stocks. The results consistently demonstrate the superior performance of the RL-based indicator in terms of profitability and adaptability. This highlights the potential of RL as a promising tool for enhancing financial trading strategies.
BibTeX
@article{tiwari2025stock,
  author = {Ashish Tiwari and Anand Kumar Sah and Gaurav Pandeya and Laxmi Prasad Bhatt},
  title = {{Stock Trading Indicator using Reinforcement Learning}},
  journal = {Journal of Advanced College of Engineering and Management},
  year = {2025},
  doi = {10.3126/jacem.v10i1.76326},
}
Figure