• LIMITED TIME ONLY: Take $40 off VIP with code: BTD40.

Change daily bar color from something that happen on weekly?

mbarcala

Active member
VIP
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...

halcyonguy

Well-known member
VIP
Lifetime
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

Similar threads

Top