input length = 14;
input trigger1 = 148;
input trigger2 = 0;
input arrowdisplacer = .0001; #Change by .001 increments to move arrows
input showallarrows = yes; #show only one arrow per direction or all
def price = close + low + high;
def linDev = LinDev(price, length);
def CCI = if linDev == 0 then 0 else (price - Average(price, length)) /
linDev / 0.015;
def below150 = if CCI[1] > -trigger1 and CCI < -trigger1 then 1 else if below150[1] == 1 and CCI < -trigger2 then 1 else 0;
def above150 = if CCI[1] > trigger1 and CCI < trigger1 then 1 else if above150[1] == 1 and CCI > trigger2 then 1 else 0;
plot ArrowUp = if (below150[1] == 1 and below150 == 0 and showallarrows == yes) then low * (1 - arrowdisplacer) else Double.NaN;
ArrowUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
ArrowUp.SetDefaultColor(Color.YELLOW);
ArrowUp.SetLineWeight(3);
plot ArrowDn = if showallarrows and above150[1] == 1 and above150 == 0 then high * (1 + arrowdisplacer) else Double.NaN;
ArrowDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ArrowDn.SetDefaultColor(Color.YELLOW);
ArrowDn.SetLineWeight(3);
AddLabel(yes, "CCI: " + Round(CCI, 0), if CCI > 0 then if CCI[1] > CCI then Color.DARK_GREEN else Color.GREEN else if CCI[1] < CCI then Color.DARK_RED else Color.RED);
input n = 4;
def n1 = n + 1;
AddChartBubble(!IsNaN(close[n1]) and IsNaN(close[n]), close[n1], "CCI: " + Round(CCI[n1], 0), if CCI[n1] > 0 then if CCI[n1 + 1] > CCI[n1] then Color.DARK_GREEN else Color.GREEN else if CCI[n1 + 1] < CCI[n1] then Color.DARK_RED else Color.RED, yes);
#### Prior Arrowup data
input bubbleupdown = 5;
def prior = GetMaxValueOffset(!IsNaN(ArrowUp[1]), length = 100) ;
AddChartBubble(!IsNaN(ArrowUp), low - TickSize() * bubbleupdown, "Last Arrowup \n" + prior + " bars ago", Color.YELLOW, no);
AddLabel(1, "#Arrowup in Last 15 bars =" + Sum(!IsNaN(ArrowUp), 15), Color.YELLOW);
input debug = yes;
plot bn = if !debug then double.nan else BarNumber();
bn.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
#