munkeefonix

TRIX with Moving Average

Updated version of the Trix to include crossover on the background.

Length: Length of the Trix
Use Ema: True will use an ema, false will use an SMA.
Moving Average: Moving Average used on the TRIX Value.
Histogram Multiplier: Exaggerate the difference between the TRIX and Moving Average.
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?
study("TRIX Moving Average v2", shorttitle="TRIX MA")
//  Trix with a EMA or SMA. 
//
//  @author munkeefonix
//  https://www.tradingview.com/u/munkeefonix/
//
//  inputs:
//  Length: Length of the Trix
//  Use Ema: Use an ema or sma.
//  Moving Average: Moving Average used on the TRIX Value.
//  Histogram Multiplier: Exaggerate the difference between the TRIX and Moving Average.

_length=input(15, title="TRIX Length", minval=1)
_useEma=input(true, type=bool, title="Use Ema")
_ma=input(9, title="Moving Average", minval=1)
_mult=input(2.0, type=float, minval=1, title="Histogram Multiplier")
_filter=input(0.0, type=float, minval=0.0, title="Near Zero Filter")

tema(a, b)=>ema(ema(ema(a, b), b), b)
trix(a)=>((a-a[1]) / a[1]) * 10000

_trix=trix(tema(close, _length))
_trixs=_useEma ? ema(_trix, _ma) : sma(_trix, _ma)
_trixh=(_trix-_trixs)

bgcolor(_trixh[1] >= 0 and _trixh[0] < 0 ? red : _trixh[1] <= 0 and _trixh[0] > 0 ? blue : na)

hline(0, color=#000000, title="Zero Line")

plot(_trixh * _mult, color=#000000, style=area, transp=80, title="Histogram")
plot(_trix, color=#FFCC00, title="TRIX")
plot(_trixs, color=#CC0000, title="TRIX Moving Average")

plot(cross(_trix, _trixs) ? _trix : na, color=white, style=cross, linewidth=2, title="TRIX Moving Average")