Market Phases Indicator for ThinkorSwim

Ben question the only place the Quote bard can be in TOS is the left of the main chart ? Is there a way to have a Quote Baird attached to another chart like on another monitor ?
 
BTW you cannot have this code on a 5 min and have multiple quote boards on different times frames running if you change one it changes the other, I think the code has to be under another name, how can this codes name be changed or duplicated any hints ?
 
Added an option to add pullback entries when FullStochastic is oversold or overbought. Let me know your thoughts.

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;

def BuySfast = reference StochasticFast(). UpSignal is true && bullphase is true;

def SellSfast = reference StochasticFast(). DownSignal is true && bearphase 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);


input over_bought = 80;
input over_sold = 20;
input KPeriod = 10;
input DPeriod = 10;
input slowing_period =3;


def priceH = high;
def priceL = low;
def priceC = close;

def averageType = AverageType.SIMPLE;

def lowest_k = Lowest(priceL, KPeriod);
def c1 = priceC - lowest_k;
def c2 = Highest(priceH, KPeriod) - lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;

def FullK = MovingAverage(averageType, FastK, slowing_period);
def FullD = MovingAverage(averageType, FullK, DPeriod);


input StochasticPB = {default "No", "On FullK", "On FullD", "On CrossOver"}; #hint StochasticPB: Displays the pullback arrows for stochastic buy or sell signals. For FullK or FullD, will plot arrows when they cross overbought or oversold.  For CrossOver, more strict reqs, will plot arrows when FastK crosses FastD while overbought or oversold.


def OverBought = over_bought;
def OverSold = over_sold;

def upK = FullK crosses above OverSold && bullphase is true;
def upD = FullD crosses above OverSold && bullphase is true;

def downK = FullK crosses below OverBought && bearphase is true;
def downD = FullD crosses below OverBought && bearphase is true;

plot UpSignal;
plot DownSignal;
switch (StochasticPB) {
case "No":
    UpSignal = Double.NaN;
    DownSignal = Double.NaN;
case "On FullK":
    UpSignal = if upK then OverSold else Double.NaN;
    DownSignal = if downK then OverBought else Double.NaN;


case "On FullD":
    UpSignal = if upD then OverSold else Double.NaN;
    DownSignal = if downD then OverBought else Double.NaN;


case "On CrossOver":
    UpSignal = FullK crosses above FullD && bullphase && (FullK < OverSold or FullD < Oversold);

    DownSignal = FullK crosses below FullD && bearphase && (FullK > Overbought or FullD > Overbought);
}

UpSignal.SetHiding(StochasticPB == StochasticPB."No");
DownSignal.SetHiding(StochasticPB == StochasticPB."No");


UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
UpSignal.SetDefaultColor(Color.LIGHT_GREEN);
UpSignal.SetLineWeight(1);

DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
DownSignal.SetDefaultColor(Color.LIGHT_RED);
DownSignal.SetLineWeight(1);
Any ideas on the stochastic settings which would with the best ?
 
@Trading51

I would just start with the default ones and adjust from there. I mainly trade stocks but if your futures or forex, you may want different settings.
 
Using the $PYPL symbol if you have the quote board code on 30 minutes it says PYPL is in a bullish phase if you use the code that updated in post #2 and put PYPL on a 30 minute time frame it says it's in an accumulation phase, one of these codes must have an error ?
 
And the aggregation period on the indicator in the quote board is the same? Can you send a pic of the quote board?
 
For some reason when I copy & paste the code into TOS I don't see anything? Please help.

I see it now, I had to adjust the timeframe. Thanks.
 
Last edited:
Im just not sure about chart indicator time frame and watchlist time frame testing any input would be appreciated.
 
Pull up $ES on 5 min with the original code it says distribution while the 5 min quote board says bull phase, something is off
 

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