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
Ic0Ytvp.jpg



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

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
339 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

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?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top