Momentum-Adjusted Moving Average (MaMA)
A moving average that knows when to move fast and when to hold steady.
Every moving average faces the same fundamental tradeoff. A short length reacts quickly to price changes but produces noise in choppy conditions. A long length smooths out noise but lags too much to be useful in fast-moving markets. Traditional solutions - EMA, HMA, adaptive MAs - all attempt to address this, but they typically rely on a single feedback mechanism.
MaMA takes a different approach. Rather than adjusting speed based on volatility alone, it incorporates price momentum, momentum acceleration, and directional persistence simultaneously - three independent signals that together determine how strongly the current price move should influence the average. The result is an indicator that reacts decisively during genuine trending phases and stabilizes during consolidation, without requiring any manual switching between timeframes or settings.
How MaMA Works
At its core, MaMA feeds an adjusted price series into a standard moving average rather than raw price. The adjusted series combines the actual price with a momentum term - the recent rate of price change - weighted by trend persistence, a measure of how consistently price has been moving in one direction over the lookback period.
When price has been trending consistently in one direction and momentum is strong, trend persistence is high, and the momentum term adds significant weight to the adjusted source. The average moves decisively in the direction of the trend. When price is oscillating without consistent direction, persistence is low, the momentum contribution diminishes, and MaMA behaves closer to a standard moving average - staying stable rather than whipsawing with each small fluctuation.
An optional acceleration component - the second derivative of momentum - adds further responsiveness during explosive phase transitions, where the rate of change itself is changing rapidly. This makes MaMA particularly effective at detecting the early stages of breakouts or reversals before they are fully reflected in price.
Gradient Coloring
MaMA uses a four-color gradient system to communicate trend strength visually. Deep green indicates strong bullish momentum. Light green indicates mild or weakening bullish momentum. Light red indicates mild or weakening bearish momentum. Deep red indicates strong bearish momentum. The color at any point reflects a composite strength score derived from normalized momentum magnitude, acceleration, and trend persistence - giving an immediate read on whether the current trend is strengthening or fading without requiring close attention to the line's slope.
An optional standard moving average using the same length and type can be displayed alongside MaMA for direct comparison, making the adaptive behavior immediately visible.
Adaptive Feedback Bands
Inspired by feedback concepts from electronic engineering, the Feedback Bands are dynamic envelopes around MaMA that expand and contract based on the relative deviation of the adjusted price from the average, smoothed through an internal volatility measure.
When price is deviating significantly from MaMA - indicating an extended or volatile move - the bands widen, marking pressure zones where a mean reversion or continuation decision is likely approaching. When price is consolidating close to MaMA, the bands contract, indicating low volatility and potential energy buildup before the next directional move.
A fill gradient between MaMA and each band reinforces the visual - darker toward the outer band, lighter near the average - making it immediately clear how close price is to the boundary of normal deviation versus extended territory. Feedback strength and band smoothness are independently configurable.
Backtest Framework
The same integrated backtest engine used across the dgtrd toolkit is embedded here, using MaMA price crossovers as the entry and exit triggers. When price crosses above MaMA, a long signal is generated. When price crosses below, a short signal fires. Long Only, Short Only, and Both trade modes are supported, with optional reversal on opposite signal, configurable stop loss, candle direction confirmation, and same-bar conflict avoidance. Entry and exit labels, early warning labels, and a floating trade statistics panel all update in real time.
Alerts
Four alert conditions fire in two pairs - Early Signal on the unconfirmed bar and Confirmation on the confirmed bar - for both long and short crossovers. All alerts include ticker, price, and timestamp.
MaMA length, momentum length, acceleration toggle, trend persistence length, MA type, plot offset, gradient colors, feedback band strength and smoothness, band colors, and all backtest parameters are fully configurable.