34 EMA Bands [v2]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © VishvaP

//@version=5
indicator("34 EMA Bands", overlay = true)


//Constants
h_EMA = ta.ema(high, 34)
l_EMA = ta.ema(low, 34)
EMA = ta.ema(close, 34)


//Multi Timeframe
res = input.timeframe(defval='60', title="Timeframe")

h_EMAres = request.security(syminfo.tickerid, res, h_EMA)
l_EMAres = request.security(syminfo.tickerid, res, l_EMA)
EMAres = request.security(syminfo.tickerid, res, EMA)


//Lower reversion zone bands
b_High = ((h_EMAres - EMAres) * math.phi) * math.pi + EMAres
b_Low = (-(EMAres - l_EMAres) * math.phi) * math.pi + EMAres

//Lower reversion zone bands smoothed
b_High_S = ta.wma(b_High, 8)
b_Low_S = ta.wma(b_Low, 8)


//Higher reversion zone bands
phi_High = ((h_EMAres - EMAres) * math.phi) * (math.phi + 4) + EMAres
phi_Low = (-(EMAres - l_EMAres) * math.phi) * (math.phi + 4) + EMAres

//Higher reversion zone bands smoothed
phi_High_S = ta.wma(phi_High, 8)
phi_Low_S = ta.wma(phi_Low, 8)

//====================================================================================================//

//Median zone bands [plot]
highP1 = plot(h_EMAres, color = color.blue, title = "Top median zone", display=display.none)
lowP1 = plot(l_EMAres, color = color.blue, title = "Bottom median zone", display=display.none)

//Lower reversion zone bands [plot]
highP3 = plot(b_High_S, color = color.yellow, title = "Lower sell zone", display=display.none)
lowP3 = plot(b_Low_S, color = color.teal, title = "Higher buy zone", display=display.none)

//Higher reversion zone bands [plot]
phiPlotHigh = plot(phi_High_S, color = color.red, title = "Top sell zone")
phiPlotLow = plot(phi_Low_S, color = color.green, title = "Bottom buy zone")


//Sell zone region [fill]
fill(phiPlotHigh, highP3, color.new(color.red, 95), title = "Sell zone")

//Buy zone region [fill]
fill(lowP3, phiPlotLow, color.new(color.green, 95), title = "Buy zone")

//Median zone region [fill]
fill(highP1, lowP1, color.new(color.black, 75), title = "Median zone")

