Trend Direction Indicator for ThinkorSwim

Pensar

Well-known member
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.

Screenshot-2021-02-26-101239.png


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

Screenshot-2021-02-26-100738.png


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
 

Similar threads

Top