# Change daily bar color from something that happen on weekly?

#### mbarcala

##### Active member
I would like to know if the price crosses above/below the ema20 on weekly, I can have those five day bars changing color on daily chart?

Last edited:
Solution
I would like to know if the price crosses above/below the ema20 on weekly, I can have those five day bars changing color on daily chart?

this will change the color of the bars, that cross a higher aggregation average line.
only the bar that crosses the line is changed.
will draw small arrows, wedges, also.

Code:
``````# 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...``````
I would like to know if the price crosses above/below the ema20 on weekly, I can have those five day bars changing color on daily chart?

this will change the color of the bars, that cross a higher aggregation average line.
only the bar that crosses the line is changed.
will draw small arrows, wedges, also.

Code:
``````# 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();
#``````

weekly average line plotted on a 2hr chart

an error message pops up in a label if the Secondary agg time is not a multiple of the chart time

87k+ Posts
138 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?