Percent above or Below Moving Average Candle colour
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Amit_001

//@version=5
indicator("percent above or Below Moving Average", overlay=true, shorttitle = "percent_MA_X")
maLevel = input(title="Moving Average", defval=20)
percentage = input(title = "%above/Below", defval = 50)

typeMA = input.string(title = "Select type", defval = "SMA", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA", "DEMA"])
src = input(close, title="Source")
MASource = ta.sma(src, maLevel)

if typeMA == "EMA"
    MASource := ta.ema(src, maLevel)
else if typeMA == "SMMA (RMA)"
    MASource := ta.rma(src, maLevel)
else if typeMA == "VWMA"
    MASource := ta.vwma(src, maLevel)
else if typeMA == "WMA"
    MASource := ta.wma(src, maLevel)
else if typeMA == "DEMA"
    MASource := 2* ta.ema(src, maLevel) - ta.ema(ta.ema(src, maLevel), maLevel)

    

plot(MASource, color = color.new(color.orange,0))
barcolor((close>open) and (high-MASource) > ((high-low)*(percentage/100))? color.new(color.blue, 0) : na)
barcolor((close<open) and (MASource-low) > ((high-low)*(percentage/100))? color.new(color.yellow, 0) : na)

