Pine Script Awesome Oscillator

Master this unique momentum indicator by Bill Williams in TradingView's Pine Script for identifying market momentum, trend shifts, and reversal signals.

Last Updated on: Expertise: Intermediate

What is the Awesome Oscillator (AO)?

The Awesome Oscillator (AO) is a momentum indicator developed by Bill Williams, the creator of the Alligator Indicator and Fractals. Unlike most oscillators that compare closing prices, the AO compares the recent market momentum (5-period simple moving average of midpoints) with the broader market momentum (34-period simple moving average of midpoints). It is typically plotted as a histogram, with bars colored green (momentum up) or red (momentum down).

The Awesome Oscillator is designed to reflect the underlying driving force of the price, helping traders identify changes in momentum, confirm trends, and spot potential reversal signals based on specific patterns.

Components and Calculation

The calculation of the Awesome Oscillator is based on two Simple Moving Averages (SMAs) of the `midpoint` price (which is `(High + Low) / 2`):

  1. Short Period SMA: Calculate a 5-period SMA of the `midpoint` price.
  2. Long Period SMA: Calculate a 34-period SMA of the `midpoint` price.
  3. AO Formula:
    `AO = Short Period SMA of Midpoint - Long Period SMA of Midpoint`
    The resulting value oscillates around a zero line. Bars are colored based on their relation to the previous bar: green if current AO > previous AO, red if current AO < previous AO.

Basic Awesome Oscillator Implementation in Pine Script

Pine Script v5 provides a convenient built-in function `ta.ao()` for straightforward implementation.

//@version=5
indicator("My Awesome Oscillator", overlay=false) // overlay=false to plot in a separate pane

// Calculate Awesome Oscillator using the built-in function
// ta.ao uses (high+low)/2 as source and default lengths 5 and 34
aoValue = ta.ao()

// Plot the Awesome Oscillator as a histogram
// Color based on whether current AO is greater than previous AO
plot(aoValue, title="AO", style=plot.style_columns, color=aoValue >= aoValue[1] ? color.green : color.red)

// Plot the Zero Line
hline(0, "Zero Line", color.gray, linestyle=hline.style_solid)

Histogram Colors: Green bars indicate rising momentum; red bars indicate falling momentum. This is key for interpreting signals.

Practical Awesome Oscillator Trading Strategies

1. Zero Line Crossover

The zero line is a crucial level for the Awesome Oscillator, indicating a shift in momentum from bearish to bullish or vice versa. It's often used as a primary signal for trend initiation.

//@version=5
strategy("AO Zero Line Crossover Strategy", overlay=true)

// Calculate Awesome Oscillator
aoValue = ta.ao()

// Define conditions for entries
longSignal = ta.crossover(aoValue, 0)
shortSignal = ta.crossunder(aoValue, 0)

// Strategy entries/exits
if (longSignal)
    strategy.entry("Long", strategy.long)

if (shortSignal)
    strategy.entry("Short", strategy.short)

// Plot AO in a separate pane for visualization
// plot(aoValue, title="AO", style=plot.style_columns, color=aoValue >= aoValue[1] ? color.green : color.red, display=display.pane_only)
// hline(0, "Zero Line", color.gray, display=display.pane_only)

2. Twin Peaks Strategy

The Twin Peaks strategy uses two peaks (or troughs) on the Awesome Oscillator for reversal signals. This is considered a more reliable signal than simple zero-line crossovers.

//@version=5
indicator("AO Twin Peaks Scanner", overlay=true)

// Calculate Awesome Oscillator
aoValue = ta.ao()

// Plot AO as a histogram
plot(aoValue, title="AO", style=plot.style_columns, color=aoValue >= aoValue[1] ? color.new(color.green, 0) : color.new(color.red, 0))
hline(0, "Zero Line", color.gray, linestyle=hline.style_solid)

// Implementing robust Twin Peaks logic requires advanced peak/trough detection.
// This is a simplified conceptual example to illustrate the idea, focusing on general AO direction changes around peaks/troughs.
// For a fully robust Twin Peaks strategy, you would need to identify actual swing points in AO.

// Simplified Bullish Twin Peak (AO makes higher low below zero, then crosses zero)
bullishTwinPeakSignal = aoValue[2] < 0 and aoValue[1] < 0 and aoValue > 0 and aoValue[1] > aoValue[2]

// Simplified Bearish Twin Peak (AO makes lower high above zero, then crosses zero)
bearishTwinPeakSignal = aoValue[2] > 0 and aoValue[1] > 0 and aoValue < 0 and aoValue[1] < aoValue[2]

plotshape(bullishTwinPeakSignal, title="Bullish Twin Peak", location=location.belowbar, color=color.new(color.green, 0), style=shape.triangleup, size=size.small)
plotshape(bearishTwinPeakSignal, title="Bearish Twin Peak", location=location.abovebar, color=color.new(color.red, 0), style=shape.triangledown, size=size.small)

alertcondition(bullishTwinPeakSignal, "Bullish AO Twin Peaks", "Potential bullish reversal based on AO Twin Peaks.")
alertcondition(bearishTwinPeakSignal, "Bearish AO Twin Peaks", "Potential bearish reversal based on AO Twin Peaks.")

3. Saucer Strategy

The Saucer strategy is a short-term momentum signal that uses three consecutive bars of the Awesome Oscillator (or two for the bearish signal) that are on the same side of the zero line but change color, indicating a subtle shift in momentum.

//@version=5
strategy("AO Saucer Strategy", overlay=true)

// Calculate Awesome Oscillator
aoValue = ta.ao()

// Plot AO as a histogram in a separate pane
plot(aoValue, title="AO", style=plot.style_columns, color=aoValue >= aoValue[1] ? color.new(color.green, 0) : color.new(color.red, 0), display=display.pane_only)
hline(0, "Zero Line", color=color.new(color.gray, 0), linestyle=hline.style_solid, display=display.pane_only)

// Bullish Saucer condition
// AO is above zero, previous two bars are red and decreasing, current bar is green
bullishSaucer = aoValue > 0 and aoValue[1] < aoValue[2] and aoValue[1] < aoValue and aoValue > aoValue[1]

// Bearish Saucer condition
// AO is below zero, previous two bars are green and increasing, current bar is red
bearishSaucer = aoValue < 0 and aoValue[1] > aoValue[2] and aoValue[1] > aoValue and aoValue < aoValue[1]

// Strategy entries/exits
if (bullishSaucer)
    strategy.entry("Long", strategy.long)

if (bearishSaucer)
    strategy.entry("Short", strategy.short)

Optimizing Awesome Oscillator Performance

To get the most from the Awesome Oscillator in Pine Script:

Zero Line as Equilibrium: Think of the zero line as the balance point between bullish and bearish forces. Crossing it signifies a shift in who is currently dominating the market.

Common Awesome Oscillator Pitfalls

Conclusion

The Awesome Oscillator is a powerful and visually intuitive momentum indicator available in Pine Script for TradingView. Developed by Bill Williams, it offers a unique perspective on market momentum by comparing short-term and long-term price midpoint averages. Whether used for identifying shifts across the zero line, spotting the nuanced Twin Peaks pattern, or leveraging the short-term Saucer signal, the AO provides valuable insights into the underlying forces driving price. By understanding its calculation and characteristic patterns, and integrating it strategically within your broader technical analysis framework, you can leverage the Awesome Oscillator to enhance your trading decisions and gain a clearer view of market dynamics.