DEV Community

Ray
Ray

Posted on

I Built a Stock Scanner with Python and RSI Signals — Here Is What I Learned

As a developer interested in finance, I have been experimenting with building tools to analyze stock markets using technical indicators. In this article, I will share my experience creating a simple stock scanner using Python that uses Relative Strength Index (RSI) signals.

What is RSI?

The RSI is a momentum indicator by J. Welles Wilder (1978). It measures recent price change magnitude to determine overbought (>70) or oversold (<30) conditions.

Fetching Stock Data with yfinance

import yfinance as yf

symbols = ["AAPL", "GOOG", "MSFT", "AMZN"]

data = []
for symbol in symbols:
    ticker = yf.Ticker(symbol)
    hist = ticker.history(period="1y")
    data.append(hist)
Enter fullscreen mode Exit fullscreen mode

Calculating RSI

def rsi(data, window=14):
    delta = data["Close"].diff().dropna()
    u = delta.clip(lower=0)
    d = (-delta).clip(lower=0)
    rs = u.ewm(com=window-1, adjust=False).mean() / d.ewm(com=window-1, adjust=False).mean()
    return 100 - (100 / (1 + rs))
Enter fullscreen mode Exit fullscreen mode

Generating Buy/Sell Signals

overbought_threshold = 70
oversold_threshold = 30

for i, symbol in enumerate(symbols):
    current_rsi = rsi(data[i]).iloc[-1]
    if current_rsi > overbought_threshold:
        print(f"{symbol}: SELL signal (RSI={current_rsi:.1f})")
    elif current_rsi < oversold_threshold:
        print(f"{symbol}: BUY signal (RSI={current_rsi:.1f})")
    else:
        print(f"{symbol}: HOLD (RSI={current_rsi:.1f})")
Enter fullscreen mode Exit fullscreen mode

What I Learned

  1. RSI alone is noisy — volume and trend confirmation is essential
  2. Backtesting is mandatory — signals that look great on a chart often collapse under real conditions
  3. Paper trade first — always validate with fake money before risking real capital

If you want to take this further, I built TradeSight — a self-hosted Python app that runs AI-powered strategy tournaments overnight and paper trades via Alpaca. No cloud subscription, everything on your machine.

Happy to answer questions in the comments!

Top comments (0)