Add text label to horizontal lines?

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

Whats going on, I have a script that plots daily pivots and I was wondering how I can code it to add text above the line on the upper that says "Daily Pivot"?

This is the code.

Code:
input timeFrame = {default day,WEEK, MONTH};
input showOnlyToday = no;

def H = high(period = timeFrame)[1];
def L = low(period = timeFrame)[1];
def C = close(period = timeFrame)[1];

def calc_PP = (H + L + C) / 3;
def calc_R1 =  (2 * calc_PP) - L;
def calc_R2 = calc_PP + H - L;
def calc_R3 = H + 2 * (calc_PP - L);

def calc_S1 = (2 * calc_PP) - H;
def calc_S2 = calc_PP - H + L;
def calc_S3 = L - 2 * (H - calc_PP);

plot PP;


if (showOnlyToday and !IsNaN(close(period = timeFrame)[-1])) or
(getAggregationPeriod() > if timeframe == timeframe.WEEK then AggregationPeriod.WEEK else AggregationPeriod.MONTH)

then {

 
  
    PP = Double.NaN;
  
 
 
}
else {
  
 

  
    PP = calc_PP;
  
 

}


PP.DefineColor("Color", Color.CYAN);
PP.AssignValueColor(PP.color("Color"));
PP.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
 
This is what I tried but it hasn't been working.

Code:
addchartBubble((showlabel, PP, if timeframe == aggregationPeriod.DAY then "Daily Pivot") else if timeframe == aggregationPeriod.WEEK then "Weekly Pivot" else if timeframe == aggregationPeriod.MONTH then "Monthly Pivot"),color.BLUE);
 
@aceboogie_11 thinkscript does not support all the if/else semantics you'd expect in a "real" language. you gotta put the if/else stuff in each argument.

Code:
declare upper;

input showBubble = yes;

def timeframe = GetAggregationPeriod();

AddChartBubble(
    showBubble,
    close,
    if timeframe == AggregationPeriod.FIVE_MIN then "5 min"
    else if timeframe == AggregationPeriod.FIFTEEN_MIN then "15 min"
    else "other",
    Color.GRAY);
 
Thanks, but the code just adds a bubble around ever candle instead of being above the coded pivot in the script which is that I am trying to accomplish @korygill

This is what I got so far.

Code:
declare upper;

input showBubble = yes;

def timeframe1 = getAggregationPeriod();

AddChartBubble(
    showBubble,
    pp,
    if timeframe1 == AggregationPeriod.day then "Daily Pivot"
    else if timeframe1 == AggregationPeriod.week then "Weekly Pivot"
    else "other",
    Color.GRAY);
 
step 1: get the bubble to change text per different timeframe.

step 2: you need to figure out when/where to display it. first bar, last bar, etc. instead of yes for showBubble, that would be some other condition.
 
Merry Christmas :) @Ronin13

Code:
input timeFrame = {default day,WEEK, MONTH};
input showOnlyToday = no;

def H = high(period = timeFrame)[1];
def L = low(period = timeFrame)[1];
def C = close(period = timeFrame)[1];
def x = barnumber();

def calc_PP = (H + L + C) / 3;
def calc_R1 =  (2 * calc_PP) - L;
def calc_R2 = calc_PP + H - L;
def calc_R3 = H + 2 * (calc_PP - L);

def calc_S1 = (2 * calc_PP) - H;
def calc_S2 = calc_PP - H + L;
def calc_S3 = L - 2 * (H - calc_PP);

plot PP;


if (showOnlyToday and !IsNaN(close(period = timeFrame)[-1])) or
(getAggregationPeriod() > if timeframe == timeframe.WEEK then AggregationPeriod.WEEK else AggregationPeriod.MONTH)

then {

 
  
    PP = Double.NaN;
  
 
 
}
else {
  
 

  
    PP = calc_PP;
  
 

}
PP.DefineColor("Color", Color.CYAN);
PP.AssignValueColor(PP.color("Color"));
PP.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

addchartbubble(x == highestall(x), pp, "Weekly Pivot", color.orange, no);

@Ronin13 just change out what your line is for example in my code “pp” is the plot, just change that for any line you want to be defined, then change the name in the parentheses for example mine is “weekly pivot”. Should be good from the :) hope this helps
 
Last edited by a moderator:
I'm a seasoned Developer trying to work with ThinkScript for the first time. I was able to plot a horizontal line but has anyone been able to add a label/title/name to the line on either left side or right side, like one can do manually through the "Add Drawing" on the chart which brings pop up dialog box after clicking on Edit Properties to "Show name" and "Show price" on either left or right side?

My intention is to find a way to pull my current position's stock symbol, add a "Buy Price" horizontal line along with buy price on either left or right side.
Then add a "10% Profit" line along with calculated profit in "name" on left side. Do the same with 20%, 30%, etc.

I also want to add alert to each horizontal line to send me a SMS alert.

I'd appreciate any info you can share whether if this is feasible or not and where can I find them?

Thank you very much!
 
@RoachStock Unfortunately, the manual route is the only route for adding labels to the horizontal lines... Vertical lines, on the other hand, can have labels added via Thinkscript code...
Thank you for your reply. I'm starting to think that I probably could live without the horizontal label as I would simply assume that a red line means BUY PRICE and all the green PROFIT levels would represent 10%, 20%, 30%, etc. Cheers!

On another note, is there a way to pull the current position stock's trade price in?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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