Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
I want a line plotted across the chart that shows my average cost for the charted item. If the entry cost is less than the current price (I'm positive p/l) color the line green, else color it red.
The code below errors on the line:
posline.setDefaultColor(if price > (LastPrice) then Color.LIGHT_RED else Color.Green );
I have searched over two hours for a this simple requirement, to assign a color based on a decision, instead of hard coding the defaultcolor. I need it to be defaultcolor because I want the whole bar to be plotted the one color.
Can you help answer these questions from other members on NexusFi?
In order to apply conditional color to a plot you need to use AssignValueColor. As you pointed out, just using that with your previous logic resulted in a the color switching as last price changes across the chart. To avoid that, I've changed the logic to get the last price from the last bar. I hard coded the average price, but thats just to provide some test value instead of a real average cost. I think this achieves what you were looking for.