Question about coloring bars using takevaluecolor

I'm trying to colorcode volume bars based on whether they are up or down from last bar, 2 last bars etc, and if I'm using AssignValueColor. I'm using define color for most of them, but I want the a bar that is equal to value of last bar to be colored same as last bar. Is that possible somehow with TakeValueColor?
 
Solution
@tibby42 If I understand correctly, it seems as if using AssignValueColor() would work fine for your needs. Here is an example of coding two different requirements for one color using "or" -
Code:
plot v = volume;
v.assignvaluecolor(if v > v[1] or  v == v[1] then color.green else color.red);

If that does not fit your needs, you can use TakeValueColor() by placing it in the AssignValueColor() function -
Code:
plot c = close;
c.setdefaultcolor(color.yellow);
plot v = volume;
v.assignvaluecolor(c.takevaluecolor());
@tibby42 If I understand correctly, it seems as if using AssignValueColor() would work fine for your needs. Here is an example of coding two different requirements for one color using "or" -
Code:
plot v = volume;
v.assignvaluecolor(if v > v[1] or  v == v[1] then color.green else color.red);

If that does not fit your needs, you can use TakeValueColor() by placing it in the AssignValueColor() function -
Code:
plot c = close;
c.setdefaultcolor(color.yellow);
plot v = volume;
v.assignvaluecolor(c.takevaluecolor());
 
Solution

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

Thanks for the feedback. I was overtired and decidedly inarticulate that night. I’m trying to assign color of a bar equal to last bar especially by color of last bar - like if last bar was white and this bar is equal then color.white.. I don’t know if that’s possible really so I decided to just go with leaving equal the same color as up from last bar. It’s handy to know besting works for those commands. Thank you.
 
I’m trying to assign color of a bar equal to last bar especially by color of last bar - like if last bar was white and this bar is equal then color.white..
@tibby42 To do this, all you need to do is make sure the criteria you are using for coloring the last bar white is present on the last candle. Try something like
Code:
def variable = here put whatever criteria you are using to color the last candle as a boolean 1 else 0 statement;
( example ---> def variable = if close > open then 1 else 0; )

and then after the plot, do
yourplot.assignvaluecolor(if variable[1] == 1 then color_the_bar_the_same_color else color_it_this);

Something like that. There's more than one way to do it - you could also do everything in the plot statement. Hope this helps.
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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