#cross_above_more_than1_lower_00
#https://usethinkscript.com/threads/if-when-then-statement.14511/
#...so that when the histogram crosses above 0, an arrow plots but not UNTIL the histogram is greater than 1. It may be the second or third histogram bar
#----------------------------
declare lower;
def na = double.nan;
def bn = barnumber();
#/////////////////////////////////
# test data
# difference of 2 avgs
input avg1_type = AverageType.SIMPLE;
input avg1_price = close;
input avg1_len = 9;
def ma1 = MovingAverage(avg1_type, avg1_price, avg1_len);
input avg2_type = AverageType.SIMPLE;
input avg2_price = close;
input avg2_len = 50;
def ma2 = MovingAverage(avg2_type, avg2_price, avg2_len);
def diff = ma1 - ma2;
#input show_test_averages = no;
#plot t1 = if show_test_averages then ma1 else na;
#plot t2 = if show_test_averages then ma2 else na;
# end test data
#/////////////////////////////////
#def signal1 = line;
def signal1 = diff;
#def signal2 = ....
#def signal3 = ...
#------------------------
input min_difference = 1.0;
# conditions , sequencial advancing , one after the other
def cond1 = signal1 crosses above 0;
def cond2 = signal1 crosses below 0;
def cond3 = signal1 > min_difference;
def cond4 = signal1 < -min_difference;
# conditions , cancel
#def cancel = signal1 crosses below 0;
def cancel1 = cond2;
def cancel2 = cond1;
# create vars, that count up, with each new condition (0,1,2)
def tup =
if bn == 1 then 0
else if cancel1 then 0
else if tup[1] == 0 and cond1 and cond3 then 2
else if tup[1] == 0 and cond1 then 1
else if tup[1] == 1 and cond3 then 2
else tup[1];
def trigger1 = (tup == 2 and tup[1] != 2);
def tdwn =
if bn == 1 then 0
else if cancel2 then 0
else if tdwn[1] == 0 and cond2 and cond4 then 2
else if tdwn[1] == 0 and cond2 then 1
else if tdwn[1] == 1 and cond4 then 2
else tdwn[1];
def trigger2 = (tdwn == 2 and tdwn[1] != 2);
DefineGlobalColor(color = Color.white, name = "trig_bar");
plot z = if bn == 1 then na else diff;
z.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
z.AssignValueColor(if bn == 1 then color.gray else if trigger1 or trigger2 then GlobalColor("trig_bar") else if diff > 0 then color.green else color.red);
z.SetLineWeight(3);
z.HideBubble();
plot zup = if trigger1 then -0.1 else na;
zup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zup.SetDefaultColor(Color.CYAN);
zup.SetLineWeight(2);
zup.HideBubble();
plot zdwn = if trigger2 then 0.1 else na;
zdwn.SetPaintingStrategy(PaintingStrategy.ARROW_down);
zdwn.SetDefaultColor(Color.CYAN);
zdwn.SetLineWeight(2);
zdwn.HideBubble();
#------------------------------
input test_vert_lines = no;
addverticalline(test_vert_lines and (cond1 or cond3), "cond 1", Color.CYAN);
addverticalline(test_vert_lines and (cond2 or cond4), "cond 2", Color.yellow);
#