Mayer MA
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © diemock

//@version=4
study("Mayer MA", overlay = true)
res = input("D", "Resolution")
d_tckr=security(syminfo.tickerid, "D", close)
w_tckr=security(syminfo.tickerid, "W", close)
tckr = security(syminfo.tickerid, res, close)


getMaLen() =>
    if bar_index < 200
        bar_index + 1
    else
        200


//200 Week Moving Average Heatmap
MA200 = sma(d_tckr, getMaLen())
wMA200 = wma(d_tckr, getMaLen())
Mayer = hl2 / MA200
lowMA=plot(MA200 * 0.55, transp = 100)
buylvl=plot(MA200 * 1.1, color=color.green)
plot(MA200 * 1.7, color=color.white)
selllvl=plot(MA200 * 2.5,color=color.red)
hiMA=plot(MA200 * 5, transp = 100)
lowWMA=plot(wMA200 * 0.55, color = color.white, transp = 100)
hiWMA=plot(wMA200 * 5, color = color.white, transp = 100)
fill(lowMA, lowWMA, color = color.green, transp = 50)
fill(hiMA, hiWMA, color = color.red, transp = 50)

//RSI
r = sma(rsi(d_tckr, 8), 4)
ob=0.0
os=0.0
ob := cross(r, 70) and rising(r, 2)? d_tckr : ob[1]
os := cross(r, 30) and falling(r, 2)? d_tckr : os[1]

fill(lowWMA,hiMA,d_tckr<os?#34ebb4:na, transp=90)
fill(lowWMA,hiMA,d_tckr>ob?#e62595:na, transp=90)

//Stoch RSI
rsi1 = rsi(d_tckr, 14)
stoch = sma(stoch(rsi1, rsi1, rsi1, 14), 3)

//RSI
up = rma(max(change(d_tckr), 0), 14)
down = rma(-min(change(d_tckr), 0), 14)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))


fill(lowWMA,hiMA,stoch<20 and rsi < 30?color.aqua:na, transp=65)
fill(lowWMA,hiMA,stoch>80 and rsi > 70?color.maroon:na, transp=60)