I've tried to modify an indicator already available on Tradingview.
The idea was to transform a WaveTrends in a "line" indicators which change color when an oversold or overbought condition is met. Those indicators are wavetrends from another timeframe.
I have two problems with that, I want to use an input function to be able to change the timeframe without have to do it by changing the code.
Second issue, You can see 4 line on the image
- mid TF short condition
- longTF short condition
- mid TF long condition
- longTF long condition.
I bypassed my difficulties by creating 2 lines for long and 2 lines for short but I would like to combined them in only 2 lines with 3 different color : Green for oversold condition, red for overbought condition and finally gray in between.
study("WTcheckMTF", shorttitle="WTCMTF")
n1 = input(10, "Channel Length")
n2 = input(21, "Average Length")
obLevel1 = input(60, "Over Bought Level 1")
obLevel2 = input(53, "Over Bought Level 2")
osLevel1 = input(-60, "Over Sold Level 1")
osLevel2 = input(-53, "Over Sold Level 2")
ap = hlc3
esa = ema(ap, n1)
d = ema(abs(ap - esa), n1)
ci = (ap - esa) / (0.015 * d)
tci = ema(ci, n2)
wt1 = tci
wt2 = sma(wt1,4)
//Mid and longer TF defining
long = input("D", "Interval used for long TF", type = resolution)
mid = input("360", "Interval used for mid TF", type = resolution)
**MidWT = security(tickerid, "360",wt2)
LongWT = security(tickerid, "720", wt2)**
//treshold MT LT
LWTLT = input(-53, "OS Threshold L")
LWTMT = input(-53, "OS Threshold M")
SWTLT = input(53, "OB Threshold L")
SWTMT = input(53, "OB Threshold M")
L1=1
M1=2
L2=3
M2=4
// Color for MT LT indicators
**lcolor1 = LongWT <= LWTLT ? lime : gray
mcolor1 = MidWT <= LWTMT ? lime : gray
lcolor2 = LongWT >= SWTLT ? red : gray
mcolor2 = MidWT >= SWTMT ? red : gray**
// plot
plot(L1, style=line,color=lcolor1,linewidth=25)
plot(M1, style=line,color=mcolor1,linewidth=25)
plot(L2, style=line,color=lcolor2,linewidth=25)
plot(M2, style=line,color=mcolor2,linewidth=25)