Market Phases Indicator for ThinkorSwim

M654aei.png
 
Absolutely Amazing so far

am I wrong in assuming that as long as the longer time frames are bullish the others don't matter so much? Is there a better way to utilize this tool than that? This may be petty but I wish I could reorder the timeframes so they appear in order, left to right.
 
This is a great study. I have been using it for the last week and really like the results. I do have a question. I have been doing more reseach on the trend advisor. I have also located a manual on this system. There are two other studies with this system. Both appear to be oscillators. One is Market Phase and the other is -acuTRADE Osc. Does anyone have either of these studies?

I have also updated the code for the candles to match the label of what market phase the candles are in.

input colorbars = yes;
assignPriceColor(if colorbars and bullphase then Color.GREEN else if accphase is true then Color.LIGHT_GREEN else if recphase is true then Color.LIGHT_ORANGE else if warnphase is true then Color.ORANGE else if distphase is true then Color.light_red else if bearphase then Color.RED else Color.current);
 
Last edited:
Greetings,

The Market Phases indicator is based off of Chuck Dukas Trend Advisor model of identifying what phase a stock is in. Whether is is bullish, bearish, accumulation, distribution etc. I have attached an image below so you can see. With this indicator, you can scan for stocks in all six phases as well as pullbacks to a fast user chosen ema if a stock is under a bullish or bearish phase. I have included a watchlist column so you can use to your liking. Hope this helps.


Please note: On the chart indicator, when you load it, uncheck the show plots for buphase, acphase, rephase, bephase, dphase, wphase. These mess up the chart sizing. If someone knows how to turn those off by default then please do so. Thank you.

TrendAdvisor%2BDiamond.png



Main Indicator Below

Rich (BB code):
#Trend Advisor Market Phases;

#Credit to the Chuck Dukas for creating the system and for then author of the VolumeTrendLabels whose study was use to create this indicator. Ensure you set the correct aggregation period to then chart, this helps calculate the correct volume and price action.

def agg = getAggregationPeriod();
input vPeriod = getAggregationPeriod(); #hint vPeriod: Grabs aggregation period from current chart.

def O = open(period = vPeriod);
def H = high(period = vPeriod);
def C = close(period = vPeriod);
def L = low(period = vPeriod);
def V = volume(period = vPeriod);

def SV = V * (H - C) / (H - L);
def BV = V * (C - L) / (H - L);

# below determines if volume supports the move, adds conviction

AddLabel(yes, "Buyer Vol Strong ", if high > high[1] and low > low[1] and BV*1.05 > SV then Color.GREEN else color.black);

AddLabel(yes, "Seller Vol Strong", if high < high[1] and low < low[1] and SV*1.05 > BV then Color.MAGENTA else color.black);

# below determines if price supports the move

AddLabel(yes, "Price Strong ", if high > high[1] and high [1] > high[2] and low > low[1] and low[1] > low[2] then Color.GREEN else color.black);

AddLabel(yes, "Price Weak", if high < high[1] and high[1] < high[2] and low < low[1] and low[1] < low[2] then Color.MAGENTA else color.black);





declare upper;
input price = close;
input displace = 0;

input avglength = 10; #hint avgLength: Then exponential average length you want to use for your pullback entries.

def fastavg = 50;
def slowavg = 200;


plot fastsma = Average( price, fastavg);
fastsma.SetDefaultColor(Color.Green);

plot slowsma = Average(price, slowavg);
slowsma.SetDefaultColor(Color.Red);

# Bullish criteria define below

# Define criteria for Bullish Phase : close > 50 SMA, close > 200 SMA, 50 SMA > 200 SMA

def bullphase = fastsma > slowsma && price > fastsma && price > slowsma;

# Define criteria for Accumulation Phase : close > 50 SMA, close > 200 SMA, 50 SMA < 200 SMA

def accphase = fastsma < slowsma && price > fastsma && price > slowsma;

# Define criteria for Recovery Phase : close > 50 SMA, close < 200 SMA, 50 SMA < 200 SMA

def recphase = fastsma < slowsma && price < slowsma && price > fastsma;



# Bearish Criteria define below

# Define criteria for Bearish Phase : close < 50 SMA, close < 200 SMA, 50 SMA < 200 SMA

def bearphase = fastsma < slowsma && price < fastsma && price < slowsma;

# Define criteria for Distribution Phase : close < 50 SMA, close < 200 SMA, 50 SMA > 200 SMA

def distphase = fastsma > slowsma && price < fastsma && price < slowsma;

# Define criteria for Warning Phase : close < 50 SMA, close > 200 SMA, 50 SMA > 200 SMA

def warnphase = fastsma > slowsma && price > slowsma && price < fastsma;


# Below conditions are for a possible entry when price touches the fastema

#def pbavg = MovingAverage(Average, price, avglength);

def pbavg = ExpAverage(data = price[-displace], length = avglength);

input bullpullback = yes;  #hint bullpullback: Do you want to display the pullback arrows for bullish fast ema entries.
input bearpullback = yes; #hint bearpullback: Do you want to display the pullback arrows for bearish fast ema entries.

def bullishpb = low < pbavg && open > pbavg;
def bearishpb = high > pbavg && open < pbavg;

def bullpb = bullphase is true && bullishpb is true;
def bearpb = bearphase is true && bearishpb is true;

# Plot Signals
plot bullpb1 = if bullpullback then bullpb else 0;
bullpb1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullpb1.SetDefaultColor(Color.CYAN);
bullpb1.SetLineWeight(1);

plot bearpb1 = if bearpullback then bearpb else 0;
bearpb1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bearpb1.SetDefaultColor(Color.red);
bearpb1.SetLineWeight(1);



plot buphase = bullphase is true;
plot acphase = accphase is true;
plot rephase = recphase is true;

plot bephase = bearphase is true;
plot dphase = distphase is true;
plot wphase = warnphase is true;


# Below adds labels to the chart to identify what phase the underlying is in


AddLabel(bullphase, " Bull Phase" , if bullphase is true then Color.GREEN else Color.BLACK);

AddLabel(accphase, " Accumation Phase ", if accphase is true then Color.lIGHT_GREEN else Color.BLACK);

AddLabel(recphase, " Recovery Phase ", if recphase is true then Color.lIGHT_ORANGE else Color.BLACK);

AddLabel(warnphase, " Warning Phase ", if warnphase is true then Color.orANGE else Color.BLACK);

AddLabel(distphase, " Distribution Phase ", if distphase is true then Color.light_red else Color.BLACK);

AddLabel(bearphase, " Bear Phase ", if bearphase is true then Color.red else Color.BLACK);


input colorbars = yes;
assignPriceColor(if colorbars and bullphase then Color.GREEN else if bearphase then Color.RED else Color.orange);

Alert(condition = bullphase[1] == 1 and bullphase == 0, text = "Bull Phase", sound = Sound.Bell, "alert type" = Alert.BAR);
Alert(condition = accphase[1] == 1 and accphase == 0, text = "Accumation Phase", sound = Sound.Bell, "alert type" = Alert.BAR);
Alert(condition = recphase[1] == 1 and recphase == 0, text = "Recovery Phase", sound = Sound.Bell, "alert type" = Alert.BAR);
Alert(condition = warnphase[1] == 1 and warnphase == 0, text = "Warning Phase", sound = Sound.Bell, "alert type" = Alert.BAR);
Alert(condition = distphase[1] == 1 and distphase == 0, text = "Distribution Phase", sound = Sound.Bell, "alert type" = Alert.BAR);
Alert(condition = bearphase[1] == 1 and bearphase == 0, text = "Bear Phase", sound = Sound.Bell, "alert type" = Alert.BAR);

Below is the watchlist column.

Updated Watchlist Column

Thanks for sharing. Here is the updated code that unplot the phases by default.

Code:
#Trend Advisor Market Phases;

#Credit to the Chuck Dukas for creating the system and for then author of the VolumeTrendLabels whose study was use to create this indicator. Ensure you set the correct aggregation period to then chart, this helps calculate the correct volume and price action.

def agg = getAggregationPeriod();
input vPeriod = AggregationPeriod.HOUR; #hint vPeriod: Enter the chart time you use here. Required to properly caluclate volume and price strength.

def O = open(period = vPeriod);
def H = high(period = vPeriod);
def C = close(period = vPeriod);
def L = low(period = vPeriod);
def V = volume(period = vPeriod);

def SV = V * (H - C) / (H - L);
def BV = V * (C - L) / (H - L);

# below determines if volume supports the move, adds conviction

AddLabel(yes, "Buyer Vol Strong ", if high > high[1] and low > low[1] and BV*1.05 > SV then Color.GREEN else color.black);

AddLabel(yes, "Seller Vol Strong", if high < high[1] and low < low[1] and SV*1.05 > BV then Color.MAGENTA else color.black);

# below determines if price supports the move

AddLabel(yes, "Price Strong ", if high > high[1] and high [1] > high[2] and low > low[1] and low[1] > low[2] then Color.GREEN else color.black);

AddLabel(yes, "Price Weak", if high < high[1] and high[1] < high[2] and low < low[1] and low[1] < low[2] then Color.MAGENTA else color.black);

declare upper;
input price = close;
input displace = 0;

input avglength = 10; #hint avgLength: Then exponential average length you want to use for your pullback entries.

def fastavg = 50;
def slowavg = 200;


plot fastsma = Average( price, fastavg);
fastsma.SetDefaultColor(Color.Green);

plot slowsma = Average(price, slowavg);
slowsma.SetDefaultColor(Color.Red);

# Bullish criteria define below

# Define criteria for Bullish Phase : close > 50 SMA, close > 200 SMA, 50 SMA > 200 SMA

def bullphase = fastsma > slowsma && price > fastsma && price > slowsma;

# Define criteria for Accumulation Phase : close > 50 SMA, close > 200 SMA, 50 SMA < 200 SMA

def accphase = fastsma < slowsma && price > fastsma && price > slowsma;

# Define criteria for Recovery Phase : close > 50 SMA, close < 200 SMA, 50 SMA < 200 SMA

def recphase = fastsma < slowsma && price < slowsma && price > fastsma;



# Bearish Criteria define below

# Define criteria for Bearish Phase : close < 50 SMA, close < 200 SMA, 50 SMA < 200 SMA

def bearphase = fastsma < slowsma && price < fastsma && price < slowsma;

# Define criteria for Distribution Phase : close < 50 SMA, close < 200 SMA, 50 SMA > 200 SMA

def distphase = fastsma > slowsma && price < fastsma && price < slowsma;

# Define criteria for Warning Phase : close < 50 SMA, close > 200 SMA, 50 SMA > 200 SMA

def warnphase = fastsma > slowsma && price > slowsma && price < fastsma;


# Below conditions are for a possible entry when price touches the fastema

#def pbavg = MovingAverage(Average, price, avglength);

def pbavg = ExpAverage(data = price[-displace], length = avglength);

input bullpullback = yes;  #hint bullpullback: Do you want to display the pullback arrows for bullish fast ema entries.
input bearpullback = yes; #hint bearpullback: Do you want to display the pullback arrows for bearish fast ema entries.

def bullishpb = low < pbavg && open > pbavg;
def bearishpb = high > pbavg && open < pbavg;

def bullpb = bullphase is true && bullishpb is true;
def bearpb = bearphase is true && bearishpb is true;

# Plot Signals
plot bullpb1 = if bullpullback then bullpb else 0;
bullpb1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullpb1.SetDefaultColor(Color.CYAN);
bullpb1.SetLineWeight(1);

plot bearpb1 = if bearpullback then bearpb else 0;
bearpb1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bearpb1.SetDefaultColor(Color.red);
bearpb1.SetLineWeight(1);



#plot buphase = bullphase is true;
#plot acphase = accphase is true;
#plot rephase = recphase is true;

#plot bephase = bearphase is true;
#plot dphase = distphase is true;
#plot wphase = warnphase is true;


# Below adds labels to the chart to identify what phase the underlying is in


AddLabel(bullphase, " Bull Phase" , if bullphase is true then Color.GREEN else Color.BLACK);

AddLabel(accphase, " Accumation Phase ", if accphase is true then Color.lIGHT_GREEN else Color.BLACK);

AddLabel(recphase, " Recovery Phase ", if recphase is true then Color.lIGHT_ORANGE else Color.BLACK);

AddLabel(warnphase, " Warning Phase ", if warnphase is true then Color.orANGE else Color.BLACK);

AddLabel(distphase, " Distribution Phase ", if distphase is true then Color.light_red else Color.BLACK);

AddLabel(bearphase, " Bear Phase ", if bearphase is true then Color.red else Color.BLACK);


assignPriceColor(if bullphase then Color.GREEN else if bearphase then Color.RED else Color.orange);
Hi Ben, I read somewhere in this thread that if the Study Agg period is set to HOUR that the time frame on the chart can be changed to anything lower than HOUR and the phases indicated will be correct -- is this CORRECT?? Thx ~
 
Hi Ben, I read somewhere in this thread that if the Study Agg period is set to HOUR that the time frame on the chart can be changed to anything lower than HOUR and the phases indicated will be correct -- is this CORRECT?? Thx ~
yes
 
Hi Ben, I read somewhere in this thread that if the Study Agg period is set to HOUR that the time frame on the chart can be changed to anything lower than HOUR and the phases indicated will be correct -- is this CORRECT?? Thx ~
This indicator maybe best suited to longer time frames, which confirm trend. If you are trading long in a bear, may not be the best direction?
 
As a follow-up to the example on CSCO

iULodF4.png


It's now enter a Bull Phase on the 5M, Recovery on the 1H, might make a good candidate for a short term trade.

Build and a system and share your ideas. Let us know how you plan to trade it ;)
@diazlaz, @Billions did anyone figure out a system yet as to how to use this advantageously?

Also if anyone wants, here is a PDF copy of the book by Chuck Dukas "TRENDADVISOR GUIDE TO BREAKTHROUGH PROFITS" on my google drive.

https://tinyurl.com/yc8dnhhj
 
Last edited:
Thanks for this Indicator, Scan, WL - it's pretty slick.

I'm not a coding guru but a dabbler. Since I like to preserve my columns and not waste them on MTF, I was wondering if the phase column could include a count of how many bars back the phase has been in? I have Keltner Channel column which does this on my WL. I set it to 5min, so a 2 would say the indicator fired 10mins ago. I suspect this portion (count1, count2) does the count and it'll have to be applied to all the different phase sections, assuming it was preceding the label header:

Code:
# Momentum Keltner Channels Watchlist Column
# Based on the FW_MOBO code by TOS user davidinc (aka Firstwave, aka David Elliott)
# The count displayed in the watchlist shows the number of bars since a break up or break down

input length       =     34;
input factor       =     0.5;
input displace     =     0;
input price        =     close;
input type         =     AverageType.EXPONENTIAL;

def nan      =   double.nan;
def shift    =   factor * MovingAverage(type, TrueRange(high, close, low), length);
def avg      =   MovingAverage(type, price, length);
def line1    =   avg[-displace] - shift[-displace];
def line2    =   avg[-displace] + shift[-displace];
def Chg      =   if(close > line2, 1, if(close < line1, -1, 0));
def Hold     =   CompoundValue(1,if(Hold[1] == Chg or Chg == 0, Hold[1], if(Chg == 1, 1, -1)), 0);

def n1 = Hold[0] == 1;
def n2 = Hold[0] == -1;
def count1 = if n1 and !n1[1] then 1 else count1[1]+1;
def count2 = if n2 and !n2[1] then 1 else count2[1]+1;

plot n = if n1 then count1 else if n2 then count2 else double.nan;
     n.setdefaultcolor(color.black);
 assignbackgroundcolor(if n1 and count1 then color.green else color.red);

#AddLabel(yes, if n1 then "👍" else if n2 then "👎" else " ", if n2 then Color.red else if n1 then Color.green else Color.black);
#AssignBackgroundColor(color.black);
#End of code
 
Is It possible to stop changes in bar color, if I want to keep the default candle colors? Choosing "colorbars "NO" in Customizing Makes all Bars Orange.
 
Last edited:
Is It possible to stop changes in bar color, if I want to keep the default candle colors? Choosing "colorbars "NO" in Customizing Makes all Bars Orange.
The 1st post of this thread has been corrected. Choosing "colorbars "NO" in Customizing, will turn off painting the candles.
 
Is there any way this could be converted for tick charts? This might be my favorite candle painting indicator.. (y)
Your post did not provide enough information as to why Market Phases is not working on your tick charts.
If you have a charting error, you will find an (!) explanation mark in the upper left-hand corner of your chart.
Clicking on the (!) explanation mark will provide you clues as to where you have gone astray.
yrOuPxN.png
 

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