I just want to share a cool Tradingview Indicator and wondering if it can be converted into thinkscript
https://www.tradingview.com/script/16Da1RcQ-LordPepe-Stochastic-Signals/
This indicator generates some solid support/resistance along with buy and sell signal
Here's the code of this indicator
//@version=5
indicator(title="Exhaustion Suite", shorttitle="X Suite", overlay=true)
exShowTip = 'This will enable and disable the exhaustion support and resistance lines.'
exSourceTip = 'Choose a'
exSwingTip = 'This will check if we have a lower low or higher high than x bars back. Higher x will give less signals. 40 is arbitrary number. Find settings that work best for your trading style.'
exBarCount = 'This will control how many exhausted bars to count before looking for the highest high/lowest low to give signal. 10 is arbitrary number. Find settings that work best for your trading style.'
exBarsBack = 'This controls the sensitivity of an exhausted bar. Exaustion is a close > close x bars ago. This setting controls the x.'
superPositionTip = 'This will produce signals that are appear on the higher timeframe exhaustion and the current timeframe.'
exhaustionShow = input.bool(true, title='Show S/R Lines?', group='Exhaustion', tooltip=exShowTip, inline = '1')
exhaustionSource = input.source(close, title="Source", group='Exhaustion', inline = '2')
exhaustionSwing = input.int(40, title="Swing Length", group='Exhaustion', tooltip=exSwingTip, inline = '3')
exhaustionBarCount = input.int(10, title="Bar Count", group='Exhaustion', tooltip=exBarCount, inline = '4')
exhaustionBarsBack = input.int(4, title="Bars Back", group='Exhaustion', tooltip=exBarsBack, inline = '5')
exhaustionLineSize = input.int(1, title="S/R Size", group='Exhaustion', inline = '6')
supportColor = input.color(#20d400, title='TF1 Support Color', group='Exhaustion', inline = '7')
resistanceColor = input.color(#ed2f00, title='TF1 Resistance Color', group='Exhaustion', inline = '7')
exhaustionHigherTFShow = input.bool(false, title='Higher Timeframe Show?', group = 'Exhaustion', inline = '8')
exhaustionHigherTrendTF = input.timeframe('240', title='Higher Timeframe Signals', group='Exhaustion', inline = '8')
hSupportColor = input.color(#005be3, title='TF2 Support Color', group='Exhaustion', inline = '9')
hResistanceColor = input.color(#5b00e3, title='TF2 Resistance Color', group='Exhaustion', inline = '9')
superPositionSignals = input.bool(false, title = 'Super Position Signals? (under testing)', group = 'Exhaustion', tooltip=superPositionTip)
exhaustion(BARS, SWING_LEN, B_BACK, SRC) =>
var bullCount = 0
var bearCount = 0
ret = 0
k = ta.stoch(close, high, low, 8)
adr = ta.sma(high, 14) - ta.sma(low, 14)
adr_mean = ta.sma(adr, 20)
bullCount := SRC > SRC[B_BACK] ? bullCount + 1 : bullCount
bearCount := SRC < SRC[B_BACK] ? bearCount + 1 : bearCount
lowest_ = ta.lowest(low, SWING_LEN)
highest_ = ta.highest(high, SWING_LEN)
if(bullCount > BARS and close < open and high >= highest_)
bullCount := 0
ret = -1
else if(bearCount > BARS and close > open and low <= lowest_)
bearCount := 0
ret = 1
trend = exhaustion(exhaustionBarCount, exhaustionSwing, exhaustionBarsBack, exhaustionSource)
top = trend == -1 ? high : na
bottom = trend == 1 ? low : na
resistance = float(na)
support = float(na)
resistance := close < open and trend ? high : resistance[1]
support := close > open and trend ? low : support[1]
rescol = resistanceColor
resColor = ta.change(resistance) == 0 ? rescol: na
supcol = supportColor
supColor = ta.change(support) == 0 ? supcol : na
plotchar(exhaustionShow ? bottom:na, title="Buy", color=supcol, location=location.belowbar, char = '🡹', size=size.tiny)
plotchar(exhaustionShow ? top:na, title="Sell", color=rescol, location=location.abovebar, char = '🢃', size=size.tiny)
//Plot level
plot(exhaustionShow ? resistance :na, title="Reistance Level", style=plot.style_line, color=resColor, linewidth=exhaustionLineSize)
plot(exhaustionShow ? support :na, title="Support Level", style=plot.style_line, color=supColor, linewidth=exhaustionLineSize)
higherTFSource = request.security(syminfo.tickerid, exhaustionHigherTrendTF, exhaustionSource)
htfHigh = request.security(syminfo.tickerid, exhaustionHigherTrendTF, high)
htfLow = request.security(syminfo.tickerid, exhaustionHigherTrendTF, low)
htfOpen = request.security(syminfo.tickerid, exhaustionHigherTrendTF, open)
htfExhaustion(BARS, SWING_LEN, B_BACK, SRC) =>
var bullCount = 0
var bearCount = 0
ret = 0
k = ta.stoch(higherTFSource, htfHigh, htfLow, 8)
adr = ta.sma(htfHigh, 14) - ta.sma(htfLow, 14)
adr_mean = ta.sma(adr, 20)
bullCount := SRC > SRC[B_BACK] ? bullCount + 1 : bullCount
bearCount := SRC < SRC[B_BACK] ? bearCount + 1 : bearCount
lowest_ = ta.lowest(htfLow, SWING_LEN)
highest_ = ta.highest(htfHigh, SWING_LEN)
if(bullCount > BARS and higherTFSource < htfOpen and htfHigh >= highest_)
bullCount := 0
ret = -1
else if(bearCount > BARS and higherTFSource > htfOpen and htfLow <= lowest_)
bearCount := 0
ret = 1
higherTrend = htfExhaustion(exhaustionBarCount, exhaustionSwing, exhaustionBarsBack, higherTFSource)
hTop = higherTrend == -1 ? htfHigh : na
hBottom = higherTrend == 1 ? htfLow : na
hResistance = float(na)
hSupport = float(na)
hResistance := higherTFSource < htfOpen and higherTrend ? htfHigh : hResistance[1]
hSupport := higherTFSource > htfOpen and higherTrend ? htfLow : hSupport[1]
hrescol = hResistanceColor
hresColor = ta.change(hResistance) == 0 ? hrescol: na
hsupcol = hSupportColor
hsupColor = ta.change(hSupport) == 0 ? hsupcol : na
plotshape(exhaustionHigherTFShow ? hBottom:na, title="Buy", color=hsupcol, location=location.belowbar, style = shape.triangleup, size=size.normal)
plotshape(exhaustionHigherTFShow ? hTop:na, title="Sell", color=hrescol, location=location.abovebar, style = shape.triangledown, size=size.normal)
//Plot level
plot(exhaustionHigherTFShow ? hResistance :na, title="Reistance Level", style=plot.style_linebr, color=hresColor, linewidth=exhaustionLineSize)
plot(exhaustionHigherTFShow ? hSupport :na, title="Support Level", style=plot.style_linebr, color=hsupColor, linewidth=exhaustionLineSize)
superPositionBuy = trend == 1 and higherTrend == 1
superPositionSell = trend == -1 and higherTrend == -1
plotshape(superPositionSignals ? superPositionBuy : na, location=location.belowbar, style = shape.triangleup, size=size.normal, color=hsupcol)
plotshape(superPositionSignals ? superPositionSell : na, location=location.abovebar, style = shape.triangledown, size=size.normal, color=hrescol)
//=============================================================================================================
//MESA Moving Average`
mesaToolTip = 'This will show the MESA MA on another timeframe of your choosing. Great for knowing larger trends while diving into smaller ones.'
show = input(false, inline = '3', title="Show MESA for selected higher timeframes", tooltip = mesaToolTip, group = 'MESA')
_tf = input.timeframe(defval='0', inline = '3', title="Timeframe", group = 'MESA')
mesa = input.bool(true, title='MESA MA', inline='0', group='MESA')
tf1 = _tf == '0' ? timeframe.period : _tf
srcb = close
src1 = request.security(syminfo.tickerid, tf1, close, barmerge.gaps_on)
fast = 0.25
slow = 0.05
getMESA(src_in, fast, slow, show) =>
MAMA = 0.0
FAMA = 0.0
Price = src_in
FastLimit = fast
SlowLimit = slow
PI = 3.14159
Smooth = 0.0
Detrender = 0.0
I1 = 0.0
Q1 = 0.0
jI = 0.0
jQ = 0.0
I2 = 0.0
Q2 = 0.0
Re = 0.0
Im = 0.0
Period = 0.0
SmoothPeriod = 0.0
Phase = 0.0
DeltaPhase = 0.0
alpha = 0.0
if bar_index > 5 and show and not na(Price)
Smooth := (4 * Price + 3 * Price[1] + 2 * Price[2] + Price[3]) / 10
Detrender := (0.0962 * Smooth + 0.5769 * Smooth[2] - 0.5769 * Smooth[4] - 0.0962 * Smooth[6]) *
(0.075 * Period[1] + 0.54)
//Get the Inphase & Quadtrature Components
Q1 := (0.0962 * Detrender + 0.5769 * Detrender[2] - 0.5769 * Detrender[4] -
0.0962 * Detrender[6]) * (0.075 * Period[1] + 0.54)
I1 := Detrender[3]
//Advance phase angle by 90 deg
jI := (0.0962 * I1 + 0.5769 * I1[2] - 0.5769 * I1[4] - 0.0962 * I1[6]) *
(0.075 * Period[1] + 0.54)
jQ := (0.0962 * Q1 + 0.5769 * Q1[2] - 0.5769 * Q1[4] - 0.0962 * Q1[6]) *
(0.075 * Period[1] + 0.54)
//Phasor addition for 3-bar averaging
I2 := I1 - jQ
Q2 := Q1 + jI
//Smooth the I and Q components before applying the discriminator
I2 := 0.2 * I2 + 0.8 * I2[1]
Q2 := 0.2 * Q2 + 0.8 * Q2[1]
//Homodyne Discriminator
Re := I2 * I2[1] + Q2 * Q2[1]
Im := I2 * Q2[1] - Q2 * I2[1]
Re := 0.2 * Re + 0.8 * Re[1]
Im := 0.2 * Im + 0.8 * Im[1]
if Im != 0 and Re != 0
Period := 2 * PI / math.atan(Im / Re)
Period := Period>1.5*Period[1] ? 1.5*Period[1] : Period
Period := Period>50 ? 50 : Period
Period := Period<0.67*Period[1] ? 0.67*Period[1] : Period
Period := Period<6 ? 6 : Period
Period := 0.2*Period + 0.8*Period[1]
SmoothPeriod := 0.33 * Period + 0.67 * SmoothPeriod[1]
if I1 != 0
Phase := 180 / PI * math.atan(Q1 / I1)
DeltaPhase := Phase[1] - Phase
if DeltaPhase < 1
DeltaPhase := 1
alpha := FastLimit / DeltaPhase
alpha := alpha<SlowLimit ? SlowLimit : alpha
alpha := alpha>FastLimit ? FastLimit : alpha
MAMA := alpha * Price + (1 - alpha) * MAMA[1]
FAMA := 0.5 * alpha * MAMA + (1 - 0.5 * alpha) * FAMA[1]
if bar_index > 5 and show and na(Price)
MAMA := MAMA[1]
FAMA := FAMA[1]
if not show
MAMA := na
FAMA := na
[MAMA, FAMA]
[M_cur, F_cur] = getMESA(srcb, fast, slow, true)
[M_1, F_1] = getMESA(src1, fast, slow, show)
//BASELINE PLOT - includes the MAMA, FAMA, and fill
mamaColor = input.color(#138484, title='MAMA Color', group='MESA')
famaColor = input.color(#ff0000, title='FAMA Color', group='MESA')
cloudBars = input.bool(true, title='MESA MA Colored Bars?')
cloudBull = input.color(#42e3f5, title='Cloud Colored Bars')
cloudBear = input.color(#d6d6d6, title='Cloud Colored Bars')
cloudColors = M_cur > F_cur ? cloudBull : cloudBear
// Update charts
barcolor(cloudBars ? cloudColors : na)
p_m_cur = plot(mesa ? M_cur:na, "MAMA", mamaColor, 1)
p_f_cur = plot(mesa ? F_cur:na, "FAMA", famaColor, 1)
fill(p_m_cur, p_f_cur, M_cur > F_cur ? color.new(cloudBull, 90) : color.new(cloudBear, 90))
//SECONDARY PLOT - includes timeframe 1
p_m_1 = plot(mesa ? M_1:na, "MAMA Higher TF", mamaColor, 1)
p_f_1 = plot(mesa ? F_1:na, "FAMA Higher TF", famaColor, 1)
fill(p_m_1, p_f_1, M_cur > F_cur ? color.new(cloudBull, 90) : color.new(cloudBear, 90))
// Wavetrend Zone
//=============================================================================================================
// WaveTrend by VuManChu
wtMASource = input.source(hlc3, inline = '4', title = 'WT MA Source', group = 'Wavetrend')
wtChannelLen = input(9, inline = '5', title = 'WT Channel Length', group = 'Wavetrend')
wtAverageLen = input(12, inline = '5', title = 'WT Average Length', group = 'Wavetrend')
wtMALen = input(3, inline = '5', title = 'WT MA Length', group = 'Wavetrend')
obosSignalsTip = '1, 2, and 3 are overbought and oversold signals. The bullish numbers appear on bottom for bullish and on top for bearish. You can set these levels by changing the Wavetrend OB and OS levels.'
// WaveTrend Overbought & Oversold lines
obLevel1 = input(40, inline = '6', title = 'WT OB 1', group = 'Wavetrend')
obLevel2 = input(60, inline = '6', title = 'WT OB 2', group = 'Wavetrend')
obLevel3 = input(75, inline = '6', title = 'WT OB 3', group = 'Wavetrend')
osLevel1 = input(-40, inline = '7', title = 'WT OS 1', group = 'Wavetrend')
osLevel2 = input(-60, inline = '7', title = 'WT OS 2', group = 'Wavetrend')
osLevel3 = input(-75, inline = '7', title = 'WT OS 3', group = 'Wavetrend')
colorWTB1 = input.color(#fffb00, inline = '1', title = 'L1B', group = 'Wavetrend')
colorWTS1 = input.color(#ff9d00, inline = '1', title = 'L1S', group = 'Wavetrend')
colorWTB2 = input.color(#9dff00, inline = '1', title = 'L2B', group = 'Wavetrend')
colorWTS2 = input.color(#ff8400, inline = '1', title = 'L2S', group = 'Wavetrend')
colorWTB3 = input.color(#32a84a, inline = '1', title = 'L3B', group = 'Wavetrend')
colorWTS3 = input.color(#ff0000, inline = '1', title = 'L3S', group = 'Wavetrend', tooltip=obosSignalsTip)
level1Tip = 'Fastest WaveTrend signal. Best for low timeframe scalps but also very good at larger timeframes. Use with moving averages.'
level2Tip = "Intermediate WaveTrend signal. Best for confirming a potential reversal. Uptrend is different than downtrend as they could be used as reload zones if moving averages aren't broken."
level3Tip = 'Slowest WaveTrend signal. Best for most likely reversal senario. Should be used in conjunction with other indicators for confirmation. e.g. Exhaustion signal + Level 3 WaveTrend.'
lev1Sig = input.bool(false, title='Level 1 Signals', tooltip=level1Tip)
lev2Sig = input.bool(false, title='Level 2 Signals', tooltip=level2Tip)
lev3Sig = input.bool(true, title='Level 3 Signals', tooltip=level3Tip)
f_wavetrend(src, chlen, avg, malen, tf) =>
tfsrc = request.security(syminfo.tickerid, tf, src)
esa = ta.ema(tfsrc, chlen)
de = ta.ema(math.abs(tfsrc - esa), chlen)
ci = (tfsrc - esa) / (0.015 * de)
wt1 = request.security(syminfo.tickerid, tf, ta.ema(ci, avg))
wt2 = request.security(syminfo.tickerid, tf, ta.sma(wt1, malen))
wtVwap = wt1 - wt2
wtOversold = wt2 <= osLevel1
wtOverbought = wt2 >= obLevel1
wtCross = ta.cross(wt1, wt2)
wtCrossUp = wt2 - wt1 <= 0
wtCrossDown = wt2 - wt1 >= 0
wtCrosslast = ta.cross(wt1[2], wt2[2])
wtCrossUplast = wt2[2] - wt1[2] <= 0
wtCrossDownlast = wt2[2] - wt1[2] >= 0
[wt1, wt2, wtOversold, wtOverbought, wtCross, wtCrossUp, wtCrossDown, wtCrosslast, wtCrossUplast, wtCrossDownlast, wtVwap]
// Calculates WaveTrend
[wt1, wt2, wtOversold, wtOverbought, wtCross, wtCrossUp, wtCrossDown, wtCross_last, wtCrossUp_last, wtCrossDown_last, wtVwap] = f_wavetrend(wtMASource, wtChannelLen, wtAverageLen, wtMALen, timeframe.period)
lev1Buy = ta.crossover(wt1, wt2) and wt1 <= osLevel1 and wt1 > osLevel2
lev1Sell = ta.crossunder(wt1, wt2) and wt1 >= obLevel1 and wt1 < obLevel2
lev2Buy = ta.crossover(wt1, wt2) and wt1 <= osLevel2 and wt1 > osLevel3
lev2Sell = ta.crossunder(wt1, wt2) and wt1 >= obLevel2 and wt1 < obLevel3
lev3Buy = ta.crossover(wt1, wt2) and wt1 <= osLevel3
lev3Sell = ta.crossunder(wt1, wt2) and wt1 >= obLevel3
plotchar(lev1Sig ? lev1Buy:na, char = 'Ⅰ', location = location.belowbar, color = colorWTB1, size = size.tiny)
plotchar(lev1Sig ? lev1Sell:na, char = 'Ⅰ', location = location.abovebar, color = colorWTS1, size = size.tiny)
plotchar(lev2Sig ? lev2Buy:na, char = 'Ⅱ', location = location.belowbar, color = colorWTB2, size = size.tiny)
plotchar(lev2Sig ? lev2Sell:na, char = 'Ⅱ', location = location.abovebar, color = colorWTS2, size = size.tiny)
plotchar(lev3Sig ? lev3Buy:na, char = 'Ⅲ', location = location.belowbar, color = colorWTB3, size = size.tiny)
plotchar(lev3Sig ? lev3Sell:na, char = 'Ⅲ', location = location.abovebar, color = colorWTS3, size = size.tiny)
Hello
@samer800,
is it possible for you to take a look at this script and convert it into thinkscript. Its a really good support/resistance indicator