CoreWeave gained 209%. We called it early.

Stocks & Income’s free daily investing newsletter sends you the breakout stocks before they go mainstream.

Here are some recent highlights:

CoreWeave (before it soared 209%)
Palantir (+441% this year)
On Holding (+25%)
Nova Ltd. (+13% so far)

And much, much more.

Read what we’re tracking next before it takes off.

With Stocks & Income, you’ll get AI stock picks, streamlined news coverage, key charts, and 1-sentence sector updates—all built to help you invest smarter and beat the market in 5 minutes per day.

It’s 100% free and delivered daily to your inbox.

Join 100,000+ smart investors receiving the breakout trades early.

Stocks & Income is for informational purposes only and is not intended to be used as investment advice. Do your own research.

🚀 Your Investing Journey Just Got Better: Premium Subscriptions Are Here! 🚀

It’s been 4 months since we launched our premium subscription plans at GuruFinance Insights, and the results have been phenomenal! Now, we’re making it even better for you to take your investing game to the next level. Whether you’re just starting out or you’re a seasoned trader, our updated plans are designed to give you the tools, insights, and support you need to succeed.

Here’s what you’ll get as a premium member:

  • Exclusive Trading Strategies: Unlock proven methods to maximize your returns.

  • In-Depth Research Analysis: Stay ahead with insights from the latest market trends.

  • Ad-Free Experience: Focus on what matters most—your investments.

  • Monthly AMA Sessions: Get your questions answered by top industry experts.

  • Coding Tutorials: Learn how to automate your trading strategies like a pro.

  • Masterclasses & One-on-One Consultations: Elevate your skills with personalized guidance.

Our three tailored plans—Starter Investor, Pro Trader, and Elite Investor—are designed to fit your unique needs and goals. Whether you’re looking for foundational tools or advanced strategies, we’ve got you covered.

Don’t wait any longer to transform your investment strategy. The last 4 months have shown just how powerful these tools can be—now it’s your turn to experience the difference.

Photo by Nicholas Cappello on Unsplash

For years, I relied on trading apps that threw endless candlestick charts at me. They were colorful, yes, but when it came to making decisions, I often felt like I was guessing. What I wanted was structure — something systematic, something I could trust. That’s when I decided to build a Python script to analyze stock market patterns.

This wasn’t about predicting the next big rally or becoming a Wall Street genius overnight. My goal was simple: to use Python to uncover recurring patterns, validate trading signals, and reduce the guesswork. In this article, I’ll take you through how I did it — from collecting data all the way to generating buy/sell recommendations.

200+ AI Side Hustles to Start Right Now

AI isn't just changing business—it's creating entirely new income opportunities. The Hustle's guide features 200+ ways to make money with AI, from beginner-friendly gigs to advanced ventures. Each comes with realistic income projections and resource requirements. Join 1.5M professionals getting daily insights on emerging tech and business opportunities.

1) Getting the Data Right

The first challenge was obvious: stock data. I needed reliable, historical market data that wouldn’t require scraping shady websites. That’s when I turned to the yfinance library, which gave me direct access to Yahoo Finance’s dataset.

import yfinance as yf  
data = yf.download("AAPL", start="2020-01-01", end="2023-12-31")
print(data.head())

This gave me structured data with open, high, low, close, and volume information. Having a clean dataset from the start made every step that followed much smoother.

2) Exploring Data Before Analysis

One mistake I see beginners make is rushing straight into building algorithms without first looking at the data. I took the opposite approach.

I visualized the stock price history, checked daily volumes, and even calculated simple statistics like average daily returns. Doing this gave me a mental picture of Apple’s stock behavior. More importantly, it helped me verify that the data I pulled was trustworthy and didn’t have missing gaps.

This step may not involve flashy code, but it’s essential. If your dataset is flawed, everything you build on top of it will crumble.

3) Adding Moving Averages for Trends

With clean data in hand, I started with the most fundamental tool: moving averages. They smooth out noise and reveal underlying trends. I focused on the 20-day and 50-day simple moving averages (SMA).

data["SMA_20"] = data["Close"].rolling(window=20).mean()
data["SMA_50"] = data["Close"].rolling(window=50).mean()

When I plotted these against the stock price, crossovers between the short-term and long-term averages started standing out. These crossover points often acted as potential buy or sell signals. It wasn’t foolproof, but it was a solid baseline.

4) Recognizing Candlestick Patterns

Moving averages show trends, but traders also rely heavily on candlestick patterns. A Doji, Hammer, or Engulfing pattern can sometimes reveal a reversal before moving averages catch on.

Instead of manually squinting at charts, I automated pattern recognition with the ta-lib library. Suddenly, what used to take me minutes of staring became instant detection.

The takeaway? Automation doesn’t just save time — it also eliminates human bias. A script won’t “wish” a bullish pattern into existence the way a hopeful trader might.

5) Detecting Market Trends Beyond Visuals

Patterns alone can be misleading, especially in choppy markets. I wanted my script to label broader market trends — whether the stock was in an uptrend, downtrend, or moving sideways.

To do this, I calculated the slope of rolling price windows. A positive slope meant uptrend, negative slope meant downtrend, and near-zero slopes signaled sideways movement.

What I loved about this step was how it added context. A bullish candlestick pattern during a strong downtrend wasn’t worth acting on, but the same pattern in an uptrend? That was a different story.

6) Validating Signals With RSI

One of the easiest traps is acting on every signal you see. I needed a filter, and that’s where RSI (Relative Strength Index) came in.

RSI values above 70 usually suggest overbought conditions, while values below 30 indicate oversold conditions. By combining candlestick signals with RSI, I reduced false positives dramatically.

For example, a “buy” signal accompanied by an RSI of 85 was noise, but the same signal with an RSI of 25 was something worth noting. This kind of layered validation was the difference between a toy project and something I could actually trust.

7) Generating Actionable Signals

Once I had moving averages, candlestick recognition, trend detection, and RSI in place, I tied everything together into a signal generator.

def generate_signals(df):
    signals = []
    for i in range(len(df)):
        if df["SMA_20"].iloc[i] > df["SMA_50"].iloc[i] and df["RSI"].iloc[i] < 30:
            signals.append("BUY")
        elif df["SMA_20"].iloc[i] < df["SMA_50"].iloc[i] and df["RSI"].iloc[i] > 70:
            signals.append("SELL")
        else:
            signals.append("HOLD")
    return signals
data["Signal"] = generate_signals(data)

The first time I saw the script print out “BUY” or “SELL” next to specific dates, it felt like magic. But really, it was just Python stacking logic on top of data.

8) Putting It to the Test With Backtesting

Theory is nice, but trading requires proof. I didn’t want to trust signals blindly, so I added a simple backtesting loop.

I simulated trades based on my signals, starting with a fixed capital amount. At the end, I compared the final portfolio value with a simple buy-and-hold strategy.

This wasn’t perfect — I didn’t account for transaction costs or slippage — but it gave me a rough measure of whether my approach was better than blind luck. Sometimes it was, sometimes it wasn’t. That’s the reality of markets.

Engaging With You

That’s the journey: from raw Yahoo Finance data to an automated script that analyzes stock market patterns, filters them with RSI, and tests them with backtesting.

But here’s where I’d like to hand things over to you. If you were extending this project, what would you add? Real-time alerts? Integration with a brokerage API? Machine learning models for predictions?

Drop your thoughts below — I’d love to see how far we can push this project together.

Keep Reading

No posts found