# bongo_stacked_rsis
#--------------------
#https://usethinkscript.com/threads/bongo-indicator-for-thinkorswim.14473/#post-124524
#Bongo Indicator For ThinkOrSwim
#Bongo designed by a group of traders at an HGSI seminar.
#Mod: atcsam - User contol & price % from MA
def na = double.nan;
def bn = barnumber();
input averagetype = AverageType.SIMPLE;
input length = 8;
input RSI_1 = 8;
input RSI_2 = 14;
input RSI_3 = 19;
Input ShowLabel = Yes;
DefineGlobalColor("BongoUP",Color.Green);
DefineGlobalColor("BongoDn",Color.RED);
def r1 = RSI(length = RSI_1);
def r2 = RSI(length = RSI_2);
def r3 = RSI(length = RSI_3);
plot MA1 = MovingAverage(averagetype, close, length);
# calc % chg
def machg = ma1 - ma1[1];
def machgper = 100*machg/ma1[1];
def Up = If((r1 > r2) and (r2 > r3) and (close > MA1), 1, 0);
def Dn = If((r1 < r2) and (r2 < r3) and (close < MA1), 1, 0);
# use same var at end. then no white sections. cont color
def BongoUp2 = if Up then 1 else if Dn then 0 else BongoUp2[1];
def BongoDn2 = if Dn then 1 else if Up then 0 else BongoDn2[1];
MA1.AssignValueColor(if BongoUp2 then GlobalColor("BongoUp") else if BongoDn2 then GlobalColor("BongoDn") else Color.WHITE);
MA1.SetLineWeight(1);
def per = Round( 100* (Close-ma1)/ma1,1);
#--------------------------------------
# cnt bars since rev
def cnt = if bn == 1 then 0
else if BongoUp2 and BongoDn2[1] then 1
else if Bongodn2 and Bongoup2[1] then -1
else if cnt[1] > 0 then cnt[1] + 1
else if cnt[1] < 0 then cnt[1] - 1
else cnt[1];
AddLabel(
ShowLabel,
cnt,
if BongoUp2 then Color.GREEN
else if BongoDn2 then Color.RED
else Color.WHITE
);
addlabel(yes, per +" %", (if per >0 then color.Light_green else if per < 0 then color.light_red else color.light_gray));