AssignValueColor to a Plot according to the Candle or Price Color?

ezcwb

New member
Hello!
I have been using the community for a while with all the scripts around already,
But it is my first time posting requesting help of something I am trying to do:

I'm having issues changing the color of a plot according to a conditional (which would be price).
I'm well concerned that the "AssignValueColor" shall be used for this but I am having a problem on the constant to retrieve the value.

#Line.AssignValueColor( if Line > "x" then Color.UPTICK else Color.DOWNTICK);

Full code:

Code:
input price = close;
input offset = 0;
input length = 0;

def sma = SimpleMovingAvg(price, 1, length);

rec line = if IsNaN(sma) then line[1] else sma[offset];
 
plot priceline = if IsNaN(sma) then line else Double.NaN;
priceline.setpaintingStrategy(paintingStrategy.DASHES);
priceline.setdefaultColor(Color.White);
#priceline.AssignValueColor( if priceline > "open?/lastclose?" then Color.UPTICK else Color.DOWNTICK);

As simple as it is.
Being "X" the candle open ( or last candle close, no problem)
Basically I just want the line plotted above to be green or red, same color as the candle actually, or the price bubble on the right axis itself.
But nothing I do seems to work. I've tried from def, to input, to close, or close - close[1], price = close, up to Set "Up" and "Down" colors an so on a lot of different stuff but nothing seems to work.
The condition actually works, if I manually add a price under "X" I can see line changing according to up or down that value
(but it is not something I'll be doing for every candle of course lol I just tried to see if the other arguments were right)

So, any clue, anyone?
Thank you in advance!
Appreciate you guys and this helpful community.
 
Last edited:
Solution
Hello, thank you for you answer. And that for the heads up on </> I'll update the post.
I didn't post the rest of the code bc honestly there's nothing much left more than that lol
It's just a price line, that moves with current price (I even tried CURRENT from bars but that didn't work as well)


Code:
input price = close;
input offset = 0;
input length = 0;

def sma = SimpleMovingAvg(price, 1, length);

rec line = if IsNaN(sma) then line[1] else sma[offset];
 
plot priceline = if IsNaN(sma) then line else Double.NaN;
priceline.setpaintingStrategy(paintingStrategy.DASHES);
priceline.setdefaultColor(Color.White);
#priceline.AssignValueColor( if priceline > "open?/lastclose?" then Color.UPTICK else Color.DOWNTICK);

I would like that to...
Hello!
I have been using the community for a while with all the scripts around already,
But it is my first time posting requesting help of something I am trying to do:

I'm having issues changing the color of a plot according to a conditional (which would be price).
I'm well concerned that the "AssignValueColor" shall be used for this but I am having a problem on the constant to retrieve the value.

#Line.AssignValueColor( if Line > "x" then Color.UPTICK else Color.DOWNTICK);

As simple as it is.
Being "X" the candle open ( or last candle close, no problem)
Basically I just want the line plotted above to be green or red, same color as the candle actually, or the price bubble on the right axis itself.
But nothing I do seems to work. I've tried from def, to input, to close, or close - close[1], price = close, up to Set "Up" and "Down" colors an so on a lot of different stuff but nothing seems to work.
The condition actually works, if I manually add a price under "X" I can see line changing according to up or down that value
(but it is not something I'll be doing for every candle of course lol I just tried to see if the other arguments were right)

So, any clue, anyone?
Thank you in advance!
Appreciate you guys and this helpful community.
hello and welcome

it is near impossible to help someone fix their code, when they only post 1 code line.
we don't know what line =.
we don't know what x =.

don't be bashfull, post a study you are working on, working or not, and someone will help.

when you post code, click on the icon at the top, </> then a window will open , for you to paste in the code.
 

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

hello and welcome

it is near impossible to help someone fix their code, when they only post 1 code line.
we don't know what line =.
we don't know what x =.

don't be bashfull, post a study you are working on, working or not, and someone will help.

when you post code, click on the icon at the top, </> then a window will open , for you to paste in the code.

Hello, thank you for you answer. And that for the heads up on </> I'll update the post.
I didn't post the rest of the code bc honestly there's nothing much left more than that lol
It's just a price line, that moves with current price (I even tried CURRENT from bars but that didn't work as well)


Code:
input price = close;
input offset = 0;
input length = 0;

def sma = SimpleMovingAvg(price, 1, length);

rec line = if IsNaN(sma) then line[1] else sma[offset];
 
plot priceline = if IsNaN(sma) then line else Double.NaN;
priceline.setpaintingStrategy(paintingStrategy.DASHES);
priceline.setdefaultColor(Color.White);
#priceline.AssignValueColor( if priceline > "open?/lastclose?" then Color.UPTICK else Color.DOWNTICK);

I would like that to be colored as the current price bubble or candle body (red or green) on the timeframe currently active (whichever is selected).
Tried posting a pic of the outcome but cant add images.
Currently working, its just the color custom thing.
Thanks!
 
Hello, thank you for you answer. And that for the heads up on </> I'll update the post.
I didn't post the rest of the code bc honestly there's nothing much left more than that lol
It's just a price line, that moves with current price (I even tried CURRENT from bars but that didn't work as well)


Code:
input price = close;
input offset = 0;
input length = 0;

def sma = SimpleMovingAvg(price, 1, length);

rec line = if IsNaN(sma) then line[1] else sma[offset];
 
plot priceline = if IsNaN(sma) then line else Double.NaN;
priceline.setpaintingStrategy(paintingStrategy.DASHES);
priceline.setdefaultColor(Color.White);
#priceline.AssignValueColor( if priceline > "open?/lastclose?" then Color.UPTICK else Color.DOWNTICK);

I would like that to be colored as the current price bubble or candle body (red or green) on the timeframe currently active (whichever is selected).
Tried posting a pic of the outcome but cant add images.
Currently working, its just the color custom thing.
Thanks!


you are trying to determine a variable value, after the last bar, where there is no price data.

you need way to,
...find the last bar, and define the condition of it.
...then keep this value during the expansion area, the area after the last visible bar.

just like you are doing in your line = ... formula

in this formula
def lastdir =
this part keeps a value from the last bar
else if isnan(close) then lastdir[1]


Ruby:
# colorline_bycandle_00
#def na = double.nan;
def bn = barnumber();

# true on the last bar
def lastbar = !isnan(close[0]) and isnan(close[-1]);

# determine direction of last bar
def lastdir = if bn ==  1 then 0
 else if isnan(close) then lastdir[1]
 else if (close > open) then 1
 else if (close < open) then -1
 else lastdir[1];

input price = close;
input offset = 0;
input length = 0;

def sma = SimpleMovingAvg(price, 1, length);
def line = if IsNaN(sma) then line[1] else sma[offset];
 plot priceline = if IsNaN(sma) then line else Double.NaN;

# this looks like a solid line zoomed out
priceline.setpaintingStrategy(paintingStrategy.DASHES);

# this always looks dashed
#priceline.SetStyle(Curve.MEDIUM_DASH);

#priceline.setdefaultColor(Color.White);
priceline.AssignValueColor(if lastdir > 0 then Color.UPTICK else if lastdir < 0 then Color.DOWNTICK else color.gray);
#priceline.AssignValueColor(if lastdir > 0 then Color.green else if lastdir < 0 then Color.red else color.gray);


input test1 = no;
addchartbubble( test1, line*0.995,
lastdir
, (if lastdir > 0 then Color.UPTICK else if lastdir < 0 then Color.DOWNTICK else color.gray), no);
#
 
Solution

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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