B-Xtrender Indicator for ThinkorSwim

Mordoor

New member
2019 Donor
I was reading a journal and came across an interesting trend indicator created by Bharat Jhunjhunwala called the B-Xtrender. It plots as two different histograms below the chart. There is a short term indicator and a long term indicator. Here is how he describes it:

The short-term indicator indicates the corrections in the ongoing major trend. The short-term indicator is constructed by using the following steps:

a. A 20-day exponential moving average of the price is derived. A 20-day period is selected, as it encompasses roughly a trading month. Exponential moving averages are one of the most dynamic ways of smoothing the trend.
b. The 15-day period RSI (Wilder’s Relative Strength Index) of the above 20-day period EMA of Price is calculated.
c. The above formula is then plotted as a histogram for better visual representation.
We can use Amibroker Afl for the creation of the above: Field = (RSIa((EMA(C,5)- EMA(C,20)),15))-50;

The long-term indicator displays the major trend that is in place. The long-term indicator is constructed by using the following steps:

a. A 5-day exponential moving average of the closing price is derived. A 5-day period is selected, as it marks a trading week.
b. A 20-day exponential moving average of the closing price is derived. A 20-day period is considered, as it marks a trading month.
c. The difference of a 5-day exponential moving average of the price and a 20-day exponential moving average of the price is derived.
d. A 15-day period RSI (Wilder’s Relative Strength Index) of the above “difference” is derived and plotted.
e. The above derivation is plotted as a histogram for better visual representation. We can use Amibroker Afl to create the above formula as: Field = (RSIa((EMA(C,5)- EMA(C,20)),15))-50

Would anyone be interested in creating this in TOS? Here is a link to the journal: https://ifta.org/publications/journal/ Scroll down towards the bottom of the page and click on the downloadable PDF for the 2019 journal. This indicator is shown and described on page 21-34. He has backtested this and has some pretty impressive results.

Here is the code from TradingView. Please help me convert it.

Code:
//@version=4
study("B-Xtrender @Puppytherapy")

short_l1 = input(5 , title="Short - L1")
short_l2 = input(20, title="Short - L2")
short_l3 = input(15, title="Short - L3")

long_l1  = input(20, title="Long - L1")
long_l2  = input(15, title="Long - L2")

shortTermXtrender = rsi(ema(close, short_l1) - ema(close, short_l2), short_l3 ) - 50
longTermXtrender  = rsi( ema(close, long_l1), long_l2 ) - 50

shortXtrenderCol = shortTermXtrender > 0 ? shortTermXtrender > shortTermXtrender[1] ? color.lime : #228B22 : shortTermXtrender > shortTermXtrender[1] ? color.red : #8B0000
plot(shortTermXtrender, color=shortXtrenderCol, style=plot.style_columns, linewidth=1, title="B-Xtrender Osc. - Histogram", transp = 50)

t3(src, len)=>
    xe1_1 = ema(src,    len)
    xe2_1 = ema(xe1_1,  len)
    xe3_1 = ema(xe2_1,  len)
    xe4_1 = ema(xe3_1,  len)
    xe5_1 = ema(xe4_1,  len)
    xe6_1 = ema(xe5_1,  len)
    b_1 = 0.7
    c1_1 = -b_1*b_1*b_1
    c2_1 = 3*b_1*b_1+3*b_1*b_1*b_1
    c3_1 = -6*b_1*b_1-3*b_1-3*b_1*b_1*b_1
    c4_1 = 1+3*b_1+b_1*b_1*b_1+3*b_1*b_1
    nT3Average_1 = c1_1 * xe6_1 + c2_1 * xe5_1 + c3_1 * xe4_1 + c4_1 * xe3_1
    
maShortTermXtrender = t3( shortTermXtrender , 5 )

colShortTermXtrender = maShortTermXtrender > maShortTermXtrender[1] ? color.lime : color.red
plot(maShortTermXtrender, color=#000000             , style=plot.style_line, linewidth=5, title="B-Xtrender Shadow")
plot(maShortTermXtrender, color=colShortTermXtrender, style=plot.style_line, linewidth=3, title="B-Xtrender Color ")

plotshape(maShortTermXtrender > maShortTermXtrender[1] and maShortTermXtrender[1] < maShortTermXtrender[2] ? maShortTermXtrender : na, location=location.absolute, style=shape.circle, color=color.lime, size=size.tiny, transp=10)
plotshape(maShortTermXtrender < maShortTermXtrender[1] and maShortTermXtrender[1] > maShortTermXtrender[2] ? maShortTermXtrender : na, location=location.absolute, style=shape.circle, color=color.red , size=size.tiny, transp=10)

longXtrenderCol   = longTermXtrender> 0 ? longTermXtrender > longTermXtrender[1] ? color.lime : #228B22 : longTermXtrender > longTermXtrender[1] ? color.red : #8B0000
macollongXtrenderCol =  longTermXtrender > longTermXtrender[1] ? color.lime : color.red
plot(longTermXtrender , color=longXtrenderCol, style=plot.style_histogram, linewidth=2, title="B-Xtrender Trend - Histogram", transp = 80)

plot(longTermXtrender , color=#000000             , style=plot.style_line, linewidth=5, title="B-Xtrender Trend - Line", transp = 80)
plot(longTermXtrender , color=macollongXtrenderCol, style=plot.style_line, linewidth=3, title="B-Xtrender Trend - Line", transp = 80)
 
Thread starter Similar threads Forum Replies Date
G Sharp the Slope of the SPY indicator? Questions 1
B Adhara AI Indicator Questions 3
C NOPE Indicator Playground 3
T SFI Indicator - Buy/Sell Signal for Forex Trading Questions 5
germanburrito GANN Square Of 9 Indicator for ThinkorSwim Indicators 86

Similar threads

Top