What it measures
The Awesome Oscillator compares short-term momentum with longer-term momentum. It's the difference between a 5-bar and a 34-bar simple moving average of each bar's midpoint, drawn as a histogram. Above zero, the short average is higher than the long one; below zero, lower.
Bill Williams introduced it as part of his trading method, alongside the Alligator and fractals. It's close in spirit to MACD, but uses simple averages of the bar midpoint instead of exponential averages of the close.
The formula in words
- Midpoint of each bar = (high + low) ÷ 2.
- AO = 5-period SMA of the midpoint − 34-period SMA of the midpoint.
- Each bar is coloured green if AO is higher than on the previous bar and red if it's lower. The colour describes the change, not the sign.
Like MACD, AO is in price units, so its values can't be compared across symbols. The whole formula is two moving averages, which the script writes out with ta.sma(hl2, ...).
How traders read it
- Zero-line crosses. AO crossing above zero means the 5-bar average of the midpoint has moved above the 34-bar average: short-term momentum has turned up. It's the same event as a 5/34 SMA crossover of the midpoint.
- Saucers. Above zero, two red bars (momentum easing) followed by a green bar is a bullish saucer: a pause in upward momentum that resumes. Below zero, two green bars followed by a red one is a bearish saucer.
- Twin peaks. Two lows below zero, the second higher than the first, with AO staying below zero between them, is Williams' bullish twin peaks; the bearish version mirrors it above zero. It's a form of divergence and needs swing detection to code.
- Colour. A change from red to green describes momentum improving, even below zero. Many traders use colour for timing and the zero line for direction.
Common settings
| Setting | Typical value | Notes |
|---|---|---|
| Fast SMA | 5 | Williams' default. |
| Slow SMA | 34 | Williams' default. |
| Source | Bar midpoint | Fixed in the original definition. |
Most traders keep 5 and 34. Changing them turns AO into a generic moving-average oscillator, which can be useful, but the saucer and twin-peaks descriptions were written for the defaults.
Pine Script v6 code
The complete, self-contained script is below. Copy it into a new indicator in TradingView's Pine Editor, or download the .pine file.
//@version=6
indicator("Awesome Oscillator", shorttitle = "AO")
fastLen = input.int(5, "Fast SMA", minval = 1, group = "Calculation")
slowLen = input.int(34, "Slow SMA", minval = 2, group = "Calculation")
showSaucers = input.bool(true, "Mark saucers", group = "Signals")
// AO = 5-period SMA of the bar midpoint minus the 34-period SMA of the bar midpoint.
ao = ta.sma(hl2, fastLen) - ta.sma(hl2, slowLen)
rising = ao > ao[1]
zeroUp = ta.crossover(ao, 0)
zeroDown = ta.crossunder(ao, 0)
// Saucer: three bars on the same side of zero, two moving against the trend, then one moving with it.
bullSaucer = ao > 0 and ao[1] > 0 and ao[2] > 0 and ao[2] < ao[3] and ao[1] < ao[2] and ao > ao[1]
bearSaucer = ao < 0 and ao[1] < 0 and ao[2] < 0 and ao[2] > ao[3] and ao[1] > ao[2] and ao < ao[1]
plot(ao, "AO", color = rising ? color.new(color.teal, 0) : color.new(color.red, 0), style = plot.style_columns)
hline(0, "Zero", color = color.new(color.gray, 50))
plotshape(showSaucers and bullSaucer, "Bullish saucer", shape.triangleup, location.bottom, color.new(color.teal, 0), size = size.tiny)
plotshape(showSaucers and bearSaucer, "Bearish saucer", shape.triangledown, location.top, color.new(color.red, 0), size = size.tiny)
alertcondition(zeroUp, "AO crosses above zero", "Awesome Oscillator crossed above zero on {{ticker}} ({{interval}})")
alertcondition(zeroDown, "AO crosses below zero", "Awesome Oscillator crossed below zero on {{ticker}} ({{interval}})")
alertcondition(bullSaucer, "Bullish saucer", "Bullish Awesome Oscillator saucer on {{ticker}} ({{interval}})")
alertcondition(bearSaucer, "Bearish saucer", "Bearish Awesome Oscillator saucer on {{ticker}} ({{interval}})")AO is drawn as green and red columns, with triangles on bullish and bearish saucers using the definition above: three bars on the same side of zero, two moving against the trend and then one moving with it. Saucer marks can be switched off.
Alert conditions cover zero-line crosses and both saucers. The bar and its colour can change while the bar is open, so use Once per bar close.
Add it to your chart
- Open any chart on TradingView and open the Pine Editor.
- Create a new indicator, delete the template code and paste the script.
- Click Save, then Add to chart. Change lengths and levels from the indicator's settings.
Stuck on an error? See how to add a Pine Script indicator to TradingView.
Pitfalls
- Colour as a signal on its own. Red and green bars alternate constantly in ranges.
- Saucers in weak trends. A saucer just above zero in a sideways market is a much weaker reading than one in a clear trend.
- Comparing levels. AO is in price units: compare it only with its own history on the same symbol.
- Lag. A 34-period average is slow, so zero-line crosses come well after the turn.
Related reading
- Pine Script alerts: alertcondition() vs alert(), messages, webhooks and frequency
- Pine Script v6 for beginners: the concepts that make everything click
- Risk/Reward Calculator (free tool)
- Expectancy & Win-Rate Calculator (free tool)
The script is an educational example: test it on your own markets before relying on it. Indicators describe the past; they don't predict the future. Trading involves substantial risk of loss and is not suitable for every investor. Edgoro is a software tool, not a broker or financial adviser: nothing it produces is investment advice, and past or backtested performance does not guarantee future results.