Education only. Not financial advice.
Education only. Not financial advice.
Watch the video
Show transcript
Welcome to Lesson B3. Before we start, this lesson is education only. It is not financial advice. Today you'll build a simple agent that watches a price and alerts you when it moves. It never buys or sells. And we'll use made-up sample data, so there's no account and no key needed.
First, the big difference. An alert tells you something happened, and you decide what to do. An auto-trade buys or sells by itself. This lesson builds alerts only.
Our tip: never let a beginner's agent place trades. Keep a human in charge. Remember the sneaky notes from Lesson B1? An agent that can trade can be tricked into trading.
Let's build it with Grok. Copy the prompt from the lesson page and paste it into Grok. We ask for beginner Python for Colab, with no installs, no internet and no keys. We ask Grok to make a small sample price table for a made-up stock called DEMO. Then compare each day to the first day, and print an alert if the price moved five percent or more, up or down. And we say clearly, education only, no trades.
Our tip: five percent is just a practice rule. It's not a signal to buy or sell.
Here's Grok's code, with comments and a plain-words explanation. Yours may look a little different. That's fine. In our run, Grok picked its own sample prices, so it flagged days three, four and six.
To make sure we all see the same result, the lesson page also has a ready-made block. Let's paste that into Colab. Look at the top. Six days of sample prices for DEMO, starting at one hundred. These are not real prices.
Press Run. Two alerts. Day four, up six point one percent. Day six, down five point three percent. Then done. And notice day five stays quiet. It's only down about one and a half percent from day one.
Let's check our understanding. Ask Grok, explain in plain words why day five did not trigger an alert. Our tip: asking Grok to explain results is a great way to make sure you really get it. When we tried it, Grok said Day 5 was less than five percent away from Day 1, so it stayed under the cutoff.
Later, when you want real data, services like Alpha Vantage, or Massive, which used to be called Polygon dot i o, offer data keys. Our tip: read each one's terms and limits first.
Some people use yfinance. It's an unofficial, open-source tool for Yahoo Finance data. Its makers say it is, quote, "not affiliated, endorsed, or vetted by Yahoo," end quote, and is, quote, "intended for research and educational purposes." End quote. Our tip: fine for learning, not for a product.
And to practice with pretend money, some brokers offer paper trading. Alpaca says, quote, "Paper trading is a real-time simulation environment where you can test your code." End quote. And, quote, "please note that paper trading is only a simulation." End quote. These names are examples, not endorsements.
Now the most important point. Can AI predict where a price will go? The CFTC, a U.S. government agency that oversees commodity markets, says, quote: "AI technology can't predict the future or sudden market changes." End quote.
Safety check. Our tip: alerts only, sample data first, and you make every decision. Education only. Not financial advice.
Quick check. What's the difference between an alert and an auto-trade? An alert tells you, an auto-trade acts by itself. Is the DEMO data real? No, it's sample data. Can AI predict prices? No. Next, in Lesson B4, you'll learn to test ideas honestly and spot fake AI trading bots.
What you'll learn
- The difference between an alert and an auto-trade
- How to build a simple price-watch rule with Grok's help
- Why practice money and sample data come first
Step 1: Alert, don't trade
- Alert: the agent tells you something happened. You decide what to do.
- Auto-trade: the agent buys or sells by itself.
This lesson builds alerts only. Our tip: never let a beginner's agent place trades. Keep a human in charge (see Lesson B1).
Step 2: Ask Grok for the code
Paste this into Grok:
Write beginner Python for Google Colab. No installs, no internet, no API keys.
1. Create a small SAMPLE price table in the code (not real data) for a made-up
stock called "DEMO" with 6 days of closing prices.
2. Compare each day's price to the first day.
3. If the price moved up or down by 5 percent or more, print an ALERT line
with the day, the price and the percent change.
4. Add a comment on each part, and explain it in plain words after the code.
This is for education only. Do not place trades or suggest buying or selling.
Our tip: 5 percent is just a sample rule for practice. It is not a signal to buy or sell.
Grok's real answer (our test run)
We ran this exact prompt through Grok (model grok-4.7) on Oct 30, 2026. Grok's answers change from run to run, so yours will differ. Quoted as Grok returned it, except where we mark [trimmed] and where we swapped dashes for commas to match our style.
# Part 1: A small made-up price table stored in the code. # This is sample data only. It is not a real stock and not live prices. stock_name = "DEMO" days = ["Day 1", "Day 2", "Day 3", "Day 4", "Day 5", "Day 6"] closing_prices = [100.00, 102.00, 106.00, 94.00, 101.50, 90.00] # Part 2: Use the first day's price as the comparison point. first_price = closing_prices[0] print(stock_name, "sample prices") print("First day price:", first_price) print() # Part 3: Look at each day and compare it with the first day. for day, price in zip(days, closing_prices): # Percent change from the first day: (today - first) / first * 100 percent_change = ((price - first_price) / first_price) * 100 # Alert only if the move is 5% or more, up or down. if abs(percent_change) >= 5: print( "ALERT", day, "price", round(price, 2), "change", str(round(percent_change, 2)) + "%", )This program keeps six fake closing prices for a made-up name, DEMO, inside the code. It treats Day 1 as the starting price. For each day it calculates how far that day’s price is from Day 1, as a percent. If the move is 5 percent or more in either direction, it prints one ALERT line with the day, the price, and the percent change. Days that moved less than 5 percent are skipped. This is only a classroom example of comparing numbers. It does not place trades and does not say whether anyone should buy or sell.
We ran Grok's code on our computer. Grok picked its own sample prices, so it printed alerts for Day 3 (+6.0%), Day 4 (-6.0%) and Day 6 (-10.0%). Our ready-made block below uses our own sample prices. Education only. Not financial advice.
Step 3: Or use our ready-made block
Paste this into one Colab cell and press Run:
# SAMPLE data for a made-up stock "DEMO". Not real prices.
prices = [("Day 1", 100.00), ("Day 2", 101.50), ("Day 3", 103.20),
("Day 4", 106.10), ("Day 5", 98.40), ("Day 6", 94.70)]
start = prices[0][1]
for day, price in prices:
change = (price - start) / start * 100
if abs(change) >= 5:
print(f"ALERT {day}: price {price:.2f}, {change:+.1f}% vs Day 1")
print("Done. Education only. Not financial advice.")
What you should see: alerts for Day 4 (+6.1%), Day 6 (-5.3%), then "Done." Day 5 (-1.6%) stays quiet.
Now ask Grok: "Explain in plain words why Day 5 did not trigger an alert." Our tip: asking Grok to explain results is a great way to check your understanding.
Grok's real answer about Day 5 (our test run)
We ran our ready-made block, its output and the Day 5 question through Grok (model grok-4.7) on Oct 30, 2026. Grok's answers change from run to run, so yours will differ. Quoted as Grok returned it, except where we mark [trimmed] and where we swapped dashes for commas to match our style.
Day 5 did not print an alert because its price was less than 5% away from Day 1.
The program only alerts when the change from Day 1 is 5% or more, up or down. Anything smaller is skipped. From your output, Day 1 is 100.00 (Day 4 at 106.10 is +6.1%, and Day 6 at 94.70 is -5.3%). Day 5 must have landed between 95.00 and 105.00, so the move was too small to meet the cutoff.
Our block shows Day 5 at 98.40, which is -1.6%, so it stays under the 5% cutoff. Education only. Not financial advice.
Step 4: Moving to real data later (optional)
When you're ready, data services offer keys for real price data, such as Alpha Vantage or Massive (formerly Polygon.io). Our tip: read each one's terms and limits before you use it.
Some people use yfinance, an unofficial, open-source tool for Yahoo Finance data. Its makers say it is "not affiliated, endorsed, or vetted by Yahoo" and is "intended for research and educational purposes." (yfinance on PyPI) Our tip: fine for learning, not for a product. Check Yahoo's terms before any other use.
To practice with pretend money, brokers like Alpaca offer paper trading. Alpaca says: "Paper trading is a real-time simulation environment where you can test your code." It also says: "please note that paper trading is only a simulation." (Alpaca paper trading)
These names are examples, not endorsements.
Check yourself
- What's the difference between an alert and an auto-trade? (Answer: an alert tells you, an auto-trade acts by itself)
- Is the DEMO data real? (Answer: No, it's sample data)
- Can AI predict where a price will go? (Answer: No. See the caution box.)
Caution box The CFTC says: "AI technology can't predict the future or sudden market changes." (CFTC Customer Advisory) Our tip: alerts only, sample data first, and you make every decision. Education only. Not financial advice.
Builds on
- AI Helps You Learn Stocks guide
- Lesson A3: Build with Grok as your coding partner
- Lesson B1: Prompt injection, explained simply
Sources
- CFTC, "AI Won't Turn Trading Bots into Money Machines," Jan 25, 2024 (date per CFTC press release 8854-24): https://www.cftc.gov/LearnAndProtect/AdvisoriesAndArticles/AITradingBots.html ; https://www.cftc.gov/PressRoom/PressReleases/8854-24
- yfinance on PyPI: https://pypi.org/project/yfinance/
- Alpaca paper trading: https://docs.alpaca.markets/us/docs/paper-trading
- Alpha Vantage support: https://www.alphavantage.co/support/
- Massive (formerly Polygon.io) pricing: https://massive.com/pricing
Creator credits
- xAI (Grok): X https://x.com/grok , https://x.com/spacexsi
- CFTC: X https://x.com/CFTC , YouTube https://www.youtube.com/user/CFTC
- Alpaca: X https://x.com/AlpacaHQ
- Massive: X https://x.com/massive_com , YouTube https://www.youtube.com/@massive_com
Education only. Not financial advice.