Join useThinkScript to post your question to a community of 21,000+ developers and traders.
#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);
Do we just add this to the code or replace existing codeAdded 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);
Ben question, when you put that in custom quotes what time frame is that based off of the 60 min?@MBF Use the shareable link. Then click the gear icon under your Watchlist and it should be under Custom Quotes. There is no need to create a new study.
Where in the quote Board would I do that or how@Trading51 the default timeframe for everything in ThinkorSwim is the daily chart. You can always adjust it to whichever timeframe you wish to use.
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
![]() |
Market Structure Trailing Stop [LuxAlgo] for ThinkOrSwim | Indicators | 11 | |
![]() |
Market Bias (CEREBR) Indicator for ThinkOrSwim | Indicators | 13 | |
T | NextSignal's Market Volume Profile For ThinkOrSwim | Indicators | 16 | |
F | Tea 2.0 - Market Cycle Indicator For ThinkOrSwim | Indicators | 12 | |
S | System Market Intraday Setup for ThinkorSwim | Indicators | 4 |
Start a new thread and receive assistance from our community.
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.
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.