Master this unique oscillator in TradingView's Pinescript for identifying trends, momentum, and divergence with reduced noise.
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.
Trix is derived from a triple-smoothed Exponential Moving Average of the closing price. The calculation process involves three main steps:
//@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.gray, linestyle=hline.style_dotted)
The zero line is crucial for Trix. Crossing above zero indicates bullish momentum, while crossing below indicates bearish 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)
//@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)
//@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.")
To enhance the effectiveness of the Trix indicator in Pinescript:
While Trix effectively filters noise, the triple-smoothing process introduces more lag compared to single-EMA indicators. Be aware of this when timing entries.
The Trix indicator is a sophisticated and highly effective momentum oscillator in Pinescript 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.
Get a high-performance Pinescript analysis tool for actionable market insights, designed for traders on the move.
This strategy runs in live mode on TradingView, helping you identify potential opportunities.
Get Pinescript Strategy