# 1.5x average bar size

#### Archie

##### New member
Does anyone know how to make a candle change colors if its 1.5x the average size of the last 15 bars of any time denomination? I can supply the code for the average bar part. I just want all candles to turn yellow if they are 1.5 times the size

Solution
Does anyone know how to make a candle change colors if its 1.5x the average size of the last 15 bars of any time denomination? I can supply the code for the average bar part. I just want all candles to turn yellow if they are 1.5 times the size

Try this

Code:
def cond = (high - low) > Average((high - low), 15) * 1.5;

input usepricecolor = yes;
AssignPriceColor(if !usepricecolor
then Color.CURRENT else
if cond then Color.YELLOW
else Color.CURRENT);
Does anyone know how to make a candle change colors if its 1.5x the average size of the last 15 bars of any time denomination? I can supply the code for the average bar part. I just want all candles to turn yellow if they are 1.5 times the size

Try this

Code:
def cond = (high - low) > Average((high - low), 15) * 1.5;

input usepricecolor = yes;
AssignPriceColor(if !usepricecolor
then Color.CURRENT else
if cond then Color.YELLOW
else Color.CURRENT);

@SleepyZ , thanks for this. I just used your code to "color" the candles after they meet other multiple criteria. I also have two conditions and two colors. I am using a white background with "current" candles white also, so when the criteria is met, they appear and really stand out. Perfect !!

To clarify, I have two conditions, two colors, and each condition has multiple criteria.

@SleepyZ , thanks for this. I just used your code to "color" the candles after they meet other multiple criteria. I also have two conditions and two colors. I am using a white background with "current" candles white also, so when the criteria is met, they appear and really stand out. Perfect !!

To clarify, I have two conditions, two colors, and each condition has multiple criteria.

You can include the additional colors into the assignpricecolor() function from the two conditions. The 'current' color is the default color used for your candles. Multiple assignpricecolor statements will not work properly together. Just use one statement.

Yes, thanks, this is how I handles it

Code:
AssignPriceColor(if !ColorCandles
then Color.CURRENT else
if CondUp then Color.CYAN
else if CondDown then Color.MAGENTA else Color.Current);

@SleepyZ This indicator is amazing, but sometimes it doesn't activate when i open my tos platform. I have to go in and tinker with variables in the code and keep hitting apply to hope the indicator works. Sometimes i open my platform and its working fine. Do you know why I could be having these issues?

@SleepyZ This indicator is amazing, but sometimes it doesn't activate when i open my tos platform. I have to go in and tinker with variables in the code and keep hitting apply to hope the indicator works. Sometimes i open my platform and its working fine. Do you know why I could be having these issues?

Not sure without some example. A lightly traded symbol with gaps or missing bars might cause a problem.

I have included a test bubble code to the original that may help analyze any problem. Look for a N/A in the bubble possibly and see which of the 3 variables are affected.

Let me know the specifics of the problem when it occurs along with a chart image.

Ruby:
def cond = (high - low) > Average((high - low), 15) * 1.5;

input usepricecolor = yes;
AssignPriceColor(if !usepricecolor
then Color.CURRENT else
if cond then Color.YELLOW
else Color.CURRENT);

input test = yes;
AddChartBubble(test, low * .9994, "C  " +cond + "\nHL " + (high - low) + "\nA " + (Average((high - low), 15) * 1.5), if cond then Color.YELLOW
else Color.gray, no);

So have been using it on emini, so no problem with light trading there... when i changed the parameters a bit i got the bars to stop getting painted, so it could be a problem with paint function as none of the bubbles have NA in them.

So have been using it on emini, so no problem with light trading there... when i changed the parameters a bit i got the bars to stop getting painted, so it could be a problem with paint function as none of the bubbles have NA in them.

Thanks for the shared chart. The problem appears to be that you had multiple studies (2- Tails and AvgBO2) that used assignpricecolor, causing a conflict. TOS informs you of this by the icon in the upper left corner of the chart. See the red circled area in the image below in the upper panel, which is your shared chart. The lower panel is the revised code combining those conflicting scripts into one script, AvgBO2 below, thereby eliminating the conflict. To emphasize the coloring in the lower panel, I made all of the candles not meeting the painting color conditions to then be colored gray.

Delete the Tails script and use the combined new code below in place of AvgBO2
New combined code
Ruby:
def Bull =
Close > Open and
Open - Low > High - Open;
def Bear =
Close < Open and
High - Open > Open - Low
;
#assignPriceColor(
#    if Bull then Color.dark_green
#    else if Bear then Color.dark_red
#    else Color.Current
#);
def cond = (high - low) > Average((high - low), 10) * 1.7;

input usepricecolor = yes;
AssignPriceColor(if !usepricecolor
then Color.CURRENT else
if cond then Color.YELLOW
else if Bull then Color.dark_green
else if Bear then Color.dark_red
else Color.current);

input test = no;
AddChartBubble(test, low * .9994, "C  " + cond + "\nHL " + (high - low) + "\nA " + (Average((high - low), 15) * 1.5), if cond then Color.YELLOW
else Color.GRAY, no);

Fantastic Sleepy thanks so much and happy Thanksgiving

@SleepyZ can i add a condition in the code to cap the value to say 2.0x avg bar range of last amount of bars? so it would only paint bars between 1.5-2X avg size of last 10 bars?

@SleepyZ can i add a condition in the code to cap the value to say 2.0x avg bar range of last amount of bars? so it would only paint bars between 1.5-2X avg size of last 10 bars?

Here are just 2 of the ways you can do that. You can choose a combination of the 2 or some variation:

1. Create an input named factor, defaulted to 1.5. Then use a Hint at the input screen, visible by clicking the '?' icon.
a. Add Min(factor, 2.0) in the cond def. You could create an input factor_max for 2.0, and replace min(factor, 2.0) with min(factor, factor_max).
Code:
input factor     = 1.5;#Hint factor: limited to 2.0
input length     = 10;
def cond         = (high - low) > Average((high - low), length) * min(factor, 2.0);

2. Use the Assert() function. When you input a value for factor exceeding your 2.0 cap, the '!' icon will appear in the upper left corner of the script, disclosing the error. It will require you to reduce the factor to less than or equal to 2.0 for study to appear.
Code:
input factor = 1.5;#Hint factor: limited to 2.0
Assert(factor <= 2.0, "Factor cannot exceed 2.0. Enter a value less than 2.0 @ input factor");
input length = 10;
def cond     = (high - low) > Average((high - low), length) * factor;

Below is the full code with option 1 above.

Ruby:
def Bull =
close > open and
open - low > high - open;
def Bear =
close < open and
high - open > open - low
;
#assignPriceColor(
#    if Bull then Color.dark_green
#    else if Bear then Color.dark_red
#    else Color.Current
#);

input factor     = 1.5;#Hint factor: limited to 2.0
input length     = 10;
def cond         = (high - low) > Average((high - low), length) * min(factor, 2.0);

input usepricecolor = yes;
AssignPriceColor(if !usepricecolor
then Color.CURRENT else
if cond then Color.YELLOW
else if Bull then Color.DARK_GREEN
else if Bear then Color.DARK_RED
else Color.CURRENT);

input test = yes;
AddChartBubble(test, low * .9994, "C  " + cond + "\nHL " + (high - low) + "\nA " + (Average((high - low), length) * Min(factor, 2.0)) + "\nF " + Min(factor, 2.0), if cond then Color.YELLOW
else Color.GRAY, no);

Last edited:
That works great...thanks again Sleepy

Hey @SleepyZ I was messing around with the code from above with Option 1 and I cant seem to get the code to Cap the limit to 2.0x avg of last 10 bars... I changed the code to lower the cap as well and it still paints any and all bars even if they are over 2.0x, 2.5x, whatever. So i was wondering what i could change in the code to make that cap work?
Thanks

87k+ Posts
306 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?