Pine Script Trix (Triple Exponential Average)

Master this unique oscillator in TradingView's Pine Script for identifying trends, momentum, and divergence with reduced noise.

Posted: Expertise: Intermediate

What is Trix?

The Trix (Triple Exponential Average) indicator is a momentum oscillator developed by Jack Hutson. It aims to filter out insignificant price movements (noise) by applying an exponential moving average (EMA) three times to the closing price. The result is a smooth line that oscillates around a zero line, helping traders identify trends, gauge momentum, and spot potential divergences.

Because of its triple smoothing, Trix is particularly effective at reducing short-term fluctuations, allowing traders to focus on the broader trend and less on minor price changes.

Components and Calculation

Trix is derived from a triple-smoothed Exponential Moving Average of the closing price. The calculation process involves three main steps:

  1. First EMA: Calculate an EMA of the closing price over a specified period (e.g., 15 periods).
  2. Second EMA: Calculate an EMA of the first EMA over the same period.
  3. Third EMA: Calculate an EMA of the second EMA over the same period.
  4. Trix Value: The percentage change of this third EMA from the previous bar. This effectively turns the smoothed moving average into a momentum oscillator.

Often, a signal line (typically a 9-period EMA of the Trix line) is also plotted to generate crossover signals, similar to how MACD works.

Basic Trix Implementation in Pine Script

Pine Script v5 provides a built-in `ta.trix()` function for easy implementation.

//@version=5
indicator("My Trix Indicator", overlay=false)

// Inputs for Trix parameters
length = input.int(15, title="Trix Length")
signalLength = input.int(9, title="Signal Length")

// Calculate Trix value using the built-in function
trixValue = ta.trix(close, length)

// Calculate the Signal Line (EMA of Trix)
trixSignal = ta.ema(trixValue, signalLength)

// Plot the Trix Line
plot(trixValue, title="Trix Line", color=color.blue, linewidth=2)

// Plot the Signal Line
plot(trixSignal, title="Signal Line", color=color.red, linewidth=1)

// Plot a horizontal line at zero for reference
hline(0, "Zero Line", color=color.gray, linestyle=hline.style_dotted)
Zero Line Importance: The zero line is crucial for Trix. Crossing above zero indicates bullish momentum, while crossing below indicates bearish momentum.

Practical Trix Trading Strategies

1. Zero Line Crossover Strategy (Trend Direction)

One of the simplest ways to use Trix is by observing its crossovers with the zero line. This indicates a shift in the primary trend or momentum.

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

length = input.int(15, title="Trix Length")
signalLength = input.int(9, title="Signal Length")

trixValue = ta.trix(close, length)
trixSignal = ta.ema(trixValue, signalLength)

// Define conditions
longCondition = ta.crossover(trixValue, 0)
shortCondition = ta.crossunder(trixValue, 0)

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

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

// Optional: Plot Trix in a separate pane for visualization
// plot(trixValue, "Trix Line", color.blue)
// plot(trixSignal, "Signal Line", color.red)
// hline(0, "Zero Line", color.gray)

2. Trix Signal Line Crossover Strategy (Entry/Exit Signals)

Similar to MACD, Trix also uses a signal line (an EMA of Trix) to generate more frequent and refined trading signals.

//@version=5
strategy("Trix Signal Crossover Strategy", overlay=true)

length = input.int(15, title="Trix Length")
signalLength = input.int(9, title="Signal Length")

trixValue = ta.trix(close, length)
trixSignal = ta.ema(trixValue, signalLength)

// Define conditions
longCondition = ta.crossover(trixValue, trixSignal)
shortCondition = ta.crossunder(trixValue, trixSignal)

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

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

// Optional: Plot Trix in a separate pane for visualization
// plot(trixValue, "Trix Line", color.blue)
// plot(trixSignal, "Signal Line", color.red)
// hline(0, "Zero Line", color.gray)

3. Trix Divergence Strategy

Divergence between the Trix indicator and price action can signal potential reversals, indicating that the current trend is losing momentum.

//@version=5
indicator("Trix Divergence Scanner", overlay=true)

length = input.int(15, title="Trix Length")
signalLength = input.int(9, title="Signal Length")

trixValue = ta.trix(close, length)
trixSignal = ta.ema(trixValue, signalLength)

// Plot Trix and Signal lines for visual confirmation
plot(trixValue, "Trix Line", color.blue)
plot(trixSignal, "Signal Line", color.red)
hline(0, "Zero Line", color.gray)

// Simple divergence detection (conceptual, for advanced scripts this needs robust pivot detection)
// This is a simplified example and might need refinement for actual trading.

// Bullish Divergence Example
bullishDiv = (close[2] > close[1] and close[1] > close) and (trixValue[2] < trixValue[1] and trixValue[1] < trixValue)

// Bearish Divergence Example
bearishDiv = (close[2] < close[1] and close[1] < close) and (trixValue[2] > trixValue[1] and trixValue[1] > trixValue)

// Plot divergence signals on the price chart
plotshape(bullishDiv, title="Bullish Divergence", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)
plotshape(bearishDiv, title="Bearish Divergence", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)

// Alert for divergence
alertcondition(bullishDiv, "Bullish Trix Divergence", "Trix bullish divergence detected! Potential reversal.")
alertcondition(bearishDiv, "Bearish Trix Divergence", "Trix bearish divergence detected! Potential reversal.")

Optimizing Trix Performance

To enhance the effectiveness of the Trix indicator in Pine Script:

Smoothed but Lagging: While Trix effectively filters noise, the triple-smoothing process introduces more lag compared to single-EMA indicators. Be aware of this when timing entries.

Common Trix Pitfalls

Conclusion

The Trix indicator is a sophisticated and highly effective momentum oscillator in Pine Script for TradingView. Its triple-smoothing mechanism significantly reduces noise, allowing traders to identify underlying trends, gauge momentum, and spot crucial divergences with greater clarity. By mastering its components, understanding its signals, and integrating it thoughtfully into your multi-indicator strategies, you can leverage Trix to refine your market analysis and enhance your trading decisions.