WMA 20 50 ATR Trailing Stop (Trend)
Buys when the 20-bar weighted moving average crosses above the 50-bar, and exits on the cross back down or on a trailing stop 3 average true ranges below the highest close since entry.
How It Works
- Compute the 20- and 50-bar weighted moving averages and the 22-bar average range.
- Buy when the 20-bar WMA crosses above the 50-bar.
- While in the trade, track the highest close since entry and trail a stop 3 average ranges below it — the stop only ever moves up.
- Sell on whichever comes first: the averages crossing back down, or price hitting the trailing stop — locking in profit on a sharp reversal without waiting for the slow averages to cross.
Worked example. WMA20 crosses above WMA50 at a price of 100 with an average range of 1.0, so the initial stop sits at 97. Price climbs to a high close of 110, dragging the stop up to 107. A sudden slide to 106.8 hits the trailing stop and banks the gain before the averages ever cross back.
The Math Behind The Indicators
Everything runs on closing prices of the traded timeframe: P is a close, Pt today's close, and N counts bars — one bar is one candle of that timeframe, so 20 bars on a 1h chart is 20 hours.
- Weighted Moving Average (WMA)
- A moving average where newer prices count more: the latest close gets weight N, the one before N − 1, down to weight 1 for the oldest. That makes it react to a turn in price sooner than a plain average.
- \[\mathrm{WMA}_N = \dfrac{N \cdot P_t + (N-1) \cdot P_{t-1} + \cdots + 1 \cdot P_{t-N+1}}{N + (N-1) + \cdots + 1}\]
- Example: With N = 3 and closes 100, 102, 104 (oldest to newest): (1·100 + 2·102 + 3·104) / (1 + 2 + 3) = 616 / 6 ≈ 102.67 — pulled closer to the latest price than the plain average of 102.
- Average Range (ATR)
- How much price typically moves per bar. These backtests run on closing prices, so each bar's range is the absolute close-to-close change, and the ATR is the average of the last N ranges. It sizes stops: a stop placed k ATRs away automatically adapts to how volatile the market currently is.
- \[\mathrm{ATR}_N = \dfrac{1}{N}\sum_{i=1}^{N} \left|P_{t-i+1} - P_{t-i}\right|\]
- Example: If the last three close-to-close moves were +2, −1 and +3, the ranges are 2, 1, 3 and the 3-bar ATR is 2. A stop 2 ATRs below an entry at 100 then sits at 96.