Add text label to horizontal lines?

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);
 

korygill

Active member
VIP
@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);
 

korygill

Active member
VIP
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:

RoachStock

New member
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

New member
@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

Top