Trend Momentum Divergence Indicator for ThinkorSwim

BenTen

Administrative
Staff member
Staff
VIP
ubgTzu2.png


thinkScript Code

Rich (BB code):
#That will show mostly price within it's range compared to the indicator within it's range. Since the indicator is bound and price is free to run at any angle it please for as long is it damn well likes, it more or less will only allow you too see price against your indicator. If I was going to trade it on shorter timeframes, I would use this version

#

# Yet Another Divergence Script - Trend Momentum Divergence

# Nube 6.5.18

#hint: Usess linear of price scaled to RSI as an indicator of trend

declare lower;

input Length     = 14;

input OverBought = 70;

input OverSold   = 30;

input Cloud      = yes;

def na = Double.NaN;

def indicator  = RSI(Length = length);

script scale {

    input c = 0;

    input Min = 0;

    input Max = 1;

    def hh = HighestAll(c);

    def ll = LowestAll(c);

    plot Range = (((Max - Min) * (c - ll)) /  (hh - ll)) + Min;

}

def sPrice = scale(close, Lowest(indicator, length), Highest(indicator, length));

plot 

OB  = if !IsNaN(close) then OverBought else na;

OB.SetDefaultColor(Color.Light_Red);

plot 

OS  = if !IsNaN(close) then OverSold else na;

OS.SetDefaultColor(Color.Light_Green);

plot 

RSI = indicator;

RSI.DefineColor("Over Bought", Color.Red);

RSI.DefineColor("Over Sold", Color.Green);

RSI.DefineColor("Typical", Color.White);

RSI.AssignValueColor(

if    RSI > OB 

then  RSI.color("Over Bought") 

else  if   RSI < overSold 

      then RSI.color("Over Sold") 

      else RSI.color("Typical")

);

plot 

priceTrend = Inertia(sPrice, length);

priceTrend.DefineColor("Price Trend Down", CreateColor(150,50,50));

priceTrend.DefineColor("Price Trend Up", CreateColor(50,150,50));

priceTrend.AssignValueColor(if   priceTrend < priceTrend[1]

                            then priceTrend.Color("Price Trend Down")

                            else priceTrend.Color("Price Trend Up"));

addCloud(if (cloud,rsi,na), priceTrend, 

CreateColor(50,150,50), CreateColor(150,50,50));

# f/ Trend Momentum Divergence

Shareable Link

https://tos.mx/qKnSH4
 
Last edited:

MerryDay

Administrative
Staff member
Staff
VIP
@Shrum
The Trend Momentum is a bound oscillator. Oscillator refers to the movement up over the midline (positive) or down (negative). Bounded refers to the upper and lower limits of the oscillator: Overbought is the upper red line, Oversold, is the lower green line. When the plot crosses above oversold, the bullish trend is beginning. When the plot crosses below overbought, it is ending.
 
Last edited:

Shrum

Member
Thank you @MerryDay , I guess I should have asked my question a little differently - I know one line is basically RSI and I am curious as to what the other line is measuring? Does that make sense? Thanks
 

MerryDay

Administrative
Staff member
Staff
VIP
@Shrum The faint red/green oscillating plot is the RSI. The bold white plot is the Trend Momentum line. It is calculated with the Inertia function.
This particular inertia plot is the linear regression curve of the RSI using the least-square approximation method.

Here is a thread that discusses the definition of inertia. You can use the search box to get dozens of other examples of its use.
https://usethinkscript.com/threads/what-is-inertia-and-inertiaall-from-linear-regression.1355/
 

Similar threads

Top