RSI-2-Stock-Trading-Strategy

200-SMA and 2-RSI Trading Strategy

This Python script implements a backtesting simulation for a simple trading strategy using two common technical indicators: the 200-day Simple Moving Average (SMA) and a 2-period Relative Strength Index (RSI). The strategy is designed to identify and capitalize on potential buy and sell signals based on the confluence of these indicators.

How the Strategy Works

The core of this strategy lies in its specific entry and exit conditions:

Key Features

How to Use

Install Dependencies: Make sure you have the necessary libraries installed by running the command:

    pip install yfinance pandas matplotlib numpy

Run the Script: Execute the Python script from your terminal:

    python your_script_name.py

Analyze the Results: The script will download the data, perform the backtest, print the final results to the console, and save a plot named [ticker_symbol]_trading_strategy_plot.png in the same directory.

Code: here

Important Note on the RSI Period

The script uses a very short 2-period RSI, which is highly sensitive and volatile. While this is used to generate a specific signal, a more conventional RSI period for trading strategies is 14 days, as it provides a smoother, less erratic signal. The use of a 2-period RSI in this script is a deliberate choice for this specific strategy’s logic.


Output Examples

TLKM.JK

BBCA.JK

BBRI.JK

BMRI.JK



Back to Index