% up/down from SMA Alerts
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Phoo222

//@version=5
indicator(title="% up/down from SMA Alerts", shorttitle="% Alert", overlay=true, timeframe="")


//SMA inputs
len = input.int(20, minval=1, title="Length")
src = input(close, title="Source")
offset = input.int(title="Offset", defval=0)
SMA = ta.sma(src, len)
perAway = input.int(10, "% value", minval=1, maxval=300)

plot(SMA, title="SMA", offset=offset)


PercentInc = SMA + (SMA * perAway / 100)
PercentDec = SMA - (SMA * perAway / 100)

plot(PercentInc, title="% Up line")
plot(PercentDec, title="% Down Line")


//if current price increase x% from SMA then Alert trigger
alertcondition(close >= PercentInc, title='% up SMA', message='% up from SMA')

//if current price decrease x% from SMA then Alert trigger
alertcondition(close <= PercentDec, title='% down SMA', message='% down from SMA')

