How to separate plot function from addlabel function?

Mutagenix

New member
Working with this custom watchlist column as a "confirmation stack"

I'm trying to keep my x plot to be able to sort the column numerically.

I can't figure out how to to add a color-coded "U" or "D" in front of the x plot without
disabling numerical sorting. What am I missing here?

How can I use AddLabel without affecting Plot X?


Code:
plot x = Round(100 * ((close/ open) - 1), 1);

addLabel(yes, if open>close[1] then x + "U" else x + "D");

x.AssignValueColor( if x < 0 then Color.ORANGE else Color.cyan);

AssignBackgroundColor(if close>open and close[1]>open[1] then color.blue else if close<open and close[1]<open[1] then color.red else color.black);

Thanks all
 
Last edited:
Solution
Working with this custom watchlist column as a "confirmation stack"

I'm trying to keep my x plot to be able to sort the column numerically.

I can't figure out how to to add a color-coded "U" or "D" in front of the x plot without
disabling numerical sorting. What am I missing here?

How can I use AddLabel without affecting Plot X?

you can't.

------------------------------------
watchlist column study
zzsort1b
http://tos.mx/QTKRi7U

i have always thought only one output function should be used in a column. i see your study does work, but by adding a label, the combined outputs are treated like text and sorted like it.

disabled the plot and put everything in 1 label.
added color to a label, which is the font color. i...
Working with this custom watchlist column as a "confirmation stack"

I'm trying to keep my x plot to be able to sort the column numerically.

I can't figure out how to to add a color-coded "U" or "D" in front of the x plot without
disabling numerical sorting. What am I missing here?

How can I use AddLabel without affecting Plot X?

you can't.

------------------------------------
watchlist column study
zzsort1b
http://tos.mx/QTKRi7U

i have always thought only one output function should be used in a column. i see your study does work, but by adding a label, the combined outputs are treated like text and sorted like it.

disabled the plot and put everything in 1 label.
added color to a label, which is the font color. i changed orange to white, to be easy to read.


when you use a label in a column, it changes the data to text.
numbers are sorted right to left.
text is sorted left to right.

with text , all the values have to have the desired characters in the correct location.
if a decimal point, or a + is missing, or a trailing 0 is gone, it won't sort correctly.

added several if thens to fill in the missing characters.

i looked up ascii codes and found that a comma is between a + and a -.
using a comma for 0.0 keeps them sorted correctly.

used absolute value of data and added a sign separately, because some numbers needed a leading 0 added.
added a trailing 0 as needed.

this is based off of rounding to 0.0.
if the rounding number is changed from 1 to 2, another trailing 0 if-then formula will have to be added.
if the rounding number is changed from 1 to 0, the existing if-then formula will have to be removed.


Ruby:
# zzsort1

#plot x = Round(100 * ((close/ open) - 1), 1);
#x.AssignValueColor( if x < 0 then Color.ORANGE else Color.cyan);

def x = Round(100 * ((close/ open) - 1), 1);

def int = ( x % 1 == 0);

#addLabel(yes, if open>close[1] then x + "U" else x + "D", if x < 0 then Color.ORANGE else Color.cyan);

# color is the font color
addLabel(yes,
 (if open>close[1] then "U " else "D ") +
 (if x > 0 then "+" else if x < 0 then "-" else ",") +
 (if absvalue(x) < 10 then "0" else "") +
 absvalue(x) +
 (if int then ".0" else "")
, if x < 0 then Color.white else Color.cyan);

AssignBackgroundColor(if close>open and close[1]>open[1] then color.blue else if close<open and close[1]<open[1] then color.red else color.black);
#


psaqHCa.jpg


--------------------------------------------------


ref:
for sorting 0.0 in columns, find a character between + and - . comma is between them.

+ 43
, 44 comma
- 45

ascii codes
https://www.alpharithms.com/ascii-table-512119/
hal_col hal_sort
 
Last edited:
Solution
Anyone have a work around code for when sorting % changes in watchlists to be correct alphanumeric
I have found some info about this issue but can't seem to make it happen for me, thanks ahead

when I do AsPercent(PctChg) it sorts something like this
6%
11.2%
1.3%

When I do absvalue(PctChg it will sort correct but wrong format
.112
.06
.013

What do I need to do for the % format and correct sorting?
 
Anyone have a work around code for when sorting % changes in watchlists to be correct alphanumeric
I have found some info about this issue but can't seem to make it happen for me, thanks ahead

when I do AsPercent(PctChg) it sorts something like this
6%
11.2%
1.3%

When I do absvalue(PctChg it will sort correct but wrong format
.112
.06
.013

What do I need to do for the % format and correct sorting?

when sorting text, you need all data to have the same quantity of characters. if some are missing then add them in.

this uses several if thens to add characters as needed, so text data sorts like a number, in a column.
https://usethinkscript.com/threads/...tion-from-addlabel-function.10456/#post-92584
 
Thanks for your reply, not sure what you have applies to me here is my code what should I change?
Code:
#HINT: This study plots a chart label for Net Change and Percent Change from prior close (regardless of time period of the chart.

input period_Type = AggregationPeriod.DAY;

def begin = close(period = period_Type)[1];
def end = close(period = period_Type);
def NetChg = end - begin;
def PctChg = (end/begin)-1;

AddLabel(yes, "" + AsPercent(PctChg) +  "  " + AsDollars(NetChg), if NetChg > 0 then CreateColor(100,200,100) else if NetChg < 0 then Color.Dark_Orange else color.LIGHT_GRAY);
 
Last edited:
Thanks for your reply, not sure what you have applies to me here is my code what should I change?
Code:
#HINT: This study plots a chart label for Net Change and Percent Change from prior close (regardless of time period of the chart.

input period_Type = AggregationPeriod.DAY;

def begin = close(period = period_Type)[1];
def end = close(period = period_Type);
def NetChg = end - begin;
def PctChg = (end/begin)-1;

AddLabel(yes, "" + AsPercent(PctChg) +  "  " + AsDollars(NetChg), if NetChg > 0 then CreateColor(100,200,100) else if NetChg < 0 then Color.Dark_Orange else color.LIGHT_GRAY);

look at my post#2.
this converts a number to text.
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/AsPercent
so instead of using aspercent , do like i did above and use several if-thens to fill in the required characters and the %
 
  • Like
Reactions: dxk

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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