PHP Code:
//@version=5
// Copyright (c) 2019-present, Franklin Moormann (cheatcountry)
// True Range Adjusted Exponential Moving Average [CC] script may be freely distributed under the MIT license.
indicator('*', max_bars_back = 500, overlay = true)
float inp55 = input(title = 'Source', defval = close)
string res55 = input.timeframe(title = 'Resolution', defval = '')
bool rep55 = input(title = 'Allow Repainting?', defval = false)
float src47 = request.security(syminfo.tickerid, res55, inp55[rep55 ? 0 : barstate.isrealtime ? 1 : 0])[rep55 ? 0 : barstate.isrealtime ? 0 : 1]
int length47 = input.int(title = 'Length', defval = 40, minval = 2)
float mult47 = input.float(title = 'Mult', defval = 10.0, minval = 0.01)
float alpha47 = 2.0 / (length47 + 1)
float trL47 = ta.lowest(ta.tr, length47)
float trH47 = ta.highest(ta.tr, length47)
float trAdj47 = trH47 - trL47 != 0 ? (ta.tr - trL47) / (trH47 - trL47) : 0
float trAdjEma47 = 0.0
trAdjEma47 := nz(trAdjEma47[1]) + (alpha47 * (1 + (trAdj47 * mult47)) * (src47 - nz(trAdjEma47[1])))
float slo47 = src47 - trAdjEma47
int sig47 = slo47 > 0 ? slo47 > nz(slo47[1]) ? 2 : 1 : slo47 < 0 ? slo47 < nz(slo47[1]) ? -2 : -1 : 0
color tradjemaColor47 = sig47 > 1 ? color.green : sig47 > 0 ? color.lime : sig47 < -1 ? color.maroon : sig47 < 0 ? color.red : color.black
//plot(trAdjEma47, title = 'TrAdjEma', color = tradjemaColor47, linewidth = 2)
/////////////////////////////////
float src49 = request.security(syminfo.tickerid, res55, inp55[rep55 ? 0 : barstate.isrealtime ? 1 : 0])[rep55 ? 0 : barstate.isrealtime ? 0 : 1]
float tr49 = request.security(syminfo.tickerid, res55, ta.tr[rep55 ? 0 : barstate.isrealtime ? 1 : 0])[rep55 ? 0 : barstate.isrealtime ? 0 : 1]
int length49 = input.int(title = 'Length', defval = 30, minval = 2)
float hhC49 = ta.highest(src49, length49)
float llC49 = ta.lowest(src49, length49)
float result49 = hhC49 - llC49
float effort49 = math.sum(tr49, length49)
float alpha49 = effort49 != 0 ? result49 / effort49 : 0
float nama49 = 0.0
nama49 := (alpha49 * src49) + ((1 - alpha49) * nz(nama49[1]))
float slo49 = src49 - nama49
int sig49 = slo49 > 0 ? slo49 > nz(slo49[1]) ? 2 : 1 : slo49 < 0 ? slo49 < nz(slo49[1]) ? -2 : -1 : 0
color namaColor49 = sig49 > 1 ? color.green : sig49 > 0 ? color.lime : sig49 < -1 ? color.maroon : sig49 < 0 ? color.red : color.black
//plot(nama49, title = 'Nama', color = namaColor49, linewidth = 2)
//////////////////////////////////////
float src50 = request.security(syminfo.tickerid, res55, inp55[rep55 ? 0 : barstate.isrealtime ? 1 : 0])[rep55 ? 0 : barstate.isrealtime ? 0 : 1]
float tr50 = request.security(syminfo.tickerid, res55, ta.tr[rep55 ? 0 : barstate.isrealtime ? 1 : 0])[rep55 ? 0 : barstate.isrealtime ? 0 : 1]
int length50 = input.int(title = 'Length', defval = 30, minval = 2)
float result50 = math.abs(src50 - nz(src50[length50]))
float effort50 = math.sum(tr50, length50)
float alpha50 = effort50 != 0 ? result50 / effort50 : 0
float anama50 = 0.0
anama50 := (alpha50 * src50) + ((1 - alpha50) * nz(anama50[1]))
float slo50 = src50 - anama50
int sig50 = slo50 > 0 ? slo50 > nz(slo50[1]) ? 2 : 1 : slo50 < 0 ? slo50 < nz(slo50[1]) ? -2 : -1 : 0
color anamaColor50 = sig50 > 1 ? color.green : sig50 > 0 ? color.lime : sig50 < -1 ? color.maroon : sig50 < 0 ? color.red : color.black
//plot(anama50, title = 'Anama', color = anamaColor50, linewidth = 2)
/////////////////////////////////////////////////////////
float src51 = request.security(syminfo.ticker, res55, inp55[rep55 ? 0 : barstate.isrealtime ? 1 : 0])[rep55 ? 0 : barstate.isrealtime ? 0 : 1]
int fastLength51 = input.int(title = 'FastLength', defval = 6, minval = 1)
int slowLength51 = input.int(title = 'SlowLength', defval = 12, minval = 1)
int sampleLength51 = input.int(title = 'SampleLength', defval = 5, minval = 1)
hannFilter51(float sampleSrc51, int length51) =>
filt51 = 0.0, coef51 = 0.0
for i = 1 to length51
cosine51 = 1 - math.cos(2 * math.pi * i / (length51 + 1))
filt51 := filt51 + (cosine51 * nz(sampleSrc51[i - 1]))
coef51 := coef51 + cosine51
filt51 := coef51 != 0 ? filt51 / coef51 : 0
float sample51 = 0.0
sample51 := bar_index % sampleLength51 == 0 ? src51 : nz(sample51[1])
float fastAvg51 = hannFilter51(sample51, fastLength51)
float slowAvg51 = hannFilter51(sample51, slowLength51)
float slo51 = fastAvg51 - slowAvg51
int sig51 = slo51 > 0 ? slo51 > nz(slo51[1]) ? 2 : 1 : slo51 < 0 ? slo51 < nz(slo51[1]) ? -2 : -1 : 0
color udsmaColor51 = sig51 > 1 ? color.green : sig51 > 0 ? color.lime : sig51 < -1 ? color.maroon : sig51 < 0 ? color.red : color.black
//plot(fastAvg51, title = "FastAverage", color = udsmaColor51, linewidth = 2)
//plot(slowAvg51, title = "SlowAverage", color = chart.fg_color, linewidth = 1)
//////////////////////////////////
float src52 = request.security(syminfo.tickerid, res55, inp55[rep55 ? 0 : barstate.isrealtime ? 1 : 0])[rep55 ? 0 : barstate.isrealtime ? 0 : 1]
fastLength52 = input.int(title = "FastLength", defval = 14, minval = 1)
slowLength52 = input.int(title = "SlowLength", defval = 30, minval = 1)
leavittProjection52(float src52, int length52) =>
float result52 = ta.linreg(src52, length52, -1)
leavittConvolution52(float src52, int length52) =>
int sqrtLength52 = math.floor(nz(math.sqrt(length52)))
float result52 = ta.linreg(leavittProjection52(src52, length52), sqrtLength52, -1)
float fastConv52 = leavittConvolution52(src52, fastLength52)
float slowConv52 = leavittConvolution52(src52, slowLength52)
float slo52 = fastConv52 - slowConv52
int sig52 = slo52 > 0 ? slo52 > nz(slo52[1]) ? 2 : 1 : slo52 < 0 ? slo52 < nz(slo52[1]) ? -2 : -1 : 0
color lcColor52 = sig52 > 1 ? color.green : sig52 > 0 ? color.lime : sig52 < -1 ? color.maroon : sig52 < 0 ? color.red : color.white
//plot(fastConv52, title = 'FastConv', color = lcColor52, linewidth = 2)
//plot(slowConv52, title = 'SlowConv', color = chart.fg_color, linewidth = 1)
f_security(_symbol66, _res66, _src66, _repaint66) =>
request.security(_symbol66, _res66, _src66[_repaint66 ? 0 : barstate.isrealtime ? 1 : 0])[_repaint66 ? 0 : barstate.isrealtime ? 0 : 1]
res66 = input.timeframe(title='Resolution', defval='')
rep66 = input(title='Allow Repainting?', defval=false)
length53 = input.int(title='Length', defval=14, minval=1)
factor53 = input.int(title='Factor', defval=2, minval=1)
p53 = f_security(syminfo.tickerid, res66, hl2, rep66)
h53 = f_security(syminfo.tickerid, res66, high, rep66)
l53 = f_security(syminfo.tickerid, res66, low, rep66)
t53 = f_security(syminfo.tickerid, res66, ta.tr, rep66)
mpEma53 = ta.ema(p53, length53)
trEma53 = ta.ema(t53, length53)
stdDev53 = ta.stdev(trEma53, length53)
ad53 = p53 > nz(p53[1]) ? mpEma53 + trEma53 / 2 : p53 < nz(p53[1]) ? mpEma53 - trEma53 / 2 : mpEma53
adm53 = ta.ema(ad53, length53)
trndDn53 = 0.0
trndDn53 := ta.crossunder(adm53, mpEma53) ? h53[2] : p53 < nz(p53[1]) ? p53 + stdDev53 * factor53 : nz(trndDn53[1], h53[2])
trndUp53 = 0.0
trndUp53 := ta.crossover(adm53, mpEma53) ? l53[2] : p53 > nz(p53[1]) ? p53 - stdDev53 * factor53 : nz(trndUp53[1], l53[2])
trndr53 = 0.0
trndr53 := adm53 < mpEma53 ? trndDn53 : adm53 > mpEma53 ? trndUp53 : nz(trndr53[1], 0)
sig53 = p53 > trndr53 ? 1 : p53 < trndr53 ? -1 : 0
trndrColor53 = sig53 > 0 ? color.green : sig53 < 0 ? color.red : color.black
//plot(trndr53, color=trndrColor53, linewidth=2)
//plot(mpEma53, color=color.new(color.blue, 0), linewidth=2)
//plot(adm53, color=color.new(color.black, 0), linewidth=1)
/////////////////////////////////////////
c54 = f_security(syminfo.tickerid, res66, close, rep66)
v54 = f_security(syminfo.tickerid, res66, volume, rep66)
length54 = input.int(title='Length', defval=50, minval=2)
mult54 = input.float(title='Mult', defval=10.0, minval=0.01)
alpha54 = 2.0 / (length54 + 1)
mom54 = c54 - nz(c54[1])
pv54 = mom54 > 0 ? v54 : 0
nv54 = mom54 < 0 ? v54 : 0
pvMa54 = ta.ema(pv54, length54)
nvMa54 = ta.ema(nv54, length54)
vs54 = pvMa54 + nvMa54 != 0 ? math.abs(pvMa54 - nvMa54) / (pvMa54 + nvMa54) : 0
rsvaEma54 = 0.0
rsvaEma54 := nz(rsvaEma54[1]) + (alpha54 * (1 + (vs54 * mult54)) * (c54 - nz(rsvaEma54[1])))
slo54 = c54 - rsvaEma54
sig54 = slo54 > 0 ? slo54 > nz(slo54[1]) ? 2 : 1 : slo54 < 0 ? slo54 < nz(slo54[1]) ? -2 : -1 : 0
rsvaemaColor54 = sig54 > 1 ? color.green : sig54 > 0 ? color.lime : sig54 < -1 ? color.maroon : sig54 < 0 ? color.red : color.black
//plot(rsvaEma54, title='RSEma', color=rsvaemaColor54, linewidth=2)
////////////////////////////////////
length56 = input.int(title='Length', defval=25, minval=1)
h56 = f_security(syminfo.tickerid, res66, high, rep66)
l56 = f_security(syminfo.tickerid, res66, low, rep66)
c56 = f_security(syminfo.tickerid, res66, close, rep66)
hh56 = ta.highest(h56, length56)
ll56 = ta.lowest(l56, length56)
atr56 = ta.atr(length56)
mult56 = math.sqrt(length56)
dSup56 = hh56 - atr56 * mult56
dRes56 = ll56 + atr56 * mult56
dMid56 = (dSup56 + dRes56) / 2
sig56 = c56 > dMid56 ? 1 : c56 < dMid56 ? -1 : 0
dsrColor56 = sig56 > 0 ? color.green : sig56 < 0 ? color.red : color.black
//plot(dSup56, title='Support', color=color.new(color.red, 0), linewidth=2)
//plot(dMid56, title='Middle', color=dsrColor56, linewidth=1)
//plot(dRes56, title='Resistance', color=color.new(color.green, 0), linewidth=2)
///////////////////////////////
length57 = input.int(title='Length', defval=3, minval=1)
h57 = f_security(syminfo.tickerid, res66, high, rep66)
l57 = f_security(syminfo.tickerid, res66, low, rep66)
c57 = f_security(syminfo.tickerid, res66, close, rep66)
highMa57 = ta.sma(h57, length57)
lowMa57 = ta.sma(l57, length57)
ghla57 = 0.0
ghla57 := c57 > nz(highMa57[1]) ? lowMa57 : c57 < nz(lowMa57[1]) ? highMa57 : nz(ghla57[1])
sig57 = c57 > ghla57 ? 1 : c57 < ghla57 ? -1 : 0
ghlaColor57 = sig57 > 0 ? color.green : sig57 < 0 ? color.red : color.black
//plot(ghla57, title='GHLA', color=ghlaColor57, linewidth=2)
//////////////////////////////////
lbLength58 = input.int(title='LookBackLength', defval=21, minval=1)
p58 = f_security(syminfo.tickerid, res66, close, rep66)
h58 = f_security(syminfo.tickerid, res66, high, rep66)
l58 = f_security(syminfo.tickerid, res66, low, rep66)
ll58 = ta.lowest(lbLength58)
hh58 = ta.highest(lbLength58)
hCount58 = 0
lCount58 = 0
cbl58 = p58
for i = 0 to lbLength58 by 1
if l58[i] == ll58
for j58 = i + 1 to i + lbLength58 by 1
lCount58 += (h58[j58] > h58[i] ? 1 : 0)
if lCount58 == 2
cbl58 := h58[j58]
break
if h58[i] == hh58
for j58 = i + 1 to i + lbLength58 by 1
hCount58 += (l58[j58] < l58[i] ? 1 : 0)
if hCount58 == 2
cbl58 := l58[j58]
break
sig58 = p58 > cbl58 ? 1 : p58 < cbl58 ? -1 : 0
cblColor58 = sig58 > 0 ? color.green : sig58 < 0 ? color.red : color.black
//plot(cbl58, color=cblColor58, linewidth=2)
//////////////////////////////
inp59 = input(title='Source', defval=close)
h59 = f_security(syminfo.tickerid, res66, high, rep66)
l59 = f_security(syminfo.tickerid, res66, low, rep66)
c59 = f_security(syminfo.tickerid, res66, inp59, rep66)
length59 = input.int(title='Length', defval=14, minval=1)
mHigh59 = ta.linreg(h59, length59, 0) - ta.linreg(h59, length59, 1)
mLow59 = ta.linreg(l59, length59, 0) - ta.linreg(l59, length59, 1)
upperBand59 = h59, lowerBand59 = l59
for i = 0 to length59 - 1
currH59 = nz(h59[i])
prevH59 = nz(h59[i - 1])
currL59 = nz(l59[i])
prevL59 = nz(l59[i - 1])
vHigh59 = currH59 + (nz(mHigh59[i]) * i)
vLow59 = currL59 + (nz(mLow59[i]) * i)
upperBand59 := math.max(vHigh59, upperBand59)
lowerBand59 := math.min(vLow59, lowerBand59)
middleBand59 = (upperBand59 + 59) / 2
slo59 = c59 - middleBand59
sig59 = (c59 > upperBand59 and nz(c59[1]) <= nz(upperBand59[1])) or (c59 > lowerBand59 and nz(c59[1]) <= nz(lowerBand59[1]))
? 1 : (c59 < lowerBand59 and nz(c59[1]) >= nz(lowerBand59[1])) or (c59 < upperBand59 and nz(c59[1]) >= nz(upperBand59[1]))
? -1 : slo59 > 0 ? slo59 > nz(slo59[1]) ? 2 : 1 : slo59 < 0 ? slo59 < nz(slo59[1]) ? -2 : -1 : 0
pbColor59 = sig59 > 1 ? color.green : sig59 > 0 ? color.lime : sig59 < -1 ? color.maroon : sig59 < 0 ? color.red : color.black
//plot(upperBand59, title="UpperBand", linewidth=2, color=pbColor59)
//plot(middleBand59, title="MiddleBand", linewidth=1, color=color.white)
//plot(lowerBand59, title="LowerBand", linewidth=2, color=pbColor59)
///////////////////////////////////
length61 = input.int(title='Length', defval=25, minval=1)
h61 = f_security(syminfo.tickerid, res66, high, rep66)
l61 = f_security(syminfo.tickerid, res66, low, rep66)
c61 = f_security(syminfo.tickerid, res66, close, rep66)
hh61 = ta.highest(h61, length61)
ll61 = ta.lowest(l61, length61)
range_161 = hh61 - ll61
sup161 = ll61 - 0.25 * range_161
sup261 = ll61 - 0.5 * range_161
res161 = hh61 + 0.25 * range_161
res261 = hh61 + 0.5 * range_161
mid61 = (sup161 + sup261 + res161 + res261) / 4
sig61 = c61 > mid61 ? 1 : c61 < mid61 ? -1 : 0
psrColor61 = sig61 > 0 ? color.green : sig61 < 0 ? color.red : color.black
//plot(sup161, title='Support1', color=color.new(color.red, 0), linewidth=2)
//plot(sup261, title='Support2', color=color.new(color.red, 0), linewidth=2)
//plot(mid61, title='Middle', color=psrColor61, linewidth=1)
//plot(res161, title='Resistance1', color=color.new(color.green, 0), linewidth=2)
//plot(res261, title='Resistance2', color=color.new(color.green, 0), linewidth=2)