// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ChozenTrades
//@version=5
indicator('Trend Web', overlay=true)
matype = input.string('EMA', title='MA Type', options=['EMA', 'SMA', 'RMA', 'WMA', 'VWMA'])
prd = input.int(20, title='Period to Check Trend', minval=5)
rateinp = input.float(1, title='Trend Channel Rate %', minval=0.1, step=0.1)
ulinreg = input(true, title='Use Linear Regression')
linprd = input.int(10, title='Linear Regression Period', minval=2)
rate = rateinp / 100
pricerange = ta.highest(280) - ta.lowest(280)
chan = pricerange * rate
gettrend(len) =>
masrc = matype == 'EMA' ? ta.ema(close, len) : matype == 'RMA' ? ta.rma(close, len) : matype == 'VWMA' ? ta.vwma(close, len) : matype == 'WMA' ? ta.wma(close, len) : ta.sma(close, len)
ma = ulinreg ? ta.linreg(masrc, linprd, 0) : masrc
hh = ta.highest(ma, prd)
ll = ta.lowest(ma, prd)
diff = math.abs(hh - ll)
iff_1 = ma < hh - chan ? -1 : 0
iff_2 = ma > ll + chan ? 1 : iff_1
trend = diff > chan ? iff_2 : 0
_ret = trend * diff / chan
_ret
getcol(trend) =>
_ret = trend >= 10.0 ? #00FF00ff : trend >= 9.0 ? #00FF00ef : trend >= 8.0 ? #00FF00df : trend >= 7.0 ? #00FF00cf : trend >= 6.0 ? #00FF00bf : trend >= 5.0 ? #00FF00af : trend >= 4.0 ? #00FF009f : trend >= 3.0 ? #00FF008f : trend >= 2.0 ? #00FF007f : trend >= 1.0 ? #00FF006f : trend <= -10.0 ? #FF0000ff : trend <= -9.0 ? #FF0000ef : trend <= -8.0 ? #FF0000df : trend <= -7.0 ? #FF0000cf : trend <= -6.0 ? #FF0000bf : trend <= -5.0 ? #FF0000af : trend <= -4.0 ? #FF00009f : trend <= -3.0 ? #FF00008f : trend <= -2.0 ? #FF00007f : trend <= -1.0 ? #FF00006f : na
_ret
getma(lngth) =>
_ret = matype == 'EMA' ? ta.ema(close, lngth) : matype == 'RMA' ? ta.rma(close, lngth) : matype == 'VWMA' ? ta.vwma(close, lngth) : matype == 'WMA' ? ta.wma(close, lngth) : ta.sma(close, lngth)
_ret
plot(getma(5), color=getcol(gettrend(5)))
plot(getma(10), color=getcol(gettrend(10)))
plot(getma(15), color=getcol(gettrend(15)))
plot(getma(20), color=getcol(gettrend(20)))
plot(getma(25), color=getcol(gettrend(25)))
plot(getma(30), color=getcol(gettrend(30)))
plot(getma(35), color=getcol(gettrend(35)))
plot(getma(40), color=getcol(gettrend(40)))
plot(getma(45), color=getcol(gettrend(45)))
plot(getma(50), color=getcol(gettrend(50)))
plot(getma(55), color=getcol(gettrend(55)))
plot(getma(60), color=getcol(gettrend(60)))
plot(getma(65), color=getcol(gettrend(65)))
plot(getma(70), color=getcol(gettrend(70)))
plot(getma(75), color=getcol(gettrend(75)))
plot(getma(80), color=getcol(gettrend(80)))
plot(getma(85), color=getcol(gettrend(85)))
plot(getma(90), color=getcol(gettrend(90)))
plot(getma(95), color=getcol(gettrend(95)))
plot(getma(100), color=getcol(gettrend(100)))