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

//@version=4
study("Complete MA Division", max_bars_back = 4999, overlay=false)

x = input(100, 'MA1')
y = input(200, 'MA2')
curve_smoothing = input(2, 'Curve Smoothing')
slope_smoothing = input(14, 'Slope Smoothing')
f_slope(x) =>
    slopePeriod = 1
    (x - x[slopePeriod]) / slopePeriod
    
period = close
count = cum(1+1==2 ? 1 : 0)
div = x/y
// We need to calculate the moving average before the inputs 
// so we have to count each bar until the period is met
ma1 = sma( period, count<y?round((count*div))==0?1:round(count*div):x)
ma2 = sma( period, count<y?round(count):y)
curve = sma(ma1/ma2,curve_smoothing)



slope_curve = sma(f_slope(curve),slope_smoothing)
slope_curve_rsi = (rsi(slope_curve,1)/100)-0.5

plot(curve, color=slope_curve>slope_curve[1]?color.green:color.red, linewidth=4)
//plot(slope_curve_rsi, color=color.white, style=plot.style_stepline)






