Triple Exhaustion Indicator for Tradingview conversion

JohnTrader

New member
Platform
  1. Thinkorswim
  2. TradingView
Hello Barbaros,

Please help me convert this TOS into tradingview. Found it on usthinkscript, and it may benefit someone else too. Thank a lot Barbaros.

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);
 

barbaros

Administrator
Staff member
Here is the first version. Some debugging might be needed with indicators and parameters.

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
//
//
// Converted by Barbaros to ToS for https://b4indicators.com/threads/triple-exhaustion-indicator-for-tradingview-conversion.235/

//@version=5
indicator("Triple Exhaustion Indicator", overlay=true)

// --- Inputs
KPeriod = input.int(10, "KPeriod")
priceH = input.source(high, "priceH")
priceL = input.source(low, "priceL")
priceC = input.source(close, "priceC")
length = input.int(1000, "length")
paintBars = input.bool(true, "paintBars")

// --- Indicators - StochasticSlow / MACD / MACD StDev / DMI+/-
Stochastic = ta.stoch (priceC, priceH, priceL, 3)
SlowK = ta.sma (Stochastic, KPeriod)
[_, MACD, _] = ta.macd(priceC, 12, 26, 9)
priceMean = ta.sma(MACD, length)
MACD_stdev =  (MACD - priceMean) / ta.stdev(MACD, length)
[dPlus, dMinus, adx] = ta.dmi(17, 14)

// --- Conditions
sellerRegular = SlowK < 20 and MACD_stdev < -1 and dPlus < 15
sellerExtreme = SlowK < 20 and MACD_stdev < -2 and dPlus < 15
buyerRegular = SlowK > 80 and MACD_stdev > 1 and dMinus < 15
buyerExtreme = SlowK > 80 and MACD_stdev > 2 and dMinus < 15

// -- Price Color
barcolor(paintBars ? sellerExtreme ? color.rgb(0,255,255) : buyerExtreme ? color.rgb(255,0,255) : sellerRegular ? color.rgb(0, 255, 0) : buyerRegular ? color.rgb(255, 0, 0) : color.rgb(105,105,105) : na)

// --- Arrows/Triggers
RegularBuy = sellerRegular[1] and not sellerRegular
RegularSell = buyerRegular[1] and not buyerRegular

plotshape(RegularBuy, title="RegularBuy", text="Buy", style=shape.labelup, location=location.belowbar, color=color.rgb(0, 255, 0), textcolor=color.rgb(0, 0, 0), size=size.normal)
plotshape(RegularSell, title="RegularSell", text="Sell", style=shape.labeldown, location=location.abovebar, color=color.rgb(255, 0, 0), textcolor=color.rgb(255, 255, 255), size=size.normal)

d2KPiMk.png
 
Top