AlgoPro UniversityCourse home
Part 4 · Lesson

From hypothesis to rules

A strategy is not an indicator — it is a testable claim about why a market misprices something. Learn to state that claim and compile it into exact, codeable conditions.

Beginners start with an indicator ("the RSI") and go looking for a way to trade it. Professionals start with a hypothesis — a specific claim about *why* a market offers a repeatable opportunity — and then reach for whatever indicator expresses it. This lesson is about learning to think in the second order, because it is the difference between a strategy and a curve-fit accident.

Where edges come from

Real, durable edges almost always trace back to one of two sources. Everything else is usually noise dressed up as a signal.

  1. Behavioural — humans react predictably. They chase winners (momentum), panic-sell into support (over-reaction), anchor to round numbers, and under-react to slow news. These biases are structural because they are wired into people, and people keep showing up to trade.
  2. Structural — the plumbing of the market forces certain flows. Index funds must buy a stock the day it joins the index; futures roll on a schedule; margin calls force liquidation at the worst time; a central bank defends a level. These flows are price-insensitive, which is exactly what a price-sensitive trader can lean against.

Notice what is *not* on that list: "the lines crossed". A moving-average crossover is not an edge — it is a *tool*. It only becomes an edge when it expresses a claim like "trends in this instrument persist because large institutions accumulate positions over weeks, not minutes".

The market can stay irrational longer than you can stay solvent — but the reasons it is irrational are the same reasons, over and over.trader’s paraphrase of Keynes

From a vague idea to a precise claim

Most ideas arrive vague: *"gold seems to trend after the London open"*. That is a fine start, but it is not yet testable. Sharpen it by forcing answers to five questions — the who, what, when, why and how-much:

Compiling the claim into conditions

A tradeable rule is nothing more than a boolean — a condition that is true or false on every bar. "Enter long when the fast average is above the slow average AND price is above its 200-bar average" is three comparisons combined with and. Once your idea is stated crisply, translating it is mechanical:

pythonTurning a hypothesis into an explicit, testable condition
import pandas as pd

class="c"># Hypothesis: class="s">"XAUUSD 1h trends persist during the London session,
class="c"># so entering on a breakout of the London-open range should catch
class="c"># the continuation." We compile that sentence into columns.

def london_breakout_signal(df: pd.DataFrame) -> pd.Series:
    class="s">""class="s">"df has a DatetimeIndex (UTC) and columns: open, high, low, close."class="s">""
    hour = df.index.hour
    in_session = (hour >= class="n">8) & (hour < class="n">16)          class="c"># WHEN: London hours

    class="c"># The class="n">06:class="n">00-class="n">07:class="n">00 range that defines the level to break
    opening_hour = df.between_time(class="s">"class="n">06:class="n">00", class="s">"class="n">06:class="n">59")
    day = df.index.normalize()
    range_high = opening_hour[class="s">"high"].groupby(opening_hour.index.normalize()).max()
    level = day.map(range_high)                      class="c"># today's breakout level

    breakout = df[class="s">"close"] > level                   class="c"># TRIGGER: close above range
    signal = (in_session & breakout).astype(int)     class="c"># class="n">1 = long, class="n">0 = flat
    return signal

That function is the whole idea, made honest. Every assumption — which hours count, what "breakout" means, what defines the level — is now visible, versioned, and testable. Nothing is hiding in your discretion. This is the discipline the rest of the part builds on: a strategy is a function from data to a signal, and if you cannot write that function, you do not yet understand your own idea.

Next we take the two most important archetypes — trend and momentum — and build them properly, with pandas signal code and charts showing exactly where the trades fire.