Trading Strategy
TRIX Strategy
A momentum oscillator strategy using Triple Exponential Average (TRIX) to identify trend direction and filter out market noise.
Triple Smoothed Momentum
TRIX (Triple Exponential Average) is a momentum oscillator that shows the rate of change of a triple smoothed EMA. It filters out insignificant price movements and identifies trend changes. Combined with a signal line crossover and 200 EMA trend filter, this strategy provides reliable entry signals while avoiding false breakouts.
Momentum Type
4h Chart Timeframe
Intermediate Complexity
Trending Best Market
Signal Logic
Long (Buy)
TRIX crosses above its signal line while price is above 200 EMA (uptrend confirmation).
Short (Sell)
TRIX crosses below its signal line while price is below 200 EMA (downtrend confirmation).
Implementation
//@version=6
strategy("TRIX Strategy", overlay=true, initial_capital=1000000, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
// ==========================================
// 🔹 INPUTS
// ==========================================
// Group: TRIX Settings
grp_trix = "TRIX Settings"
trix_len = input.int(9, "TRIX Period", minval=1, group=grp_trix)
signal_len = input.int(5, "Signal Line Period", minval=1, group=grp_trix)
// Group: Trend Filter
grp_trend = "Trend Filter"
use_trend = input.bool(true, "Use Trend Filter (EMA 200)", group=grp_trend)
ema_len = input.int(200, "Trend EMA Length", minval=1, group=grp_trend)
// Group: Risk Management
grp_risk = "Risk Management"
atr_len = input.int(14, "ATR Length", minval=1, group=grp_risk)
sl_mult = input.float(2.0, "Stop Loss (ATR Multiplier)", step=0.1, group=grp_risk)
tp_ratio = input.float(2.0, "Risk:Reward Ratio", step=0.1, group=grp_risk)
// ==========================================
// 🔹 CALCULATIONS
// ==========================================
// TRIX - Triple smoothed EMA rate of change
ema1 = ta.ema(close, trix_len)
ema2 = ta.ema(ema1, trix_len)
ema3 = ta.ema(ema2, trix_len)
trix_val = ta.change(ema3) / ema3[1] * 100
// Signal line - EMA of TRIX
signal_val = ta.ema(trix_val, signal_len)
// Trend EMA
ema_val = ta.ema(close, ema_len)
// ATR for risk management
atr_val = ta.atr(atr_len)
// Trend conditions
trend_up = use_trend ? close > ema_val : true
trend_down = use_trend ? close < ema_val : true
// ==========================================
// 🔹 STRATEGY LOGIC
// ==========================================
// Long Entry: TRIX crosses above signal line (bullish momentum)
long_signal = ta.crossover(trix_val, signal_val) and trend_up
// Short Entry: TRIX crosses below signal line (bearish momentum)
short_signal = ta.crossover(signal_val, trix_val) and trend_down
// ==========================================
// 🔹 EXECUTION & RISK MANAGEMENT
// ==========================================
if long_signal
strategy.entry("Long", strategy.long, comment="L | TRIX Bull")
if short_signal
strategy.entry("Short", strategy.short, comment="S | TRIX Bear")
// Risk management with ATR
if strategy.position_size > 0
stop_level = strategy.position_avg_price - (atr_val * sl_mult)
profit_level = strategy.position_avg_price + (atr_val * sl_mult * tp_ratio)
strategy.exit("Exit Long", "Long", stop=stop_level, limit=profit_level, comment_loss="SL", comment_profit="TP")
if strategy.position_size < 0
stop_level = strategy.position_avg_price + (atr_val * sl_mult)
profit_level = strategy.position_avg_price - (atr_val * sl_mult * tp_ratio)
strategy.exit("Exit Short", "Short", stop=stop_level, limit=profit_level, comment_loss="SL", comment_profit="TP")
// ==========================================
// 🔹 VISUALS
// ==========================================
// Plot TRIX in separate pane (commented out for overlay)
// plot(trix_val, "TRIX", color=color.blue, linewidth=2)
// plot(signal_val, "Signal", color=color.orange, linewidth=1)
// Plot Trend EMA
plot(use_trend ? ema_val : na, "Trend EMA", color=color.new(color.orange, 0), linewidth=2)
// Plot Signals on price chart
plotshape(long_signal, title="Long Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY", textcolor=color.white)
plotshape(short_signal, title="Short Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL", textcolor=color.white)
// Background color for trend
bgcolor(trend_up ? color.new(color.green, 95) : color.new(color.red, 95))