Turn off AssignPriceColor?

keithmj

New member
This seems like it should be easy, but I'm stuck. I simply want to be able to turn on or off the AssignPriceColor function with a user option.

I have a user option:
input show_price_bar_colors = yes;

later in the script I have the AssignPriceColor function. The below code somewhat worked, but it seems like it should be easier than this. I can turn off all the colors assigned by the if statements, but that last "else" that applies to all other conditions ends up painting all the bars.

Code:
AssignPriceColor(if (big_vol_price_up and show_price_bar_colors) then GlobalColor("big_vol_price_up") else if (big_vol_price_down and show_price_bar_colors) then GlobalColor("big_vol_price_down") else if (little_vol_price_up and show_price_bar_colors) then GlobalColor("little_vol_price_up") else if (little_vol_price_down and show_price_bar_colors) then GlobalColor("little_vol_price_down") else GlobalColor("normal_vol_price"))

How can I just toggle the AssignPriceColor function on and off so I either get the custom settings or the default chart settings?

Thanks!
 
Solution
This seems like it should be easy, but I'm stuck. I simply want to be able to turn on or off the AssignPriceColor function with a user option.

I have a user option:
input show_price_bar_colors = yes;

later in the script I have the AssignPriceColor function. The below code somewhat worked, but it seems like it should be easier than this. I can turn off all the colors assigned by the if statements, but that last "else" that applies to all other conditions ends up painting all the bars.

Code:
AssignPriceColor(if (big_vol_price_up and show_price_bar_colors) then GlobalColor("big_vol_price_up") else if (big_vol_price_down and show_price_bar_colors) then GlobalColor("big_vol_price_down") else if (little_vol_price_up and...
This seems like it should be easy, but I'm stuck. I simply want to be able to turn on or off the AssignPriceColor function with a user option.

I have a user option:
input show_price_bar_colors = yes;

later in the script I have the AssignPriceColor function. The below code somewhat worked, but it seems like it should be easier than this. I can turn off all the colors assigned by the if statements, but that last "else" that applies to all other conditions ends up painting all the bars.

Code:
AssignPriceColor(if (big_vol_price_up and show_price_bar_colors) then GlobalColor("big_vol_price_up") else if (big_vol_price_down and show_price_bar_colors) then GlobalColor("big_vol_price_down") else if (little_vol_price_up and show_price_bar_colors) then GlobalColor("little_vol_price_up") else if (little_vol_price_down and show_price_bar_colors) then GlobalColor("little_vol_price_down") else GlobalColor("normal_vol_price"))

How can I just toggle the AssignPriceColor function on and off so I either get the custom settings or the default chart settings?

Thanks!
I think I just figured it out... DUH

I can put each condition as a separate AssignPriceColor function instead of the big stupid "if" statement. Like this:

Code:
AssignPriceColor(if (big_vol_price_up and show_price_bar_color) then Global("big_vol_price_up) else Color.CURRENT;

AssignPriceColor(if (big_vol_price_down and show_price_bar_color) then Global("big_vol_price_doen) else Color.CURRENT;

etc, etc
 

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

This seems like it should be easy, but I'm stuck. I simply want to be able to turn on or off the AssignPriceColor function with a user option.

I have a user option:
input show_price_bar_colors = yes;

later in the script I have the AssignPriceColor function. The below code somewhat worked, but it seems like it should be easier than this. I can turn off all the colors assigned by the if statements, but that last "else" that applies to all other conditions ends up painting all the bars.

Code:
AssignPriceColor(if (big_vol_price_up and show_price_bar_colors) then GlobalColor("big_vol_price_up") else if (big_vol_price_down and show_price_bar_colors) then GlobalColor("big_vol_price_down") else if (little_vol_price_up and show_price_bar_colors) then GlobalColor("little_vol_price_up") else if (little_vol_price_down and show_price_bar_colors) then GlobalColor("little_vol_price_down") else GlobalColor("normal_vol_price"))

How can I just toggle the AssignPriceColor function on and off so I either get the custom settings or the default chart settings?

Thanks!

can simplify the original code by processing the inverse of the enable signal first, by adding a ! before it.
then it doesn't have to be 'and'ed' to every condition.

!show_price_bar_colors
that is read as,
not show_price_bar_colors , or

in other words, if it is false, then invert to be true and use default colors.

Code:
AssignPriceColor(
if !show_price_bar_colors then color.current
else if big_vol_price_up then GlobalColor("big_vol_price_up")
else if big_vol_price_down then GlobalColor("big_vol_price_down")
else if little_vol_price_up and then GlobalColor("little_vol_price_up")
else if little_vol_price_down then GlobalColor("little_vol_price_down")
else GlobalColor("normal_vol_price")
);


i think it is better to use just one instance of AssignPriceColor() in a study, that contains all of the conditions.

i am basing that on what i have seen when multiple loaded studies have that function in them.
if there are 2 studies loaded , that each have AssignPriceColor(), then the candle coloring will be wrong and unpredictable.

similar with assignbackgroundcolor().

similarly, if 2 strategies are loaded, the strategy arrows and lines will be wrong.
 
Solution
🤔 I didn't know that about multiple instances of the function, and I do have 2 studies loaded with similar functions. I guess I'll have to re-think my last post. Thanks for the heads up!
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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