Breakout watch across several stocks, with an AI check
Watches AAPL, MSFT and NVDA on 15-minute bars and, when one closes above the high of its previous 20 bars, asks the AI whether it looks like a clean breakout or a likely fakeout. Each question is asked without waiting for the last, and only a "breakout" answer becomes a notice. It never trades.
Watches AAPL, MSFT and NVDA on 15-minute bars and, when one closes above the high of its previous 20 bars, asks the AI whether it looks like a clean breakout or a likely fakeout. Each question is asked without waiting for the last, and only a "breakout" answer becomes a notice. It never trades.
Shows: Monitor, warmup() per symbol in on_start, several @on.bar lines on one handler, bar["symbol"], ai.ask(then=, tag=), notify(title=, level=, symbol=).
"""Breakout watch across several stocks, with an AI check
Watches AAPL, MSFT and NVDA on 15-minute bars and, when one closes above the
high of its previous 20 bars, asks the AI whether it looks like a clean
breakout or a likely fakeout. Each question is asked without waiting for the
last, and only a "breakout" answer becomes a notice. It never trades.
Shows: Monitor, warmup() per symbol in on_start, several @on.bar lines on one handler, bar["symbol"], ai.ask(then=, tag=), notify(title=, level=, symbol=).
"""
import while25
from while25 import Monitor, on
from while25.inputs import Int
SYMBOLS = ["EQ:US:AAPL", "EQ:US:MSFT", "EQ:US:NVDA"]
WINDOW = 20
def is_breakout(window, bar):
"""True when `bar` closed above the highest high of the bars before it."""
return bool(window) and bar["close"] > max(r["high"] for r in window)
def push(window, bar, n=WINDOW):
"""The window with `bar` added and only the newest n kept."""
return (window + [bar])[-n:]
class BreakoutWatch(Monitor):
id = "us_breakout_watch"
label = "US breakout watch"
inputs = [Int("max_questions", default=20, minimum=1, maximum=200,
label="Most AI questions per run")]
def on_start(self, ctx):
self.rows = {s: list(while25.warmup(s, "15m", WINDOW)) for s in SYMBOLS}
self.asked = 0
@on.bar("EQ:US:AAPL", "15m")
@on.bar("EQ:US:MSFT", "15m")
@on.bar("EQ:US:NVDA", "15m")
def bar(self, ctx, bar):
key = bar["symbol"]
window = self.rows[key]
self.rows[key] = push(window, bar)
if not is_breakout(window, bar) or self.asked >= while25.params["max_questions"]:
return # the free check: most bars end here
self.asked += 1
while25.ai.ask("Is this a clean breakout or a likely fakeout? Rows are 15-minute "
"bars, oldest first; the last row is the breakout bar.",
data=self.rows[key], choices=["breakout", "fakeout"],
then=self.judged, tag=key)
def judged(self, ctx, answer, tag):
if answer == "breakout": # the price has moved since: this is a prompt to look
last = self.rows[tag][-1]["close"]
while25.notify(f"closed at {last}, above the 20-bar high", title=tag.split(":")[-1],
level="warn", symbol=tag)
elif answer is None:
while25.log(f"no AI answer for {tag}")Trend significance: is the drift in the last N closes real, or noise?
Fits a least-squares line through the last `length` closes and draws the slope's t-statistic as a histogram in its own pane, with the +/-2 line shaded. Use it to compare trend strength across symbols: a t-statistic has no units.
Fill journal for the whole account
Writes every execution on the account, from any strategy or by hand, to a CSV file in the workspace, one row per fill, and logs each order that ends refused or cancelled. A journal you can open in a spreadsheet at the end of the day.