Learning LibraryQuant LibraryTeens

Trading signals: turning numbers into decisions

Indicators are just numbers until a rule turns them into a decision. A signal is that rule — a boolean test that outputs buy, hold, or sell. (Conceptual only — not financial advice.)

The big idea

A trading signal is a rule that maps indicator values to a decision, usually expressed as comparisons returning a category.

See it in code

1The basics

At heart, a signal is one comparison that ends in a decision. Take a fast average and a slow one: if fast is above slow, the rule says BUY, otherwise it waits:

python
# A signal is a rule that outputs a decision - study only.
fast = 101
slow = 100

if fast > slow:
    print("BUY")
else:
    print("HOLD")
Run it — one comparison, one decision:
BUY

One test, two outcomes. But markets don't only go up — a real signal needs a way to say SELL too, so we add a third branch.

2A step further

Add elif for the crossover's third case: fast below slow is a bearish SELL, and dead-equal is HOLD. Now the rule covers every case:

python
fast = 99
slow = 100

if fast > slow:
    print("BUY")
elif fast < slow:
    print("SELL")
else:
    print("HOLD")
Run it — fast is below slow, so the rule says SELL:
SELL

Three branches, three decisions. Right now it only judges one pair — wrap it in a function and you can apply the exact same rule to a whole series of averages.

3In our world

Now package that three-way rule as a function and run it across many days. This is the classic crossover: fast above slow is bullish, below is bearish, equal holds — a function of two comparisons:

python
# A signal maps indicators to buy / hold / sell - for study, not advice.
def signal(fast, slow):
    if fast > slow:
        return "BUY"
    elif fast < slow:
        return "SELL"
    return "HOLD"

pairs = [(101, 100), (99, 100), (100, 100)]
for fast, slow in pairs:
    print(f"fast={fast}, slow={slow} -> {signal(fast, slow)}")
Run it — each pair of averages maps to a decision:
fast=101, slow=100 -> BUY
fast=99, slow=100 -> SELL
fast=100, slow=100 -> HOLD

The middle pair, 99 vs 100, gives SELL — the same case we ran by hand above, now just one row in a series. The whole 'strategy' is a few comparisons wrapped in a function. That's the point: a signal is just logic turning indicators into an action. Whether it's a good rule is a separate, hard question — and the reason this stays educational.

The same idea, everywhere

Mapping measurements to a decision is a universal control pattern: a thermostat (temp vs setpoint), an alert system (metric vs threshold), a game AI (distance vs range). Read the numbers, apply a rule, choose an action — the shape recurs everywhere.

Try it yourself

Add a 'buffer' so tiny differences return HOLD — like if fast > slow + 1. This reduces flip-flopping, a real concern with noisy signals. Then feed in moving averages you computed earlier.

The common mistake

Confusing a signal with a guarantee. A rule that says BUY is not a prediction that prices will rise — it's just what the rule outputs. Treating signals as certainties, or over-trading on noisy ones, is exactly why disciplined risk rules exist.

What it unlocks

Signals build on comparison operators, conditionals, and moving averages, and are studied through backtesting.