Triple Exhaustion Indicator For ThinkOrSwim

Chence27

Active member
Triple Exhaustion Indicator For ThinkOrSwim
This is a pretty powerful indicator showing buy and sell exhaustion (MACD, Stochastic and DMI all in an extreme condition). When the exhaustion ends, expect a reversal. Thank you @cos251 for the code!

Code:
## Triple Exhaustion Indicator
##
##
## CREDITS
## Requested by @Chence27 from criteria listed here https://usethinkscript.com/threads/triple-exhaustion-indicator.9001/
##
##
## Removing the header Credit credits and description is not permitted, any modification needs to be shared.
##
## V 1.0 :    @cos251 - Initial release per request from www.usethinkscript.com forum thread:
##       :    https://usethinkscript.com/threads/triple-exhaustion-indicator.9001/
## V 1.1 : @chence27 - modifcations to better approximate original study
##
##
##

declare upper;

# --- Inputs
input over_bought = 80;
input over_sold = 20;
input KPeriod = 10;
input DPeriod = 10;
input priceH = high;
input priceL = low;
input priceC = close;
input averageType = AverageType.SIMPLE;
input length = 1000;
input paintBars = yes;
input showLabels = yes;


# --- Indicators - StochasticSlow / MACD / MACD StDev / DMI+/-
def SlowK = reference StochasticFull(over_bought, over_sold, KPeriod, DPeriod, priceH, priceL, priceC, 3, averageType).FullK;
def MACD = reference MACD()."Value";
def priceMean = Average(MACD, length);
def MACD_stdev =  (MACD - priceMean) / StDev(MACD, length);
def dPlus = reference DMI()."DI+";
def dMinus = reference DMI()."DI-";
# --- End Indicators

# --- Conditions
def sellerRegular = SlowK < 20 and MACD_stdev < -1 and dPlus < 15;
def sellerExtreme = SlowK < 20 and MACD_stdev < -2 and dPlus < 15;
def buyerRegular = SlowK > 80 and MACD_stdev > 1 and dMinus < 15;
def buyerExtreme = SlowK > 80 and MACD_stdev > 2 and dMinus < 15;
# --- End Conditions

# -- Price Color
AssignPriceColor( if paintBars and sellerExtreme then Color.CYAN else if buyerExtreme and paintBars then Color.MAGENTA else if paintBars and sellerRegular then Color.GREEN else if buyerRegular and paintBars then Color.RED else if paintBars then Color.GRAY else Color.Current);

# --- Arrows/Triggers
plot RegularBuy = if sellerRegular[1] and !sellerRegular then low else Double.NaN;

RegularBuy.SetPaintingStrategy(PaintingSTrategy.ARROW_UP);

RegularBuy.SetDefaultColor(Color.GREEN);


plot RegularSell = if buyerRegular[1] and !buyerRegular then high else Double.NaN;

RegularSell.SetPaintingStrategy(PaintingSTrategy.ARROW_Down);

RegularSell.SetDefaultColor(Color.RED);


# --- Labels
AddLabel(showLabels,"SellerRegular",Color.RED);
AddLabel(showLabels,"SellerExtreme",Color.MAGENTA);
AddLabel(showLabels,"BuyerRegular",Color.GREEN);
AddLabel(showLabels,"BuyerExtreme",Color.CYAN);


VSftwHT.png

3R1WY6H.png
 
Last edited by a moderator:

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

This is a pretty powerful indicator. I'm going to explain how it works in hopes that someone here on the forum would be willing to code it in TOS and share it here in this thread. If not, you can still just add all the studies separately and monitor the conditions of each until they are in confluence.

_______________________________________________________

(Regular) SELLER EXHAUSTION condition - (if coded, this should color the bars or leave some other kind of signal for each bar that the condition is true):

All three conditions must be true:

1. Stochastic slow (default settings) = oversold (below 20)

2. MACD (default settings) = less than the negative of the 1st standard deviation of the MACD values for the past 1000 bars. In other words, take the 1st standard deviation of MACD over 1000 bars and make the value negative, and when MACD is below this value, the MACD condition is true. If you are unable to calculate standard deviation, this value is usually a little bit less than half of the average low extreme of MACD, so I might use about 40% of the extreme value. So say MACD was bottoming out at around -10, this value might be around -4, so the condition would be true when MACD was below -4.

3. DMI - directional movement index (default settings) = +DI less than 15
_______________________________________________________

(Extreme) SELLER EXHAUSTION condition - (if coded, this should give a similar signal to the regular seller exhaustion condition but be a different color or be different in some way so as to differentiate between the regular and extreme conditions):

This is the same as the Regular condition except the MACD must be below the 2nd standard deviation (instead of the 1st standard deviation). This is essentially doubling the first standard deviation (multiplying by two), or if you are unable to calculate standard deviations, I would take about 80% of the extreme lower value, so if MACD was bottoming out around -10, I would set the condition below -8.
_______________________________________________________

Seller exhaustion BUY SIGNAL - (this should give some kind of arrow to signal a buy entry):

This condition triggers when the Regular SELLER EXHAUSTION condition ends.

_______________________________________________________

(Regular) BUYER EXHAUSTION condition - (if coded, this should color the bars or leave some other kind of signal for each bar that the condition is true):

All three conditions must be true:

1. Stochastic slow (default settings) = overbought (above 80)

2. MACD (default settings) = greater than the 1st standard deviation of the MACD values for the past 1000 bars. In other words, take the 1st standard deviation of MACD over 1000 bars and when MACD is above this value, the MACD condition is true. If you are unable to calculate standard deviation, this value is usually a little bit less than half of the average high extreme of MACD. So say MACD was topping out at around 10, this value might be around 4, so the condition would be true when MACD was above 4.

3. DMI - directional movement index (default settings) = -DI less than 15
_______________________________________________________

(Extreme) BUYER EXHAUSTION condition - (if coded, this should give a similar signal to the regular seller exhaustion condition but be a different color or be different in some way so as to differentiate between the regular and extreme conditions):

This is the same as the Regular condition except the MACD must be above the 2nd standard deviation (instead of the 1st standard deviation). This is essentially doubling the first standard deviation (multiplying by two), or if you are unable to calculate standard deviations, I would take about 80% of the extreme high value, so if MACD was topping out around 10, I would set the condition above 8.
_______________________________________________________

Buyer exhaustion SELL SIGNAL - (this should give some kind of arrow to signal a sell entry):

This condition triggers when the Regular BUYER EXHAUSTION condition ends.
Check to see if all criteria was coded as you indicated. Hopefully this is what you were looking for.

Triple Exhaustion Indicator
Ruby:
## Triple Exhaustion Indicator
##
##
## CREDITS
## Requested by @Chence27 from criteria listed here https://usethinkscript.com/threads/triple-exhaustion-indicator.9001/
##
##
## Removing the header Credit credits and description is not permitted, any modification needs to be shared.
##
## V 1.0 :    @cos251 - Initial release per request from www.usethinkscript.com forum thread:
##       :    https://usethinkscript.com/threads/triple-exhaustion-indicator.9001/
##
##
##

declare upper;

# --- Inputs
input over_bought = 80;
input over_sold = 20;
input KPeriod = 10;
input DPeriod = 10;
input priceH = high;
input priceL = low;
input priceC = close;
input averageType = AverageType.SIMPLE;
input length = 1000;
input paintBars = yes;
input showLabels = yes;


# --- Indicators - StochasticSlow / MACD / MACD StDev / DMI+/-
def SlowK = reference StochasticFull(over_bought, over_sold, KPeriod, DPeriod, priceH, priceL, priceC, 3, averageType).FullK;
def MACD = reference MACD()."Value";
def priceMean = Average(MACD, length);
def MACD_stdev =  (MACD - priceMean) / StDev(MACD, length);
def dPlus = reference DMI()."DI+";
def dMinus = reference DMI()."DI-";
# --- End Indicators

# --- Conditions
def sellerRegular = SlowK < 20 and MACD_stdev < -1 and dPlus < 15;
def sellerExtreme = SlowK < 20 and MACD_stdev < -2 and dPlus < 15;
def buyerRegular = SlowK > 80 and MACD_stdev > 1 and dMinus < 15;
def buyerExtreme = SlowK > 80 and MACD_stdev > 2 and dMinus < 15;
# --- End Conditions

# -- Price Color
AssignPriceColor( if paintBars and sellerExtreme then Color.CYAN else if buyerExtreme and paintBars then Color.GREEN else if paintBars and sellerRegular then Color.YELLOW else if buyerRegular and paintBars then Color.DARK_GREEN else if paintBars then Color.GRAY else Color.Current);

# --- Arrows/Triggers
plot RegularBuy = if sellerRegular[1] and !sellerRegular then low else Double.NaN;
plot ExtremeBuy = if sellerExtreme[1] and !sellerExtreme then low else Double.NaN;
RegularBuy.SetPaintingStrategy(PaintingSTrategy.ARROW_UP);
ExtremeBuy.SetPaintingSTrategy(paintingSTrategy.Arrow_UP);
RegularBuy.SetDefaultColor(Color.LIME);
ExtremeBuy.SetDefaultColor(Color.GREEN);

plot RegularSell = if buyerRegular[1] and !buyerRegular then high else Double.NaN;
plot ExtremeSell = if buyerExtreme[1] and !buyerExtreme then high else Double.NaN;
RegularSell.SetPaintingStrategy(PaintingSTrategy.ARROW_Down);
ExtremeSell.SetPaintingSTrategy(paintingSTrategy.Arrow_DOWN);
RegularSell.SetDefaultColor(Color.Light_RED);
ExtremeSell.SetDefaultColor(Color.RED);

# --- Labels
AddLabel(showLabels,"SellerRegular",Color.YELLOW);
AddLabel(showLabels,"SellerExtreme",Color.CYAN);
AddLabel(showLabels,"BuyerRegular",Color.DARK_GREEN);
AddLabel(showLabels,"BuyerExtreme",Color.GREEN);


Triple Exhaustion Indicator SCAN (Scanner)
**UPDATE - added extreme buy and trend plots!

Ruby:
## Triple Exhaustion Indicator SCAN
##
##
## CREDITS
## Requested by @Chence27 from criteria listed here https://usethinkscript.com/threads/triple-exhaustion-indicator.9001/
## SCAN requested by @Trader_Andrew
##
## Removing the header Credit credits and description is not permitted, any modification needs to be shared.
##
## V 1.1 :    @cos251 - Added Extreme buy arrow and trend plots
##
## V 1.0 :    @cos251 - Initial release per request from www.usethinkscript.com forum thread:
##       :    https://usethinkscript.com/threads/triple-exhaustion-indicator.9001/
##       :    SCAN version requested by @Trader_Andrew
##
##
##


# --- Inputs
input over_bought = 80;
input over_sold = 20;
input KPeriod = 10;
input DPeriod = 10;
input priceH = high;
input priceL = low;
input priceC = close;
input averageType = AverageType.SIMPLE;
input length = 1000;
input paintBars = yes;
input showLabels = yes;


# --- Indicators - StochasticSlow / MACD / MACD StDev / DMI+/-
def SlowK = reference StochasticFull(over_bought, over_sold, KPeriod, DPeriod, priceH, priceL, priceC, 3, averageType).FullK;
def MACD = reference MACD()."Value";
def priceMean = Average(MACD, length);
def MACD_stdev =  (MACD - priceMean) / StDev(MACD, length);
def dPlus = reference DMI()."DI+";
def dMinus = reference DMI()."DI-";
# --- End Indicators

# --- Conditions
def sellerRegular = SlowK < 20 and MACD_stdev < -1 and dPlus < 15;
def sellerExtreme = SlowK < 20 and MACD_stdev < -2 and dPlus < 15;
def buyerRegular = SlowK > 80 and MACD_stdev > 1 and dMinus < 15;
def buyerExtreme = SlowK > 80 and MACD_stdev > 2 and dMinus < 15;
# --- End Conditions

# --- Arrows/Triggers
plot RegularBuyArrow = if sellerRegular[1] and !sellerRegular then 1 else Double.NaN;
plot ExtremeBuyArrow = if sellerExtreme[1] and !sellerExtreme then 1 else Double.NaN;
plot RegularSellArrow = if buyerRegular[1] and !buyerRegular then 1 else Double.NaN;
plot ExtremeSellArrow = if buyerExtreme[1] and !buyerExtreme then 1 else Double.NaN;
plot RegularBuyTrendExists = if sellerRegular then 1 else Double.NaN;
plot ExtremeBuyTrendExists = if sellerExtreme then 1 else Double.NaN;
plot RegularSellTrendExists = if buyerRegular then 1 else Double.NaN;
plot ExtremeSellTrendExists = if buyerExtreme then 1 else DOuble.NaN;
 
Last edited:
Check to see if all criteria was coded as you indicated. Hopefully this is what you were looking for.

4TxCJVA.jpg


Ruby:
## Triple Exhaustion Indicator
##
##
## CREDITS
## Requested by @Chence27 from criteria listed here https://usethinkscript.com/threads/triple-exhaustion-indicator.9001/
##
##
## Removing the header Credit credits and description is not permitted, any modification needs to be shared.
##
## V 1.0 :    @cos251 - Initial release per request from www.usethinkscript.com forum thread:
##       :    https://usethinkscript.com/threads/triple-exhaustion-indicator.9001/
##
##
##

declare upper;

# --- Inputs
input over_bought = 80;
input over_sold = 20;
input KPeriod = 10;
input DPeriod = 10;
input priceH = high;
input priceL = low;
input priceC = close;
input averageType = AverageType.SIMPLE;
input length = 1000;
input paintBars = yes;
input showLabels = yes;


# --- Indicators - StochasticSlow / MACD / MACD StDev / DMI+/-
def SlowK = reference StochasticFull(over_bought, over_sold, KPeriod, DPeriod, priceH, priceL, priceC, 3, averageType).FullK;
def MACD = reference MACD()."Value";
def priceMean = Average(MACD, length);
def MACD_stdev =  (MACD - priceMean) / StDev(MACD, length);
def dPlus = reference DMI()."DI+";
def dMinus = reference DMI()."DI-";
# --- End Indicators

# --- Conditions
def sellerRegular = SlowK < 20 and MACD_stdev < -1 and dPlus < 15;
def sellerExtreme = SlowK < 20 and MACD_stdev < -2 and dPlus < 15;
def buyerRegular = SlowK > 80 and MACD_stdev > 1 and dMinus < 15;
def buyerExtreme = SlowK > 80 and MACD_stdev > 2 and dMinus < 15;
# --- End Conditions

# -- Price Color
AssignPriceColor( if paintBars and sellerExtreme then Color.CYAN else if buyerExtreme and paintBars then Color.GREEN else if paintBars and sellerRegular then Color.YELLOW else if buyerRegular and paintBars then Color.DARK_GREEN else if paintBars then Color.GRAY else Color.Current);

# --- Arrows/Triggers
plot RegularBuy = if sellerRegular[1] and !sellerRegular then low else Double.NaN;
plot ExtremeBuy = if sellerExtreme[1] and !sellerExtreme then low else Double.NaN;
RegularBuy.SetPaintingStrategy(PaintingSTrategy.ARROW_UP);
ExtremeBuy.SetPaintingSTrategy(paintingSTrategy.Arrow_UP);
RegularBuy.SetDefaultColor(Color.LIME);
ExtremeBuy.SetDefaultColor(Color.GREEN);

plot RegularSell = if buyerRegular[1] and !buyerRegular then high else Double.NaN;
plot ExtremeSell = if buyerExtreme[1] and !buyerExtreme then high else Double.NaN;
RegularSell.SetPaintingStrategy(PaintingSTrategy.ARROW_Down);
ExtremeSell.SetPaintingSTrategy(paintingSTrategy.Arrow_DOWN);
RegularSell.SetDefaultColor(Color.Light_RED);
ExtremeSell.SetDefaultColor(Color.RED);

# --- Labels
AddLabel(showLabels,"SellerRegular",Color.YELLOW);
AddLabel(showLabels,"SellerExtreme",Color.CYAN);
AddLabel(showLabels,"BuyerRegular",Color.DARK_GREEN);
AddLabel(showLabels,"BuyerExtreme",Color.GREEN);
This is like magic .... request is fulfill and coded in an hour .... all i can say WOW
 
I use this study as a multi time frame system. For NQ I use 750, 2000 and 5000 volume charts (TOS doesn't have volume bars I don't believe so tick charts will be the closest you can get) and for ES I use 2000, 5000 and 10000 volume charts.

The highlighted vertical colored regions are the highest time frame, the colored bars are the middle time frame, and the dots are the lower time frame. The size and length of the triangles also correspond to the time frame.

xXJ3ehM.png

SESSPQN.png

Bbv0KZj.png
 
I've made some small modifications to better approximate the color system of the original study. Also, there are no buy/sell entry signals for the extreme condition, so I got rid of those as well.

CKRP56L.png


Code:
## Triple Exhaustion Indicator
##
##
## CREDITS
## Requested by @Chence27 from criteria listed here https://usethinkscript.com/threads/triple-exhaustion-indicator.9001/
##
##
## Removing the header Credit credits and description is not permitted, any modification needs to be shared.
##
## V 1.0 :    @cos251 - Initial release per request from www.usethinkscript.com forum thread:
##       :    https://usethinkscript.com/threads/triple-exhaustion-indicator.9001/
## V 1.1 : @chence27 - modifcations to better approximate original study
##
##
##

declare upper;

# --- Inputs
input over_bought = 80;
input over_sold = 20;
input KPeriod = 10;
input DPeriod = 10;
input priceH = high;
input priceL = low;
input priceC = close;
input averageType = AverageType.SIMPLE;
input length = 1000;
input paintBars = yes;
input showLabels = yes;


# --- Indicators - StochasticSlow / MACD / MACD StDev / DMI+/-
def SlowK = reference StochasticFull(over_bought, over_sold, KPeriod, DPeriod, priceH, priceL, priceC, 3, averageType).FullK;
def MACD = reference MACD()."Value";
def priceMean = Average(MACD, length);
def MACD_stdev =  (MACD - priceMean) / StDev(MACD, length);
def dPlus = reference DMI()."DI+";
def dMinus = reference DMI()."DI-";
# --- End Indicators

# --- Conditions
def sellerRegular = SlowK < 20 and MACD_stdev < -1 and dPlus < 15;
def sellerExtreme = SlowK < 20 and MACD_stdev < -2 and dPlus < 15;
def buyerRegular = SlowK > 80 and MACD_stdev > 1 and dMinus < 15;
def buyerExtreme = SlowK > 80 and MACD_stdev > 2 and dMinus < 15;
# --- End Conditions

# -- Price Color
AssignPriceColor( if paintBars and sellerExtreme then Color.CYAN else if buyerExtreme and paintBars then Color.MAGENTA else if paintBars and sellerRegular then Color.GREEN else if buyerRegular and paintBars then Color.RED else if paintBars then Color.GRAY else Color.Current);

# --- Arrows/Triggers
plot RegularBuy = if sellerRegular[1] and !sellerRegular then low else Double.NaN;

RegularBuy.SetPaintingStrategy(PaintingSTrategy.ARROW_UP);

RegularBuy.SetDefaultColor(Color.GREEN);


plot RegularSell = if buyerRegular[1] and !buyerRegular then high else Double.NaN;

RegularSell.SetPaintingStrategy(PaintingSTrategy.ARROW_Down);

RegularSell.SetDefaultColor(Color.RED);


# --- Labels
AddLabel(showLabels,"SellerRegular",Color.RED);
AddLabel(showLabels,"SellerExtreme",Color.MAGENTA);
AddLabel(showLabels,"BuyerRegular",Color.GREEN);
AddLabel(showLabels,"BuyerExtreme",Color.CYAN);
 
@cos251 There is one issue I'd like to resolve. It seems the study only paints a certain number of bars - I'm assuming this is the 1000 "length" value. Increasing this value in the study settings doesn't seem to work. The 1000 value in the original study is only for the MACD standard deviation calculation - the study itself should not be limited to this value - it's simply the number of previous bars the standard deviation calculation is using.

EDIT: This only seems to be the case with tick charts. Time and range charts don't seem to have this issue.

An image of where it stops painting the study:
1gCz4Z7.png
 
Last edited:
@cos251 There is one issue I'd like to resolve. It seems the study only paints a certain number of bars - I'm assuming this is the 1000 "length" value. Increasing this value in the study settings doesn't seem to work. The 1000 value in the original study is only for the MACD standard deviation calculation - the study itself should not be limited to this value - it's simply the number of previous bars the standard deviation calculation is using.

EDIT: This only seems to be the case with tick charts. Time and range charts don't seem to have this issue.

An image of where it stops painting the study:
1gCz4Z7.png
I'll take a peek and see if there is anything we can do to address the TICK chart issue. Looks like you've confirmed time based charts are good.
 
@cos251 There is one issue I'd like to resolve. It seems the study only paints a certain number of bars - I'm assuming this is the 1000 "length" value. Increasing this value in the study settings doesn't seem to work. The 1000 value in the original study is only for the MACD standard deviation calculation - the study itself should not be limited to this value - it's simply the number of previous bars the standard deviation calculation is using.

EDIT: This only seems to be the case with tick charts. Time and range charts don't seem to have this issue.

An image of where it stops painting the study:
1gCz4Z7.png

I´ve noticed this issue on time charts as well but seems like it´s only missing to paint candles if you go back in time, like a month or so. Here´s a 5min chart of DWAC from october 22 without any candles painted. Oddly, it only affects certain symbols because i tried quite a few looking back a month or so and most of them painted the candles according to the study. Weird..

 
Really interesting combining them.
But why these 3 indicators? could you explain the rational? is there any other combination with other indicators that could be interesting as well? I was thinking about the famous True Momentum Oscillator.
 
Very interesting and appears to work quite well, however once the underlying instrument goes into super trend (up or down) then this indicator gives signal (sell or buy) [which is correct as per underlying indicators] and will exit way too early leaving potential gains or enter way to early inuring further loss.

Need to add some guard rails to avoid getting out too early in super up trend and avoid getting in too early in super down trend.

Thanks for sharing the study, appreciate it. :)
 
Very interesting and appears to work quite well, however once the underlying instrument goes into super trend (up or down) then this indicator gives signal (sell or buy) [which is correct as per underlying indicators] and will exit way too early leaving potential gains or enter way to early inuring further loss.

Need to add some guard rails to avoid getting out too early in super up trend and avoid getting in too early in super down trend.

Thanks for sharing the study, appreciate it. :)
Using the True Momentum Oscillator (TMO indicator) can be very helpful
 
Last edited by a moderator:
Pretty nice..
but I won't use it by itself because it gives you no consistent matching reversals to enable you confidently trade.
But, I think when paired with an indicator like a Heikin Ashi, you can not only confidently to make profitable trades,
BUT catch the high and lows if they occur while you are trading
Try it.
 
yea @Chence27 .. Nice Indicator.. really compliments my chart nicely.. instead of price color I'm using arrows on each candle. It's helping me stay in trend longer. Thanks!
5500 Tick /mnq
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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