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

#### SleepyZ

##### Well-known member
VIP
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);``````

#### scott69

##### Active member
@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

##### Well-known member
VIP
@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.

#### scott69

##### Active member
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);``````

#### offshore

##### New member
@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

##### Well-known member
VIP
@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);``````

#### offshore

##### New member
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.

#### SleepyZ

##### Well-known member
VIP
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);``````

#### offshore

##### New member
Fantastic Sleepy thanks so much and happy Thanksgiving

## 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?