YellowBar


How it works
Automated Options Trading with Inside Days
This is an automated trading robot that I built to trade the stock market without having to sit at a computer all day watching charts.
The robot watches SPY for one simple pattern, the inside day, and trades options when the price breaks out of it. It picks the option contract by scoring the nearby strikes and expirations on live prices, places the order through the Alpaca API, and manages the position with fixed take-profit and stop-loss rules. It sends email notifications for trade events and follows risk controls such as one trade per day and day-trading limits.
Implemented using TypeScript with background task scheduling.
How the System Works: Step-by-Step
1. Inside Day Detection [Daily Scan]
Once a day, right after the market opens, the system compares SPY's last two completed daily bars. If yesterday's high was below the previous day's high and yesterday's low was above the previous day's low, yesterday was an "inside day": the price was compressed into a tighter range than the day before, like a coiled spring. If there's no inside day, the system does nothing that day. It also skips holidays and other days the market is closed.
2. Breakout Monitoring [All-Session Watch]
When there's an inside day, the system watches SPY's live price every few seconds for the whole session. The breakout is the only entry rule: a trade above the inside day's high means a CALL (betting on more upside), and a trade below its low means a PUT (betting on more downside). No other indicators are checked. If SPY stays inside the range until 1:30 PM ET, the system stops watching for the day: every position is closed before the market closes, so a late entry would leave too little time to work.
3. Account Checks [Safety Rules]
Before placing an order, the system makes sure no other trade has been placed that day (one trade per day), that the account is within the day-trading limits, and how much cash is available for the position.
4. Contract Selection [Scoring]
Instead of always buying the same strike, the system scores the nearby options: from at the money to 2 strikes in the money, expiring today up to 2 trading days out. For each one it works out, from the live bid and ask, how much the option moves for each $1 of SPY (delta) and how much value it will lose to time decay while the trade is open. It then buys the contract that needs the smallest SPY move to gain 10% after paying the spread and the time decay. Contracts with a wide spread are passed over.
5. Order Execution [Limit Order at Mid]
The order is placed through Alpaca's brokerage API as a limit order at the middle of the bid/ask spread, so it doesn't overpay. If it isn't filled within 10 seconds, it's cancelled. Every order is logged, and an email is sent if anything goes wrong.
6. Position Monitoring [Fixed Exits]
Once the position is open, the system checks it every few seconds against fixed exit rules: take profit once the gain is above +10%, and stop out at -25%. As the trade works, a trailing stop moves up: at +5% the stop moves to +1%, and at +7% the stop moves to +3%, so a trade that gets close to the target doesn't turn into a loss. It also exits if SPY moves back into the inside day by 25% of its range, because the breakout has failed.
7. Position Closure [End of Trade]
When an exit rule is hit, the system sells 100% of the position and emails the results: entry and exit prices, profit or loss, percentage return and how long the trade lasted. Positions are never held overnight. Anything still open at 3:50 PM ET is closed. The next morning, the scan starts again.
Why it's useful: Instead of me having to stare at charts all day and make emotional decisions about when to buy and sell, this system follows the same simple rules every day, removing emotion and fatigue from trading decisions. It's like having a disciplined trading assistant that watches the market while I do other things and sends me email updates about what it's doing with my money.
- Built in
- 2025
- Built with
- Alpaca API
- Monitors
- SPY
- Strategy
- Inside Days