SD_TrendAction For ThinkOrSwim [Updated: 5/14/2023]

SteveDay

Member
Plus

SD_TrendAction v1.0.1

Initiated: [2023/04/19]
Revised: [2023/05/12] (v1.0.1)


Created by Steve Day
(User ID: steveday72 on UseThinkScript.com)

TLDR:
SD_TrendAction uses colors to display the bar trend & strength, based on averages of price & volume.
Each bar's trend is determined by comparing the current price (default HLC3) to the moving average of the previous "Rolling-Window Synthetic-Composite Bars" (Synthetic HLC3/HL2/OHLC4, instead of time-period based composite bars). (default is HL2). While the bar's trend strength is determined by comparing the current volume to the moving average of the previous bar's volume.
Moving average type can be selected (default is Exponential/EMA).
Length of the Moving Average / "Rolling-Window Synthetic-Composite" (shared value) is adjustable.


DISCLAIMERS:
No guarantees are given as to the effectiveness of this indicator - USE AT YOUR OWN RISK. TRADE WITH YOUR OWN DUE-DILIGENCE!​

DESCRIPTION:
"[SD] Trend Action" is similar to Bill Williams' Fade/Squat Bars, at least in naming convention & appearance (ie: bar trend colors).

It's purpose is to help determine when a trend is on a strong path upwards/downwards, or if the volume is not supporting the move up/down.

Where it differs is that it does not use an oscillator like Williams' indicator, but instead compares the current price & volume against averages of the previous bars.

Also, instead of using HLC3/HL2/OHLC4 bars with regular Aggregation Periods, I use synthetic HLC3/HL2/OHLC4 bars. These synthetic bars are created using a rolling window, thereby removing the often "clunky" pattern found when using AggregationPeriod based HLC3/HL2/OHLC4 bars.

It seems to give better results than either eMini-Watch's "Better Volume" or Bill Williams' Squat/Fade/Fake bars.

Good luck

Colors:
Strong trend up ("Green" - Colored Green) is when both price and volume are higher than average. (Volume supports the move up).​
Weak trend up ("Squat" - Colored Blue) is a when the price is higher, but the volume is lower. (Volume doesn't support the move up).​
Strong trend down ("Fade" - Colored Red) is when the price is lower and the volume is higher. (Volume supports the move down).​
Weak trend down ("Fake" - Colored Orange) is when both price and volume are lower. (Volume doesn't support the move down).​
In the rare event that a bar doesn't meet any of those conditions (price or volume is unchanged compared to their averages), then the bar is "Neutral" and colored Gray.​

Shared Study: http://tos.mx/HgaXPqd (v1.0.1)
Thumbnail: v1.0.1
OR48CYm.png


Code:
#//# SD_TrendAction v1.0.1
#==# =====================
#//# Initiated: [2023/04/19]
#//# Revised: [2023/05/12]
#//# Created by Steve Day (User ID: steveday72 on UseThinkScript.com)
#//# Contact: steve (at) steveday (dot) com
#!!# May not be sold or paywalled without my express permission.
#!!# All distributions, translations, or modified derivatives, must include the entirety of this text.

#!!# DISCLAIMERS:
#!!# No guarantees are given as to the effectiveness of this indicator - USE AT YOUR OWN RISK. TRADE WITH YOUR OWN DUE-DILIGENCE!

#..# DESCRIPTION:
#..# "[SD] Trend Action" is similar to Bill Williams' Fade/Squat Bars, at least in naming convention & look.
#..# It is designed to help me (and anyone else) determine when to get out of trends.
#..#
#..# Where it differs is that it does not use an oscillator, but instead uses moving averages to compare the price action.
#..# Also, instead of using bars with different Aggregation Periods, I use synthetic composite bars,
#..# - which create rolling window composite bars, instead of the often "clunky" action found with period based composite bars.
#..#
#..# It appears to give far better results than either eMini-Watch's "Better Volume" or Bill Williams' Squat/Fade/Fake bars.
#..#
#..# Good luck

#==# Changes:
#### [2023/05/12] v1.0.1 - Minor color change to make Blue more visible (balanced brightness).

input enable = yes;
input p_now = { "CLOSE", default "HLC3", "HL2", "OHLC4" };
input p_then = { "CLOSE", "HLC3", default "HL2", "OHLC4" };
input avgLen = 5;
input avgType = AverageType.EXPONENTIAL;



#//# Select the next higher AggregationPeriod.. (From: 1min, 5min, 15min, 1hour, 4hours, 1day, 1week, 1month, 1year)
def cap = GetAggregationPeriod();
def nap =
    if cap < AggregationPeriod.MIN then AggregationPeriod.MIN
    else if cap < AggregationPeriod.FIVE_MIN then AggregationPeriod.FIVE_MIN
    else if cap < AggregationPeriod.THIRTY_MIN then AggregationPeriod.THIRTY_MIN
    else if cap < AggregationPeriod.HOUR then AggregationPeriod.HOUR
    else if cap < AggregationPeriod.FOUR_HOURS then AggregationPeriod.FOUR_HOURS
    else if cap < AggregationPeriod.DAY then AggregationPeriod.DAY
    else if cap < AggregationPeriod.WEEK then AggregationPeriod.WEEK
    else if cap < AggregationPeriod.MONTH then AggregationPeriod.MONTH
    else if cap < AggregationPeriod.YEAR then AggregationPeriod.YEAR
    else cap;
#//# Make sure a lower Aggregation Period cannot be chosen..
def ap = Max(GetAggregationPeriod(), nap);

#//# Rolling Composite (HL2/HLC3/etc) Bars..
#//# - The goal of these is to avoid the "clunkiness" that regular Composite bars have within comparisons
def rnap = nap / cap;    ## Ratio of Next AggregationPeriod
def ravgLen = avgLen;# * rnap;  ## Use "avgLen * rnap" if you want the rolling window to have AggregationPeriod-like lengths
def hh = Highest(HIGH, rnap);
def ll = Lowest(LOW, rnap);
def rHL2 = (hh + ll) / 2;
def rHLC3 = (hh + ll + CLOSE) / 3;
def rOHLC4 = (OPEN[avgLen] + hh + ll + CLOSE) / 4;

def p1;
switch(p_now) {
case "CLOSE":
    p1 = CLOSE;
case "HLC3":
    p1 = rHLC3;
case "HL2":
    p1 = rHL2;
case "OHLC4":
    p1 = rOHLC4;
}
script getRollingAvg {
    input avgType = AverageType.SIMPLE;
    input source = close;
    input avgLen = 1;
    plot Output = if avgLen == 1 then source[1]
            else MovingAverage(avgType, source, avgLen);
}
def p2;
switch(p_then) {
case "CLOSE":
    p2 = getRollingAvg(avgType, CLOSE , ravgLen);
case "HLC3":
    p2 = getRollingAvg(avgType, rHLC3 , ravgLen);
case "HL2":
    p2 = getRollingAvg(avgType, rHL2 , ravgLen);
case "OHLC4":
    p2 = getRollingAvg(avgType, rOHLC4 , ravgLen);
}
def v1 = VOLUME;
def v2 = getRollingAvg(avgType, VOLUME , ravgLen);

DefineGlobalColor("Green", Color.GREEN);
DefineGlobalColor("Fade",  Color.RED);
DefineGlobalColor("Fake",  Color.ORANGE);
DefineGlobalColor("Squat",  CreateColor(76,165,255));#  Color.BLUE);
DefineGlobalColor("Neutral",  Color.GRAY);

AssignPriceColor(
    if enable == no then Color.CURRENT else
    if p1 > p2 and v1 > v2 then GlobalColor("Green")
    else if p1 < p2 and v1 > v2 then GlobalColor("Fade")
    else if p1 < p2 and v1 < v2 then GlobalColor("Fake")
    else if p1 > p2 and v1 < v2 then GlobalColor("Squat")
    else GlobalColor("Neutral")
);
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Can you give a description of what the colors mean? I'm a newb. Please bare with me.


Colors:
Strong trend up ("Green" - Colored Green) is when both price and volume are higher than average. (Volume supports the move up).​
Weak trend up ("Squat" - Colored Blue) is a when the price is higher, but the volume is lower. (Volume doesn't support the move up).​
Strong trend down ("Fade" - Colored Red) is when the price is lower and the volume is higher. (Volume supports the move down).​
Weak trend down ("Fake" - Colored Orange) is when both price and volume are lower. (Volume doesn't support the move down).​
In the rare event that a bar doesn't meet any of those conditions (price or volume is unchanged compared to their averages), then the bar is "Neutral" and colored Gray.​
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
302 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