← Back to home

Architecture

trend-pullback

A trading research and alert tool. No setup can send an alert before it is tested on years of history and proves it beat the base.

1. The problem

Anyone can write a backtest that makes money. The problem is that a profitable backtest proves almost nothing, and there are two ways of fooling yourself that kill any trading tool.

The first is tuning the setup until the history looks good. The result describes the past and does not survive the first month of real market.

The second is harder to see: the setup makes money, but entering on any candle with the same stop and the same target would have made the same money. In that case the edge is in the risk management, not in the signal, and you spent months building a trigger that contributes nothing.

The engineering problem is this: build a system designed to refuse its own setups, and let only what passes reach the phone.

2. The numbers

All results come from the history tests, with costs charged on every trade. R is the risk of a trade: making 0.15R per trade means making 15% of what would have been lost if the stop had been hit.

84
US stocks and ETFs that can produce a trade
146
stocks and ETFs in the full study universe
62
Brazilian assets tested. None beat the base, none sends a signal
2
test periods: development until October 2024, final from November 2024 onwards
+0.15R
for the daily trap with the trend, in both periods. The base made +0.07R and then -0.06R
+0.27R / +0.19R
for the weekly trap. The base made +0.24R and +0.12R: it beat the base by a small margin
3.6
signals a week in total, less than one per trading day
$2,200
starting balance of each paper book, risking 2% per trade
4
alert stages, each sent at most once
0
exchange keys and real orders. Every trade is a paper trade

3. The design

Two paths sharing the same rule code, with a gate between them. The study decides what is allowed to exist. The live alert only runs what the study approved.

STUDY — RUN BY HAND, DECIDES WHAT MAY EXISTHistoryBinance archives, YahooBacktesttwo separate periodsBase comparisonany entry at all,same stop and targetVerdictfour possible resultstp-coreindicators and rules — the same code on both sidesGATE: only a setup that won in both periods and beat the base can alertLIVE — HOURLY, RUNS ONLY WHAT PASSEDLive priceYahoo (15 min) · BinanceEvaluationcalls tp-coreStagessignal · entered · exited · expiredeach one only onceTelegram, dashboardand paper book

tp-core holds the indicators and the rules, and both sides call it. That is what makes the test worth anything: if the backtest ran one piece of code and the alert ran another, the test would prove nothing about what actually fires on your phone.

The four possible verdicts

Every result line from the studies ends in a verdict. Only the first one lets a setup send alerts.

Won in both periods and beat the base

Alerts are allowed. It is the only verdict that passes.

Positive without proof

Above the base, but without enough trades to support it. Alerts marked as under observation, or dashboard only.

Did not beat the base

The profit came from the stop and the target, not from the signal. Dashboard without signals.

Lost

Stays off. It remains in the code and sends nothing.

4. The decisions

Every decision has a price. Below is what I chose, what I rejected, why, and what it costs.

01. A setup has to beat the base, not just make money

Chose
Every setup is compared against entering on any candle with the same stop and the same target. If it does not beat that base, it does not alert.
Over
Accepting any setup with a positive result.
Because
A positive result can come entirely from the stop and the target, with the signal contributing nothing. Comparing against an arbitrary entry isolates what the trigger actually adds. Without that comparison you ship risk management dressed as a strategy and believe you found something.
Price I pay
A setup that genuinely works by a small margin gets refused along with the noise. The weekly trap beat the base narrowly and only just survived.

02. Two periods, and the second is never used for tuning

Chose
Development until October 2024. Final test from November 2024 onwards, with no tuning done while looking at it.
Over
A single backtest over all available history.
Because
Anything tuned on the same data it is tested on will look good. Holding back a period that was never looked at during development is the cheapest defence there is against fitting the past.
Price I pay
Less data to develop on, and the final period shrinks on its own as it becomes the present. Eventually it has to be retired and a new one held back.

03. The same code runs the study and the live alert

Chose
tp-core holds the indicators and the rules, and is called by both the backtest and the alert.
Over
A research script and a separate production implementation.
Because
If the backtest runs one piece of code and the alert runs another, the backtest says nothing about what actually fires. That is the most common way a trading tool lies to its own owner without anyone noticing.
Price I pay
Changing tp-core changes the past and the present at the same time. Every edit invalidates published results and forces the studies to be re-run.

04. Most setups were tested and turned off

Chose
Mechanical Smart Money on every chart, every sell on stocks and every day-trade setup on 15-minute and 1-hour charts lost in the tests and send nothing. Brazilian stocks did not beat the base and appear on the dashboard without signals.
Over
Shipping everything that was built.
Because
A tool that alerts on everything teaches you to ignore alerts. Once you learn to swipe the notification away, the good signal dies alongside the noise.
Price I pay
A lot of built work produces no alerts at all. What the project shows on the outside is far smaller than the code behind it.

05. Sent stages are recorded, so a message never repeats

Chose
The four stages, signal, entered, exited and expired, are recorded when sent. On the first run with a new book, trades already open are marked as seen with no message.
Over
Recomputing and sending on every run.
Because
The alert runs hourly over the same open positions. Without recording what has already gone out, the same signal arrives every hour until it expires, and a repeated alert is an ignored alert.
Price I pay
State in files that has to survive between runs. And a position that was already running before the book existed produces no history in the feed.

06. The alert reports what entering late costs

Chose
During the US session, when the price passes the trigger, the alert says how many whole shares to buy and how much the later entry changes the reward-to-risk ratio.
Over
Assuming the backtest fill.
Because
The test buys exactly at the trigger. In a real session, with a broker that only takes market and limit orders, you buy later and worse. Showing the new ratio at the moment of the alert keeps the gap between test and reality visible instead of hidden inside a nice number.
Price I pay
It is extra work on the critical path, and it tells the person something uncomfortable at exactly the second they were about to act.

07. No exchange keys, no orders, paper books only

Chose
The system executes nothing. Every recorded trade is a paper trade.
Over
Automating execution.
Because
The setups are still being proven. Connecting a key to a system whose edge is not established turns a research mistake into a money loss, and does it faster than you can notice.
Price I pay
Every trade has to be placed by hand, and the book records what the rule says rather than what was actually filled.

5. What breaks

What is unresolved today, including what fails silently.

Everything depends on a personal computer being awake

Both routines run on Windows through WSL, started by the Task Scheduler. If the machine sleeps or shuts down, no error happens: new lines simply stop appearing in the log. The failure is silent and is only found by someone who goes and checks the file, which nobody does every day.

Exit code 124 is routine, not an exception

It means the run was cut by the time limit, nine minutes for alerts and ten for markets, usually a slow network. The next run continues from saved state and nothing is lost, but a chronically slow network means a permanently late system, without that showing up as a problem anywhere.

Prices come from public sources with no contract

Stocks and ETFs come from Yahoo Finance's public chart data, about fifteen minutes delayed, and crypto comes from Binance's public data. Neither is a contracted API: they can change shape or stop without notice, and there is no second source to compare against or to take over.

The books are CSV files with no lock

The files in data/live/ hold the financial records, and the instruction is not to edit them by hand while a run is going. Nothing enforces it. Two overlapping runs, or an edit at the wrong moment, corrupt the trade history with no warning.

Alerting under observation is an unresolved problem

The trap on BTC, ETH and SOL stayed above the base in both periods, but without enough trades to prove it. Marking it as under observation is honest, and the system is still sending a signal it cannot itself justify.

The held-out period is being consumed

It began in November 2024 and grows every day. The longer the setups run and are watched inside it, the less it is a separate period and the more it becomes just another part of the data the decisions were made on.

The book and the alert do not measure the same thing

The book records entries and exits from closed candles, and the intraday alert fires on a live price. The two will not match exactly, and that difference is not measured anywhere today.

6. What I would change at 100x

Scenario: a thousand assets instead of 84, more than one person using it, and studies running on every change rather than by hand.

What survives unchanged

The discipline. The base comparison and the split into two periods depend on neither volume nor infrastructure: they are rules. They hold the same with 84 assets or with a thousand, and they are the part of the project that actually matters.

What breaks first

The hourly run on a single computer. With a thousand assets, downloading the data and evaluating the setups does not finish inside the nine-minute window, and exit code 124 stops being an exception and becomes the normal behaviour.

In the order I would change them

  1. 1

    Get the schedule off the personal machine. Today the whole system stops silently when a laptop sleeps, and that is a bigger problem than capacity: a silent failure is worse than a slow one.

  2. 2

    Separate downloading data from evaluating setups. Today one run does both inside the same time limit. With a layer that downloads continuously and an evaluator that reads what is already local, the network leaves the critical path.

  3. 3

    Replace the CSV files with a database, mainly for the lock. The books are financial records with no concurrency protection, and at any volume two runs will eventually meet.

  4. 4

    Run the studies automatically on every change to tp-core. Today touching a shared rule silently invalidates every published result, and the only thing that catches it is someone remembering to re-run them.

This page describes the system as it stands today. No orders are executed, there are no exchange keys, and every recorded trade is a paper trade. A historical test result is not a promise of future results.