Logo
OFFLINEPIXEL
/ pinescript-strategies / pine-script-trix

$ Pinescript Trix (Triple Exponential Average)

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

500+ Clients Helped
100% Satisfaction
Live Trading Ready
⚠️
Trading financial markets carries risk. All content (PineScript code, indicators, strategies) on this website is for educational purposes only. Past performance is not indicative of future results. By using any code or information from this site, you agree that you are solely responsible for your trading decisions. The author disclaims all liability for any losses incurred. To gain from experts experiences, You can always try our Invite Only Scripts
01

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.

02

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.
03

Basic Trix Implementation in Pinescript

pine-script@terminal
//@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)
$ ✓ Compiled successfully
04

Zero Line Importance

Zero Line Importance

The zero line is crucial for Trix. Crossing above zero indicates bullish momentum, while crossing below indicates bearish momentum.

05

Practical Trix Trading Strategies

06

1. Zero Line Crossover Strategy (Trend Direction)

pine-script@terminal
//@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)
$ ✓ Compiled successfully
07

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

pine-script@terminal
//@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)
$ ✓ Compiled successfully
08

3. Trix Divergence Strategy

pine-script@terminal
//@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.")
$ ✓ Compiled successfully
09

Optimizing Trix Performance

To enhance the effectiveness of the Trix indicator in Pinescript:

  • Parameter Tuning: The `length` parameter significantly impacts Trix's responsiveness. A shorter length makes it more sensitive but prone to noise, while a longer length smooths it more but adds lag. Experiment with different lengths (e.g., 9, 15, 20) and `signalLength` for various assets and timeframes.
  • Combine with Volume: Confirm Trix signals with volume. Strong breakouts or crossovers on high volume are generally more reliable.
  • Multi-Timeframe Analysis: Use Trix on a higher timeframe to confirm the overall trend direction, and then look for signals on a lower timeframe for entries and exits.
  • Filter Ranging Markets: Trix performs best in trending markets. In choppy or sideways markets, it can still produce false signals despite its smoothing. Consider using a trend filter (like ADX or SuperTrend) to confirm trend presence before acting on Trix signals.
10

Smoothed but Lagging

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.

11

Common Trix Pitfalls

  • Lag: Due to its extensive smoothing, Trix can sometimes generate signals later than other, less-smoothed oscillators, potentially causing delayed entries/exits.
  • Whipsaws in Consolidation: Despite noise reduction, Trix can still produce false signals in prolonged sideways or ranging markets, especially if the `length` is too short.
  • Over-Reliance: No single indicator provides perfect signals. Trix should always be used in conjunction with other technical analysis tools and proper risk management.
  • Misinterpretation of Flat Trix: A Trix line that is flat and hovering near zero indicates a lack of strong trend or momentum, making it a poor time for trend-following strategies.
12

Conclusion

Conclusion

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.

Enhance Your Trading

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