TRIX Histogram For ThinkOrSwim

ttsdmagic

Member
Plus
Author states:
This study is an implementation of the Standard TRIX indicator (a momentum oscillator), shown in coloured histogram format by default, with optional Bar colouring of TRIX zero cross overs. Other options include showing TRIX as a line graph instead of histogram and an optional TRIX signal line with difference histogram (to highlight signal line crosses).
9SqhAzq.png


Request for conversion of TRIX Histogram. Link:
https://www.tradingview.com/script/zR5M5N6O-TRIX-Histogram-R1-12-by-JustUncleL/
 
Last edited by a moderator:
Requests
Request for conversion of TRIX Histogram. Link:
https://www.tradingview.com/script/zR5M5N6O-TRIX-Histogram-R1-12-by-JustUncleL/

//@version=3

study(title="TRIX Histogram R2.1 by JustUncleL", shorttitle="TRIXHIS R2")

// Author: JustUncleL
// Revision: R2
//
// Description:
// This study is an implementation of the Standard TRIX indicator, shown
// in coloured histogram format by default, with optional Bar colouring of TRIX zero
// and signal crossovers. Other options include showing TRIX as a linegraph instead
// of histogram and optional TRIX signal line with difference histogram.
// Have a look at Internet references below for some examples of how TRIX can be used.
//
// Candle Colouring:
// - Aqua = TRIX zero crossing from below to above zero.
// - Blue = TRIX zero crossing from above to below zero.
// - Gold = TRIX signal line crossing TRIX line from above to below.
// - Fuchsia= TRIX signal line crossing TRIX line from below to above.
//
// References:
// - http://forex-indicators.net/momentum-indicators/trix
// - http://www.dolphintrader.com/3-ma-exponential-moving-average-trix-forex-strategy/
// - "TRIX MA" by munkeefonix
//
// Revisions:
// R2 - Added Signal line crossover bar colouring and all TRIX crosses highlighted.
// - Changed Signal line crosses to "+", instead of arrow for better visibility.
// - Added Alerts for crossovers.
// - Added Implied GPL Copyright notice.
//
// R1 - Original version.
//
//
// -----------------------------------------------------------------------------
// Copyright 2014 munkeefonix
// Copyright 2017,2018 JustUncleL
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// The GNU General Public License can be found here
// <http://www.gnu.org/licenses/>.
//
// -----------------------------------------------------------------------------
//

// --- INPUTS ---
//
length = input(12, minval=1, title="TRIX length")
signallen = input(8, minval=1, title="Signal Length")
showSignal= input(true, title="Show Signal line")
showLine = input(false, title="Show TRIX as Line instead of Histogram")
showZeroX = input(false, title="Show TRIX Zero cross overs")
showTrixX = input(false, title="Show TRIX Signal cross overs")
showBars = input(false, title="Colour Crossover Candles")
//
// --- /INPUTS ---

// --- CONSTANTS ---
//
BLUE = #0000FFFF
AQUA = #00FFFFFF
GOLD = #FFD700FF
gold = #FFD700
BLACK = #000000FF
GRAY = #808080FF
DARKGRAY= #696969FF
PURPLE = #800080FF
FUCHSIA = #FF00FFFF
MAROON = #8B0000FF
GREEN = #008000FF
//
scaleup = 2
//
// --- /CONSTANTS

// --- FUNCTIONS ---
//
// Triple EMA function
tema(a, b)=>ema(ema(ema(a, b), b), b)

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

// --- /FUNCTIONS ---

// --- SERIES ---
//
TRIX = trix(close,length)
TRIXsig = ema(TRIX,signallen)
TRIXdiff= (TRIX - TRIXsig) * scaleup
//
signalX = crossover(TRIXsig,TRIX) ? -1 : crossunder(TRIXsig,TRIX) ? 1 : 0
//
trixZX = crossover(TRIX,0)? 1 : crossunder(TRIX,0)? -1: 0
//
// --- /SERIES ---

// --- PLOTTING
//
hline(0, title="Zero")
plot(showLine?na:TRIX, title="TRIX Histogram", color = TRIX>=0 ? rising(TRIX,3)?lime:green : falling(TRIX,3)?maroon:red, style=histogram, linewidth=4, transp=10)
plot(showLine?TRIX:na, title="TRIX Line", color = TRIX>=0 ? rising(TRIX,3)?lime:green : falling(TRIX,3)?maroon:red, style=line, linewidth=2, transp=10)
plot(showSignal?TRIXsig:na, title="TRIX Signal", color = orange, style=circles, join=true, linewidth=2, transp=10)
plot(showSignal?TRIXdiff:na, title="TRIX Diff", color = gray, style=area, linewidth=1, transp=70)

plot(showSignal and showTrixX and signalX!=0?TRIXsig:na, style=cross, title="Signal X Highlight", color=black, transp=20, linewidth=5)
plot(showSignal and showTrixX and signalX==1?TRIXsig:na, style=cross, title="Signal X up", color=gold, transp=0, linewidth=4)
plot(showSignal and showTrixX and signalX==-1?TRIXsig:na, style=cross, title="Signal X down", color=fuchsia, transp=20, linewidth=4)

plot(showZeroX and trixZX!=0?TRIX:na, style=circles, title="Zero X Highlight", color=black, transp=20, linewidth=5)
plot(showZeroX and trixZX==1?TRIX:na, style=circles, title="Zero X up", color=aqua, transp=10, linewidth=4)
plot(showZeroX and trixZX==-1?TRIX:na, style=circles, title="Zero X down", color=blue, transp=10, linewidth=4)

bclr = showZeroX? trixZX==1? AQUA: trixZX==-1? BLUE: na : na
bclr := not na(bclr)? bclr : showSignal and showTrixX ? signalX==-1? FUCHSIA : signalX==1? GOLD : na : na
barcolor(showBars?bclr:na,title="TRIX Zero X Bar")

// --- /PLOTTING ---

// --- ALERTING ---

alertcondition(trixZX==1,title="ZERO X Up Alert",message="ZERO X UP")
alertcondition(trixZX==-1,title="ZERO X Down Alert",message="ZERO X DOWN")
alertcondition(signalX==1,title="Signal X Up Alert",message="SIGNAL X UP")
alertcondition(signalX==-1,title="Signal X Down Alert",message="SIGNAL X DOWN")

// --- /ALERTING ---

// eof
check the below

CSS:
#//  Author: JustUncleL
#//  Revision: R2
#study(title="TRIX Histogram R2.1 by JustUncleL", shorttitle="TRIXHIS R2")
# Converted by Sam4Cok@Samer800    - 02/2024
declare lower;

#/ --- INPUTS ---
input trixSource = close;
input trixLength = 12; #, minval=1, title="TRIX length")
input signalLength = 8; #,  minval=1, title="Signal Length")
input showSignal = yes; #(true, title="Show Signal line")
input ShowTrixAsLineInsteadOfHistogram  = no; #(false, title="Show TRIX as Line instead of Histogram")
input showZeroCrosses = no; #(false,  title="Show TRIX Zero cross overs")
input showSignalCrosses = no; #(false,  title="Show TRIX Signal cross overs")
input colorBars  = no; #(false, title="Colour Crossover Candles")
input scaleUp = 2;

def na = Double.NaN;
def last = isNaN(close);
#// Colors
DefineGlobalColor("GOLD", CreateColor(255, 215, 0));


script rising{
    input src = close;
    input len = 20;
        def rising = fold i = 0 to len with p=1 while p do
                     GetValue(src, i) > GetValue(src, i + 1);
        plot out = rising;
}
script falling{
    input src = close;
    input len = 20;
        def falling = fold i = 0 to len with p=1 while p do
                      GetValue(src, i) < GetValue(src, i + 1);
        plot out = falling;
}
#// TRIX function
Script trix {
input src = close;
input len = 12;
    def tema = ExpAverage(ExpAverage(ExpAverage(src, len), len), len);
    def trix = 10000 * ((tema - tema[1]) / tema[1]);
    plot out = trix;
}

#// --- SERIES ---
def TRIX     = trix(trixSource, trixLength);
def TRIXsig  = ExpAverage(TRIX, signalLength);
def TRIXdiff = (TRIX - TRIXsig) * scaleup;
def signalX = if (TRIXsig Crosses Above TRIX) then -1 else
              if (TRIXsig Crosses Below TRIX) then 1 else 0;
def trixZX = if (TRIX Crosses Above 0) then 1 else
             if (TRIX Crosses Below 0) then -1 else  0;

#-- Signals

plot sigXup = if showSignal and showSignalCrosses and signalX==1 then TRIXsig else na;    # "Signal X up"
plot sigXdn = if showSignal and showSignalCrosses and signalX==-1 then TRIXsig else na;   # "Signal X down"
plot zeroXup = if showZeroCrosses and trixZX==1 then 0 else na;     # "Zero X up"
plot zeroXdn = if showZeroCrosses and trixZX==-1 then 0 else na;    # "Zero X down"

sigXup.SetPaintingStrategy(PaintingStrategy.SQUARES);
sigXdn.SetPaintingStrategy(PaintingStrategy.SQUARES);
zeroXup.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
zeroXup.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
sigXup.SetDefaultColor(Color.CYAN);
sigXdn.SetDefaultColor(Color.MAGENTA);
zeroXup.SetDefaultColor(Color.VIOLET);
zeroXdn.SetDefaultColor(Color.PLUM);
#/ --- PLOTTING

def TRIXdif = if showSignal then TRIXdiff else na;     # "TRIX Diff"
AddCloud(TRIXdif, 0, Color.GRAY, Color.GRAY);

plot TRIXsignal = if showSignal then TRIXsig else na; #, title="TRIX Signal"
plot TRIXHist = if ShowTrixAsLineInsteadOfHistogram then na else TRIX; #, title="TRIX Histogram"
plot TRIXline = if ShowTrixAsLineInsteadOfHistogram then TRIX else na; #, title="TRIX Line"
plot hline = if last then na else 0; #, title="Zero")

TRIXline.SetLineWeight(2);
TRIXHist.SetLineWeight(4);
TRIXHist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
TRIXHist.AssignValueColor(if TRIX >= 0 then if rising(TRIX,3) then Color.GREEN else Color.DARK_GREEN else
                          if falling(TRIX,3) then Color.DARK_RED else Color.RED);
TRIXline.AssignValueColor(if TRIX >= 0 then if rising(TRIX,3) then Color.GREEN else Color.DARK_GREEN else
                          if falling(TRIX,3) then Color.DARK_RED else Color.RED);
TRIXsignal.SetPaintingStrategy(PaintingStrategy.POINTS);
TRIXsignal.SetDefaultColor(Color.DARK_ORANGE);
hline.SetStyle(Curve.SHORT_DASH);
hline.SetDefaultColor(Color.DARK_GRAY);

#-- Bar Color
def bclr1 = if showZeroCrosses then if trixZX==1 then 2 else if trixZX==-1 then -2 else 0 else 0;
def bclr  = if bclr1!=0 then bclr1 else
            if showSignal and showSignalCrosses then if signalX==-1 then -1 else
                                                     if signalX==1 then 1 else 0 else 0;

AssignPriceColor(if !colorBars then Color.CURRENT else
                 if bclr == 2 then Color.CYAN else
                 if bclr ==-2 then Color.MAGENTA else
                 if bclr == 1 then Color.VIOLET else
                 if bclr ==-1 then Color.PLUM else
                 if TRIX >= 0 then if rising(TRIX,3) then Color.GREEN else Color.DARK_GREEN else
                 if falling(TRIX,3) then Color.DARK_RED else Color.RED);
#-- END of CODE
 
check the below

CSS:
#//  Author: JustUncleL
#//  Revision: R2
#study(title="TRIX Histogram R2.1 by JustUncleL", shorttitle="TRIXHIS R2")
# Converted by Sam4Cok@Samer800    - 02/2024
declare lower;

#/ --- INPUTS ---
input trixSource = close;
input trixLength = 12; #, minval=1, title="TRIX length")
input signalLength = 8; #,  minval=1, title="Signal Length")
input showSignal = yes; #(true, title="Show Signal line")
input ShowTrixAsLineInsteadOfHistogram  = no; #(false, title="Show TRIX as Line instead of Histogram")
input showZeroCrosses = no; #(false,  title="Show TRIX Zero cross overs")
input showSignalCrosses = no; #(false,  title="Show TRIX Signal cross overs")
input colorBars  = no; #(false, title="Colour Crossover Candles")
input scaleUp = 2;

def na = Double.NaN;
def last = isNaN(close);
#// Colors
DefineGlobalColor("GOLD", CreateColor(255, 215, 0));


script rising{
    input src = close;
    input len = 20;
        def rising = fold i = 0 to len with p=1 while p do
                     GetValue(src, i) > GetValue(src, i + 1);
        plot out = rising;
}
script falling{
    input src = close;
    input len = 20;
        def falling = fold i = 0 to len with p=1 while p do
                      GetValue(src, i) < GetValue(src, i + 1);
        plot out = falling;
}
#// TRIX function
Script trix {
input src = close;
input len = 12;
    def tema = ExpAverage(ExpAverage(ExpAverage(src, len), len), len);
    def trix = 10000 * ((tema - tema[1]) / tema[1]);
    plot out = trix;
}

#// --- SERIES ---
def TRIX     = trix(trixSource, trixLength);
def TRIXsig  = ExpAverage(TRIX, signalLength);
def TRIXdiff = (TRIX - TRIXsig) * scaleup;
def signalX = if (TRIXsig Crosses Above TRIX) then -1 else
              if (TRIXsig Crosses Below TRIX) then 1 else 0;
def trixZX = if (TRIX Crosses Above 0) then 1 else
             if (TRIX Crosses Below 0) then -1 else  0;

#-- Signals

plot sigXup = if showSignal and showSignalCrosses and signalX==1 then TRIXsig else na;    # "Signal X up"
plot sigXdn = if showSignal and showSignalCrosses and signalX==-1 then TRIXsig else na;   # "Signal X down"
plot zeroXup = if showZeroCrosses and trixZX==1 then 0 else na;     # "Zero X up"
plot zeroXdn = if showZeroCrosses and trixZX==-1 then 0 else na;    # "Zero X down"

sigXup.SetPaintingStrategy(PaintingStrategy.SQUARES);
sigXdn.SetPaintingStrategy(PaintingStrategy.SQUARES);
zeroXup.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
zeroXup.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
sigXup.SetDefaultColor(Color.CYAN);
sigXdn.SetDefaultColor(Color.MAGENTA);
zeroXup.SetDefaultColor(Color.VIOLET);
zeroXdn.SetDefaultColor(Color.PLUM);
#/ --- PLOTTING

def TRIXdif = if showSignal then TRIXdiff else na;     # "TRIX Diff"
AddCloud(TRIXdif, 0, Color.GRAY, Color.GRAY);

plot TRIXsignal = if showSignal then TRIXsig else na; #, title="TRIX Signal"
plot TRIXHist = if ShowTrixAsLineInsteadOfHistogram then na else TRIX; #, title="TRIX Histogram"
plot TRIXline = if ShowTrixAsLineInsteadOfHistogram then TRIX else na; #, title="TRIX Line"
plot hline = if last then na else 0; #, title="Zero")

TRIXline.SetLineWeight(2);
TRIXHist.SetLineWeight(4);
TRIXHist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
TRIXHist.AssignValueColor(if TRIX >= 0 then if rising(TRIX,3) then Color.GREEN else Color.DARK_GREEN else
                          if falling(TRIX,3) then Color.DARK_RED else Color.RED);
TRIXline.AssignValueColor(if TRIX >= 0 then if rising(TRIX,3) then Color.GREEN else Color.DARK_GREEN else
                          if falling(TRIX,3) then Color.DARK_RED else Color.RED);
TRIXsignal.SetPaintingStrategy(PaintingStrategy.POINTS);
TRIXsignal.SetDefaultColor(Color.DARK_ORANGE);
hline.SetStyle(Curve.SHORT_DASH);
hline.SetDefaultColor(Color.DARK_GRAY);

#-- Bar Color
def bclr1 = if showZeroCrosses then if trixZX==1 then 2 else if trixZX==-1 then -2 else 0 else 0;
def bclr  = if bclr1!=0 then bclr1 else
            if showSignal and showSignalCrosses then if signalX==-1 then -1 else
                                                     if signalX==1 then 1 else 0 else 0;

AssignPriceColor(if !colorBars then Color.CURRENT else
                 if bclr == 2 then Color.CYAN else
                 if bclr ==-2 then Color.MAGENTA else
                 if bclr == 1 then Color.VIOLET else
                 if bclr ==-1 then Color.PLUM else
                 if TRIX >= 0 then if rising(TRIX,3) then Color.GREEN else Color.DARK_GREEN else
                 if falling(TRIX,3) then Color.DARK_RED else Color.RED);
#-- END of CODE
Thanks SO much for converting this @samer800 . I appreciate it!
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
451 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top