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
Lifetime
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);
 
Solution

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
Lifetime
@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
Lifetime
@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);
 

SleepyZ

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

http://tos.mx/KzWNosI heres link to chart.

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
Screenshot-2022-11-24-081523.png
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);
 

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.
Top