Trend Direction Indicator for ThinkorSwim

Pensar

Expert
VIP
This is a simple indicator that displays trend by using new 1, 3, and 6 month highs. When all three are in confluence, a bar at the bottom of the chart is colored based on the direction taken. I've found it quite helpful to create directional awareness for the trend of a stock.

. . . and for all the GME traders . . . .

Code:
``````# Trend Direction Indicator
# Displays trend based on new 1, 3, and 6 month highs or lows
# Pensar - V.1.0 - 02.26.2021 - Initial Release

def H = high(period = AggregationPeriod.Month);
def L = low(period = AggregationPeriod.Month);

plot "6 Month High" = Highest(H, 6);
plot "6 Month Low" = Lowest(L, 6);
plot "3 Month High" = Highest(H, 3);
plot "3 Month Low" = Lowest(L, 3);
plot "1 Month High" = Highest(H, 1);
plot "1 Month Low" = Lowest(L, 1);

def T6 = if close < "6 Month Low"[20] then -1 else if high > "6 Month High"[20] then 1 else T6[1];
def T3 = if close < "3 Month Low"[20] then -1 else if high > "3 Month High"[20] then 1 else T3[1];
def T1 = if close < "1 Month Low"[20] then -1 else if high > "1 Month High"[20] then 1 else T1[1];

"6 Month High".AssignValueColor(if T6 == 1 then Color.cyan else Color.magenta);
"6 Month High".setstyle(curve.short_dash);
"6 Month Low".AssignValueColor(if T6 == 1 then Color.cyan else Color.magenta);
"6 Month Low".setstyle(curve.short_dash);
"3 Month High".AssignValueColor(if T3 == 1 then Color.cyan else Color.magenta);
"3 Month High".setstyle(curve.short_dash);
"3 Month Low".AssignValueColor(if T3 == 1 then Color.cyan else Color.magenta);
"3 Month Low".setstyle(curve.short_dash);
"1 Month High".AssignValueColor(if T1 == 1 then Color.cyan else Color.magenta);
"1 Month High".setstyle(curve.short_dash);
"1 Month Low".AssignValueColor(if T1 == 1 then Color.cyan else Color.magenta);
"1 Month Low".setstyle(curve.short_dash);

plot Trend_Bar = if T1 then LowestAll(low) else double.nan;
Trend_Bar.SetPaintingStrategy(PaintingStrategy.LINE);
Trend_Bar.AssignValueColor(if (T1 == 1 and T3 == 1 and T6 == 1) then Color.cyan
else if (T1 == -1 and T3 == -1 and T6 == -1) then Color.magenta
else color.gray);
Trend_Bar.SetLineWeight(5);

# end code``````

Nice thanks!

Not the exact question you're looking for?

87k+ Posts
298 Online

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?