SMA Spread as %
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ericdwyang

//@version=5
indicator("Spread as %")

// SMA Variables
smaInput = input(200, "Length")
sma = ta.sma(close, smaInput)

// Spread
spread = (close - sma)

// Spread as % of last close
spread2 = spread / sma

    
// TEST PLOT
// plot(spread)
// plot(sma)
// plot(close)

plot(spread2, title="Spread", color=spread2 >= 0 ? color.blue : color.orange, style=plot.style_columns)

