EMA crossover
A trend-following strategy that buys when a fast exponential moving average crosses above a slow one and sells when it crosses back below.
The indicator
An exponential moving average weights recent prices more heavily than older ones. With a smoothing factor the recursion is
where is the close price at bar and is the period.
Choosing periods
| Fast | Slow | Character |
|---|---|---|
| 9 | 21 | Reactive, more signals |
| 12 | 26 | The MACD defaults |
| 50 | 200 | Slow, filters most of the noise |
The graph
flowchart LR P[Price source] --> F[EMA fast] P --> S[EMA slow] F --> X[Crossover] S --> X X -->|up| B[Buy] X -->|down| L[Sell]
Signal logic
The crossover module emits 1 on the bar where the fast line moves above the slow line, -1 where it drops below, and 0 otherwise:
def crossover(fast, slow):
above = fast > slow
return above.astype(int).diff().fillna(0)
Backtest
Run the strategy over at least one full market cycle before trusting it. Trend followers lose in sideways markets, so the equity curve should be judged on drawdown as much as on return.
Rendering diagrams...