trader.strategies.alligator module¶
Williams Alligator: a trend-following crossover of three shifted, smoothed moving averages.
Different signal shape from anything else in this module: rsi_revert and bollinger_revert are level-triggered oscillators, turtle is a channel breakout, and ma_crossover compares two unshifted averages. This one compares three averages that are each forward-shifted in time before the comparison happens at all, and the “level” it fires on is not a price level but a specific ordering of three lines relative to price (issue #34).
The three lines, in Bill Williams’ naming:
jaw = 13-period smoothed average of the close, shifted forward 8 bars.
teeth = 8-period smoothed average of the close, shifted forward 5 bars.
lips = 5-period smoothed average of the close, shifted forward 3 bars.
“Smoothed” is exponential (trader.indicators.ema, alpha = 2/(N+1)), not Wilder’s or a simple average. The classic Alligator smooths the median price (high + low) / 2; this implementation smooths the close instead, to stay consistent with the fan check below (jaw < teeth < lips < Close, per the issue) and with every other strategy in this module, all of which reason about the close alone. That is a deliberate simplification the issue left open, not an oversight.
“Feeding” (bullish): jaw < teeth < lips < Close — the three lines fan out below price, in order. “Feeding” (bearish): the mirror image, jaw > teeth > lips > Close. Anything else is the Alligator “sleeping” — tangled lines, no trade either way.
The signal is the transition into a feeding state, not the state itself: holding the transition rather than the state is what makes this edge-triggered rather than level-triggered, and matches ma_crossover’s transition-based signal rather than the level checks in rsi_revert / bollinger_revert.
- class trader.strategies.alligator.AlligatorStrategy(id, jaw_period=13, teeth_period=8, lips_period=5, jaw_shift=8, teeth_shift=5, lips_shift=3)[source]¶
Bases:
objectBuy on the transition into feeding-bullish; sell on the transition into feeding-bearish.
Edge-triggered by construction: the state itself (jaw < teeth < lips < close, say) can hold for many consecutive bars while the Alligator keeps feeding, and a level-triggered strategy would re-signal a BUY on every one of them. Comparing this bar’s state against the bar before it — the same shape ma_crossover uses for its crossover — means a signal fires exactly once per transition, on its first bar.
- Parameters:
id (str)
jaw_period (int)
teeth_period (int)
lips_period (int)
jaw_shift (int)
teeth_shift (int)
lips_shift (int)
- id: str¶
- jaw_period: int¶
- teeth_period: int¶
- lips_period: int¶
- jaw_shift: int¶
- teeth_shift: int¶
- lips_shift: int¶
- backtestable: ClassVar[bool] = True¶