###SLIM
#Mr Slim Miller at askSLIM dot com
#SlimRibbonCustom_markos9-7-18
input price300 = close;
input superfast_length = 8;
input fast_length = 13;
input slow_length = 21;
input displace300 = 0;
def mov_avg8 = ExpAverage(price300[-displace300], superfast_length);
def mov_avg13 = ExpAverage(price300[-displace300], fast_length);
def mov_avg21 = ExpAverage(price300[-displace300], slow_length);
#moving averages
def Superfast = mov_avg8;
def Fast = mov_avg13;
def Slow = mov_avg21;
def buy = mov_avg8 > mov_avg13 and mov_avg13 > mov_avg21 and low > mov_avg8;
def stopbuy = mov_avg8 <= mov_avg13;
def buynow = !buy[1] and buy;
def buysignal2 = CompoundValue(1, if buynow and !stopbuy then 1 else if buysignal2[1] == 1 and stopbuy then 0 else buysignal2[1], 0);
def sell = mov_avg8 < mov_avg13 and mov_avg13 < mov_avg21 and high < mov_avg8;
def stopsell = mov_avg8 >= mov_avg13;
def sellnow = !sell[1] and sell;
def sellsignal2 = CompoundValue(1, if sellnow and !stopsell then 1 else if sellsignal2[1] == 1 and stopsell then 0 else sellsignal2[1], 0);
plot Colorbars = if buysignal2 ==1 then 1 else if sellsignal2 ==1 then 2 else if buysignal2 ==0 or sellsignal2==0 then 3 else 0;
colorbars.hide();
Colorbars.definecolor("Buy_Signal_Bars", color.Green);
Colorbars.definecolor("Sell_Signal_Bars", color.red);
Colorbars.definecolor("Neutral", color.gray);
AddLabel(yes, if Colorbars ==1 then "SLIM:Up" else "SLIM:Down",
if Colorbars ==2 then Color.RED else Color.GREEN);