Directional Trend Index For ThinkOrSwim

mbarcala

Active member
Another nice indicator converted from TradingView to TOS, Enjoy!
Original Link: https://www.tradingview.com/script/CCo7yIeS-Directional-Trend-Index-DTI/

Photo
https%3A//i.imgur.com/43Z86rM.png[/img]']
43Z86rM.png


script
Code:
# Directional Trend Index - DTI converted from TradingView by mbarcala
# Original Link: https://www.tradingview.com/script/CCo7yIeS-Directional-Trend-Index-DTI/

declare lower;

input r = 5;
input s = 20;
input u = 5;

def xHMU = if(high - high[1] > 0, high - high[1], 0);
def xLMD = if(low - low[1] < 0, -(low - low[1]), 0);
def xPrice = xHMU - xLMD;
def xPriceAbs = AbsValue(xPrice);
def xuXA = ExpAverage(ExpAverage(ExpAverage(xPrice, r),s),u);
def xuXAAbs = ExpAverage(ExpAverage(ExpAverage(xPriceAbs, r),s),u);
def Val1 = 100 * xuXA;
def Val2 = xuXAAbs;

plot DTI = if(Val2 != 0, Val1 / Val2, 0);
DTI.SetDefaultColor(Color.LIME);
DTI.SetLineWeight(2);


plot hline = 0;
hline.SetDefaultColor(Color.DARK_GRAY);

plot OB = 25;
OB.SetDefaultColor(Color.BLUE);

plot OS = -25;
OS.SetDefaultColor(Color.RED);
 
Another nice indicator converted from TradingView to TOS, Enjoy!
rrW2gM2.png


Code:
# Directional Trend Index - DTI converted from TradingView by mbarcala
# Original Link: https://www.tradingview.com/script/CCo7yIeS-Directional-Trend-Index-DTI/

declare lower;

input r = 5;
input s = 20;
input u = 5;
input SigLength = 3;
input arrows = 0;
input dotsize = 3;
input APC = 0;
def xHMU = if(high - high[1] > 0, high - high[1], 0);
def xLMD = if(low - low[1] < 0, -(low - low[1]), 0);
def xPrice = xHMU - xLMD;
def xPriceAbs = AbsValue(xPrice);
def xuXA = ExpAverage(ExpAverage(ExpAverage(xPrice, r),s),u);
def xuXAAbs = ExpAverage(ExpAverage(ExpAverage(xPriceAbs, r),s),u);
def Val1 = 100 * xuXA;
def Val2 = xuXAAbs;
plot DTI = if(Val2 != 0, Val1 / Val2, 0);

DTI.setdefaultColor(Color.Cyan);
DTI.SetLineWeight(2);
DTI.HideBubble();
Plot Signal = ExpAverage(DTI,Siglength);
Signal.SetdefaultColor(Color.Magenta);
signal.SetLineWeight(2);
plot cline = 0;
cline.SetDefaultColor(Color.GRAY);
AddCloud(DTI,Signal,Color.Cyan,Color.Magenta);
def Mmax= Max(DTI,Signal);
def MMin= Min(DTI,Signal);
AddCloud(MMin,0,Color.green,Color.Black);
AddCloud(Mmax,0,Color.Black,Color.Red);
Def Con1 = DTI >= 0;
Def Con2 = DTI < 0;
Def Con3 = DTI > DTI [1];
Def Con4 = DTI < DTI[1];

Plot BullRise = If Con1 and Con3 then MMin else 0;
BullRise.SetPaintingStrategy(PaintingStrategy.Histogram);
BullRise.SetDefaultColor(Color.Green);
BullRise.SetLineWeight(3);
Plot BullFall = if Con1 and Con4 then MMin else 0;
BullFall.SetPaintingStrategy(PaintingStrategy.Histogram);
BullFall.SetDefaultColor(Color.Dark_Green);
BullFall.SetLineWeight(3);
Plot BearFall = if Con2 and Con4 then MMax else 0;
BearFall.SetPaintingStrategy(PaintingStrategy.Histogram);
BearFall.SetDefaultColor(Color.Dark_Red);
BearFall.SetLineWeight(3);
Plot BearRise = if Con2 and Con3 then Mmax else 0;
BearRise.SetPaintingStrategy(PaintingStrategy.Histogram);
BearRise.SetDefaultColor(Color.Red);
BEarRise.SetLineWeight(3);

Plot UZ = Average(DTI,34) + (1.3185*StDev(DTI,34));
UZ.SetPaintingStrategy(PaintingStrategy.Line);
UZ.SetLineWeight(2);
UZ.SetDefaultColor(Color.Yellow);
Plot LZ = Average(DTI,34) - (1.3185*StDev(DTI,34));
LZ.SetPaintingStrategy(PaintingStrategy.Line);
LZ.SetLineWeight(2);
LZ.SetDefaultColor(Color.Yellow);
plot OB = 25;
OB.SetDefaultColor(Color.BLUE);

plot OS = -25;
OS.SetDefaultColor(Color.RED);


#ARROWS
plot ArrowDown = if arrows and (DTI Crosses below Signal) then Signal else double.nan;
ArrowDown.setpaintingStrategy(paintingStrategy.Arrow_Down);
ArrowDown.setDefaultColor(color.Magenta);
ArrowDown.setLineWeight(dotsize);

plot ArrowUp = if arrows and (DTI crosses above Signal) then signal else double.nan;
ArrowUp.setpaintingStrategy(paintingStrategy.Arrow_Up);
ArrowUp.setDefaultColor(color.Cyan);
ArrowUp.setLineWeight(dotsize);

plot ArrowDown2 = if arrows and (DTI Crosses below 0) then 0 else double.nan;
ArrowDown2.setpaintingStrategy(paintingStrategy.Arrow_Down);
ArrowDown2.setDefaultColor(color.Red);
ArrowDown2.setLineWeight(dotsize);

plot ArrowUp2 = if arrows and (DTI crosses above 0 ) then 0 else double.nan;
ArrowUp2.setpaintingStrategy(paintingStrategy.Arrow_Up);
ArrowUp2.setDefaultColor(color.Blue);
ArrowUp2.setLineWeight(dotsize);

plot ArrowDown3 = if arrows and (DTI Crosses below UZ) then UZ else double.nan;
ArrowDown3.setpaintingStrategy(paintingStrategy.Arrow_Down);
ArrowDown3.setDefaultColor(color.Yellow);
ArrowDown3.setLineWeight(dotsize);

plot ArrowUp3 = if arrows and (DTI crosses above LZ ) then LZ else double.nan;
ArrowUp3.setpaintingStrategy(paintingStrategy.Arrow_Up);
ArrowUp3.setDefaultColor(color.Yellow);
ArrowUp3.setLineWeight(dotsize);

plot ArrowDown4 = if arrows and (DTI Crosses below OB) then OB else double.nan;
ArrowDown4.setpaintingStrategy(paintingStrategy.Arrow_Down);
ArrowDown4.setDefaultColor(color.Blue);
ArrowDown4.setLineWeight(dotsize);

plot ArrowUp4 = if arrows and (DTI crosses above OS ) then OS else double.nan;
ArrowUp4.setpaintingStrategy(paintingStrategy.Arrow_Up);
ArrowUp4.setDefaultColor(color.Red);
ArrowUp4.setLineWeight(dotsize);


AssignPriceColor( if APC ==1 and DTI >= signal then Color.Cyan else if APC == 1 and DTI < Signal then Color.Magenta else If APC ==2 and DTI >=0 then Color.Green else If APC ==2 and DTI <0 then Color.Red else Color.Current);
 
Last edited by a moderator:

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
397 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