Course E · Testing Popular Ideas

Formula sheet

E1 How we test an idea

Net result, and the lead over holding

net = gross − n × c
lead = net − hold
gross
the trades' results added up, before costs, in points
n
the number of trades
c
the cost of one trade, in points
net
the result after costs, in points
hold
what just holding made over the same days, after its one cost
lead
points ahead of holding; a minus sign means behind

E1 How we test an idea

More versions, a stricter pass mark

chance per version = α ÷ n
chance per version
how often a no-skill version may reach the mark set for it
α
how often you accept a lucky pass anywhere in the whole search, often 5 in 100
n
the number of versions tried, dropped ones included

E2 Moving-average crosses

The two moving averages

SMAt = (Ct + Ct−1 + … + Ct−n+1) ÷ n
EMAt = α × Ct + (1 − α) × EMAt−1,   α = 2 ÷ (n + 1)
Ct
the close on day t; Ct−1 the day before
n
the length, in days
α
the newest close's share in the EMA (the Greek letter alpha)
EMAt−1
yesterday's EMA; the very first one is the SMA of the first n closes

E2 Moving-average crosses

Crosses, versions and % a year

dt = fastt − slowt
position after day t's close = long if dt > 0, else flat
cross up: dt−1 ≤ 0 and dt > 0; cross down: dt−1 > 0 and dt ≤ 0
lag of an n-day average ≈ (n − 1) ÷ 2 days
versions = choices × choices × …
pairs = k × (k − 1) ÷ 2
% a year, g: (1 + g)years = end ÷ start, so g = (end ÷ start)1 ÷ years − 1
the rule's gain on a day = the market's % change that day if the rule was already long, 0 if flat; around a trade, only the part after the fill counts (same close: from that close; next open: from the next day's open)
cost bill a year ≈ trades a year × cost per trade
dt
fast average minus slow average on day t
≤, ≈
"equal to or below"; "about"
k
how many lengths you choose from
end, start
the account at the end and the start; years is the test's length

E3 RSI

The relative strength index

RS = AG ÷ AL
RSI = 100 − 100 ÷ (1 + RS) = 100 × AG ÷ (AG + AL)
AG
the average gain over about the last n days: each up day's rise, and 0 for a down day (with Wilder's smoothing, older days count less)
AL
the average loss over the same days, as a positive size
RS
how many times bigger the average gain is than the average loss
n
the length, in days; 14 is usual

E3 RSI

Wilder's smoothing is a moving average

AGt = AGt−1 + α × (Gt − AGt−1),   α = 1 ÷ n
Gt
today's gain (0 on a down day); losses update the same way
AGt−1
yesterday's average gain; the first one is the simple average of the first n gains
α
today's share of the new average (the Greek letter alpha)

E4 MACD

The exponential moving average

EMAt = EMAt−1 + α × (Ct − EMAt−1),   α = 2 ÷ (n + 1)
Ct
the close on day t
EMAt−1
yesterday's EMA; in this course the first one, on day n, is the simple average of the first n closes
α
today's close's share of the new EMA (the Greek letter alpha)
n
the length, in days

E4 MACD

The three lines of the MACD

MACDt = EMAfast(C)t − EMAslow(C)t
signalt = EMAsig(MACD)t
histogramt = MACDt − signalt
EMAfast(C), EMAslow(C)
EMAs of the close with the fast and the slow length (12 and 26 days by custom)
EMAsig(MACD)
an EMA of the MACD line, with the signal length (9 days by custom); in this course it starts from the simple average of its first 9 values

E5 Volatility bands

The three bands

Mt = (Ct−n+1 + … + Ct) ÷ n
st = √( [(Ct−n+1 − Mt)² + … + (Ct − Mt)²] ÷ n )
uppert = Mt + k × st,   lowert = Mt − k × st
Ct
the close on day t; each sum runs over the last n closes, today's included
n
the length: how many closes (20 by custom)
Mt
the middle band: the simple moving average of those n closes
st
their standard deviation, dividing by n in this course (some tools divide by n − 1)
k
the width, in standard deviations (2 by custom)

E6 VWAP

VWAP and its bands

VWAPt = (PaVa + … + PtVt) ÷ (Va + … + Vt)
st = √( [Va(Pa − VWAPt)² + … + Vt(Pt − VWAPt)²] ÷ (Va + … + Vt) )
uppert = VWAPt + k × st,   lowert = VWAPt − k × st
Pi
bar i's price: in this lesson the typical price, (high + low + close) ÷ 3; some tools use the close
Vi
bar i's volume: the shares traded in it
a
the anchor: the first bar the sums use (each day's first bar for a session VWAP)
st
the volume-weighted standard deviation: the typical distance of the prices from VWAP, each bar counted by its volume
t
the bar now; each sum runs over every bar from a to t
k
the width, in volume-weighted standard deviations

E7 Previous day high and low

Why touching is common: the reflection principle

P(touch) ≈ 2 × P(end beyond)
P(touch)
the chance a price touches the level at some point in a stretch of time, such as a day
P(end beyond)
the chance it ends that stretch beyond the level (above a high, below a low): count it on past days, as below, or read it off the bell curve from the level's distance in typical day's moves (see The bell curve)
≈
about: exact only for prices with no pattern in which way they move, watched at every moment

E8 The opening-range breakout

Target or stop first: the gambler's ruin

P(target first) = s ÷ (s + g)
s
the distance from the entry price to the stop
g
the distance from the entry price to the target
P(target first)
the chance the price reaches the target before the stop, for prices with no pattern in which way they move, moving in small steps (no jumps past the stop or target), when nothing else ends the trade

E9 The higher-timeframe filter

Read a longer bar only after it closes

j = ⌊(i + 1) ÷ m⌋ − 1
i
the short bar that has just closed, counted from 0 at the start of the first long bar
m
how many short bars make one long bar
j
the last finished long bar, counted from 0, when every long bar holds exactly m short bars
⌊ ⌋
round down to a whole number

E10 Session windows

A clock time needs its offset

tNY = tUTC + o(d)
tUTC
the time stamped in UTC
o(d)
New York's offset on date d: −4 hours from the second Sunday in March to the first Sunday in November (the US rule since 2007), −5 hours otherwise
tNY
the New York clock time of the same moment

E11 SMC: market structure

How many swings a market with no pattern makes

P(swing high) = qn2,   qn = ½ × ¾ × ⅚ × … × (2n − 1) ÷ (2n)
n
the width: the days on each side
qn
the chance the price stays below a given close for each of the next n days, when every day brings the same kind of move, as likely a rise of any size as a fall of the same size, independently, never exactly zero
P(swing high)
the chance a given close is a swing high of width n (close reading), under the same conditions; a swing low has the same chance

E12 SMC: liquidity sweeps

Why most sweeps come back: the Sparre Andersen theorem

P(back within n closes) ≈ 1 − qn,   qn = ½ × ¾ × ⅚ × … × (2n − 1) ÷ (2n)
n
the closes counted, starting with the bar in which the price crosses the level: 3 for 15 minutes of five-minute bars
qn
the chance all n closes stay past the level, when each move is as likely a rise of any size as a fall of the same size, independently, never exactly zero
P(back within n closes)
the chance at least one of them is back on the near side, for a price that starts at the level, under the same conditions

E13 SMC: fair value gaps

Reaching a level: the reflection principle

P(reach) = 2 × (1 − Φ(d ÷ (σ × √n)))
d
the distance from the price now to the level
σ
the standard deviation of one bar's move (how far a typical bar moves, as in the Volatility lesson)
n
the number of bars left; √n is its square root (√9 = 3)
Φ(z)
the chance that a draw from the bell curve (the hump-shaped spread of many random results; the Bell curve lesson) is below z standard deviations; in a spreadsheet, NORM.S.DIST(z,TRUE)
P(reach)
the chance the price touches the level before time runs out, for a price with no drift (no steady rise or fall) and no pattern in which way it moves, moving in small steps of a steady size

E14 SMC: order blocks

Is a small difference luck? The standard error

SE = s ÷ √n
z = average ÷ SE
n
the number of independent measurements (here, markets)
s
their standard deviation: how far a typical one sits from their average
SE
the standard error: how far luck typically moves the average of n such measurements
z
how many standard errors the average sits from zero; for an average of many independent measurements, beyond 2 either way happens about 5 times in 100 if only luck is at work

E15 Confluences

The error bar of a win rate

SE = √(p × (1 − p) ÷ n)  ·  error bar = p ± 2 × SE
p
the win rate as a fraction (35 in 100 = 0.35)
n
the number of trades
SE
the standard error of the win rate, as a fraction (× 100 for points: 0.01 is one point)

E16 Capstone: test an idea of your own

The chance that at least one version clears the line

P(at least one) = 1 − (1 − p)N
p
the chance that one version clears the line when there is nothing to find
N
the number of versions tried
P(at least one)
the chance that at least one of the N clears it, when the N are separate tries (one's result says nothing about another's) with the same p