# week_cross_on_day_00
def chartagg = getAggregationPeriod();
def chartmin = (chartagg/1000)/60;
#addlabel(1, "chartmin " + chartmin, color.magenta);
# ema20 , weekly
input avg1_agg = AggregationPeriod.week;
input avg1_len = 20;
input avg1_type = AverageType.EXPONENTIAL;
def ma1 = MovingAverage(avg1_type, close(period = avg1_agg), avg1_len);
input show_average_line = yes;
plot z1 = if show_average_line then ma1 else double.nan;
z1.SetDefaultColor(Color.yellow);
# x.setlineweight(1);
z1.hidebubble();
# check if avg1_agg is a multiple of chart agg
def aggok = ((avg1_agg % chartagg) == 0 );
addlabel(!aggok, "<<<< Secondary agg time is not a multiple of chart time. data may not be represented correctly >>>>", color.cyan);
def pricex = if close crosses above ma1 then 1
else if close crosses below ma1 then -1
else 0;
input change_bar_colors_on_crossing = yes;
# if you want red and green candles, remove # from the next line and add it to following one
#assignpricecolor(if !change_bar_colors_on_crossing then color.current else if pricex == 1 then color.green else if pricex == -1 then color.red else color.current);
assignpricecolor(if !change_bar_colors_on_crossing then color.current else if pricex == 1 then color.cyan else if pricex == -1 then color.yellow else color.current);
input show_wedges_on_crossing = yes;
plot wup = if pricex == 1 then 1 else 0;
wup.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_up);
wup.SetDefaultColor(Color.cyan);
wup.setlineweight(3);
plot wdwn = if pricex == -1 then 1 else 0;
wdwn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_down);
wdwn.SetDefaultColor(Color.yellow);
wdwn.setlineweight(3);
# -----------------------------
# test bar color
#assignpricecolor(color.yellow);
input test2 = no;
addchartbubble(test2 and pricex <> 0, low, pricex , color.cyan, no);
# -----------------------------
# https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/AverageType
# EXPONENTIAL
# HULL
# SIMPLE
# WEIGHTED
# WILDERS
#input avg2_len = 20;
#input avg2_type = AverageType.EXPONENTIAL;
#def ma2 = MovingAverage(avg2_type, close, avg2_len);
#
#plot z2 = ma2;
#z2.SetStyle(Curve.MEDIUM_DASH);
#z2.SetDefaultColor(Color.cyan);
## x.setlineweight(1);
#z2.hidebubble();
#