Auto Trend Lines Indicator for ThinkorSwim (Free Download)

BenTen

BenTen

Administrative
Staff
VIP
Warehouse
This is a free indicator for ThinkorSwim that will automatically draw trend lines on your trading charts. It works with any timeframes. The indicator includes short, medium, and long length of trend lines.

I found this code while exploring this topic on Research Trade.



thinkScript Code

Rich (BB code):
#
#Trend Line Plot    
#
input TrendLineLength1 = 50;
input TrendLineLength2 = 30;
input TrendLineLength3 = 10;

def Inertia1 = InertiaAll(close, TrendLineLength1);
def Inertia2 = InertiaAll(close, TrendLineLength2);
def Inertia3 = InertiaAll(close, TrendLineLength3);

def TL_Bull1 = Inertia1 - (HighestAll(AbsValue(Inertia1 - close)) * 0.8);
def TL_Bear1 = Inertia1 + (HighestAll(AbsValue(Inertia1 - close)) * 0.8);
def slope1a = TL_Bull1 > TL_Bull1[1];
def slope1b = TL_Bear1 > TL_Bear1[1];

def TL_Bull2 = Inertia2 - (HighestAll(AbsValue(Inertia2 - close)) * 0.8);
def TL_Bear2 = Inertia2 + (HighestAll(AbsValue(Inertia2 - close)) * 0.8);
def slope2a = TL_Bull2 > TL_Bull2[1];
def slope2b = TL_Bear2 > TL_Bear2[1];

def TL_Bull3 = Inertia3 - (HighestAll(AbsValue(Inertia3 - close)) * 0.8);
def TL_Bear3 = Inertia3 + (HighestAll(AbsValue(Inertia3 - close)) * 0.8);
def slope3a = TL_Bull3 > TL_Bull3[1];
def slope3b = TL_Bear3 > TL_Bear3[1];
#Long length
plot TrendLine1a = if slope1a > 0 then TL_Bull1 else TL_Bear1;
TrendLine1a.SetStyle(curve.long_dash);
TrendLine1a.SetLineWeight(1);
TrendLine1a.assignvaluecolor(if slope1a and IsAscending(close, 10) then color.WHITE else if slope1a then color.white else if !IsAscending(close, 10)then color.white else color.WHITE);

plot TrendLine1b = if slope1b > 0 then TL_Bear1 else TL_Bull1;
TrendLine1b.SetStyle(curve.long_dash);
TrendLine1b.SetLineWeight(1);
TrendLine1b.assignvaluecolor(if slope1b and IsAscending(close, 10) then color.white else if slope1b then color.white else if !IsAscending(close, 10)then color.white else color.white);
#Medium length
plot TrendLine2a = if slope2a > 0 then TL_Bull2 else TL_Bear2;
TrendLine2a.SetStyle(curve.medium_dash);
TrendLine2a.SetLineWeight(2);
TrendLine2a.assignvaluecolor(if slope2a and IsAscending(close, 10) then color.yellow else if slope2a then color.yellow else if !IsAscending(close, 10)then color.light_RED else color.light_RED);

plot TrendLine2b = if slope2b > 0 then TL_Bear2 else TL_Bull2;
TrendLine2b.SetStyle(curve.medium_dash);
TrendLine2b.SetLineWeight(2);
TrendLine2b.assignvaluecolor(if slope2b and IsAscending(close, 10) then color.yellow else if slope2b then color.yellow else if !IsAscending(close, 10)then color.light_RED else color.light_RED);
#Short length
plot TrendLine3a = if slope3a > 0 then TL_Bull3 else TL_Bear3;
TrendLine3a.SetStyle(curve.short_dash);
TrendLine3a.SetLineWeight(3);
TrendLine3a.assignvaluecolor(if slope3a and IsAscending(close, 10) then color.yellow else if slope3a then color.yellow else if !IsAscending(close, 10)then color.light_RED else color.light_RED);

plot TrendLine3b = if slope3b > 0 then TL_Bear3 else TL_Bull3;
TrendLine3b.SetStyle(curve.short_dash);
TrendLine3b.SetLineWeight(3);
TrendLine3b.assignvaluecolor(if slope3b and IsAscending(close, 10) then color.yellow else if slope3b then color.yellow else if !IsAscending(close, 10)then color.light_RED else color.light_RED);

Shareable Link

http://tos.mx/2wsFva

Video Tutorial

 
Last edited:
J

john3

Member
VIP
Warehouse
The "E" MAs, does it show when they all simply cross up/down or is there more logic to it? Why is it called an "E?" Thank you.
 
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
@john3 I don’t think this indicator has anything to do with EMAs or the “E” you’re referring to.
 
S

sir

New member
This script is awesome. But it seems to draw lines at the close price. Can you tell me how to draw it at the peaks of the wicks? highs and lows?
thanks
 
G

GetRichOrDieTrying

Member
Is there a way to create a scan for this that populates stocks that are in all trend stages (short, medium, long) at the same time? I would think that this would be a pretty good indication of a bullish stock, especially for day traders and scalpers.
 
G

GetRichOrDieTrying

Member
Is there a way to create a scan for this that populates stocks that are in all trend stages (short, medium, long) at the same time? I would think that this would be a pretty good indication of a bullish stock, especially for day traders and scalpers.
I should also add, that if you can't configure a scan to find stocks that are in an uptrend for all three stages, two out of the three at the same time would also suffice - since finding stocks that are in an uptrend in all three stages won't happen often.
 
G

GetRichOrDieTrying

Member
Is there a way to adjust the long term trendline to look for the swing lows with the most amount of touches going back X periods. As an example, I'd like it to trail the last 50, 100, or 300 1M Candles.
 
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
@GetRichOrDieTrying try adjusting the inputs: 50, 30, and 10.
 
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
@GetRichOrDieTrying The length of the trendline.
 
M

monkey dolphin

New member
Is there a way to plot an arrow every time the slope of one of the trendlines changes from negative to positive?
 
G

GetRichOrDieTrying

Member
@BenTen Is there a way to create a scan to populate results like the image below? If this is possible, this would be a great scan for spotting high probability pullback entries.

Criteria:
  1. The 50 and 30 lines are in an uptrend
  2. The 50 and 30 lines are parallel to each other
  3. The lower 10 lines are in a downtrend

 

Top